请教3D祖玛中,球按路径旋转的算法或思想!!!

leechrockgames 2010-02-27 11:08:39
请大虾指点:
请教3D祖玛中,球按路径旋转的算法或思想!这部分还真难.谢谢.
方法1:计算当前点与下一点的向量夹角.行不通.
...全文
825 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunjs123 2010-08-06
  • 打赏
  • 举报
回复
楼主的问题应该与做太阳系各大行星自转公转的效果差不多吧。
就是一个旋转参考点的问题。可以用下面的方法实现:

1.先将球移动到路径曲线的曲率中心点;
2.再进行绕球中心自转;
3.再把球已回应该出现的位置上。

自转的角度应该比较容易求得,如果将路径用极坐标的形式来表达的话,应该很好做的啊。
dxshenhua 2010-06-22
  • 打赏
  • 举报
回复
去看看我做的战龙飞燕祖玛!
leechrockgames 2010-03-31
  • 打赏
  • 举报
回复
[Quote=引用 35 楼 yashuwa0622 的回复:]
刚做完一个类似的游戏,当时就是这个问题没办法解决,后来用数据表做的,做表做到手抽筋~~~
[/Quote]
大虾..能加我Q.指点一下不?
yashuwa0622 2010-03-29
  • 打赏
  • 举报
回复
刚做完一个类似的游戏,当时就是这个问题没办法解决,后来用数据表做的,做表做到手抽筋~~~
leechrockgames 2010-03-23
  • 打赏
  • 举报
回复
http://hi.baidu.com/leechrockgames/album/item/0d7f0521936c5878925807ff.html

你睇下了.
leechrockgames 2010-03-23
  • 打赏
  • 举报
回复
DarthVader 2010-03-22
  • 打赏
  • 举报
回复
你得有一个网络相册,然后就回复框上边的插入图片功能,写上图片的URL就行。
leechrockgames 2010-03-21
  • 打赏
  • 举报
回复
点插入图片呀?
leechrockgames 2010-03-21
  • 打赏
  • 举报
回复

你加我QQ,我们聊聊,这个游戏我完成了.不过你的旋转,我还没有领悟.BALL做一个连表,每发射一个BALL,都与连表中所有BALL的位置做相应的位置检测.如果位置在范围内,就压到连表中,但要检测是,压到当前节点的前,或者..我是用3D实际坐标检测的.但..它的特效是2D坐标,所以要将3D坐标,转换成2D坐标.然后..播放动画
leechrockgames 2010-03-18
  • 打赏
  • 举报
回复
太谢谢你了.可不可以交个朋友呀.我QQ是:359397187
DarthVader 2010-03-18
  • 打赏
  • 举报
回复
虽说算法是实现zuma的关键。俺倒是对一些细节比较感兴趣,想跟楼主探讨下,比如球插入队列时候的动态效果如何实现
DarthVader 2010-03-16
  • 打赏
  • 举报
回复
例子代码里面就有算法 弄下来看看就明白了。
这么说吧:一个曲线的方程决定之后 根据坐标求其上任一点的算法也就出来了
看一下头文件:


#pragma once

#ifndef __NATURALCUBICSPLINE_H__
#define __NATURALCUBICSPLINE_H__

#include "CommonDef.h" <- 这是我自己的共同头文件,不必理会
#include <vector>

using namespace std;

//-----------------------------------------------------------------------------
// Name: class Cubic
// Desc: representation of Cubic
//-----------------------------------------------------------------------------

class Cubic
{
double a,b,c,d; /* a + b * u + c * u^2 + d * u^3 */ <- 这就是样条曲线的方程

public:
Cubic(double a, double b, double c, double d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
}
~Cubic(){};

/** evaluate cubic */
public:

// evaluate cubic
double eval(double u) <- 根据曲线上点的坐标求函数值(这里u其实是点在曲线上的位移)
{
return ( ( ( d * u ) + c) * u + b ) * u + a;
}

// get tangent( derivative )<- 根据曲线上点的坐标求Tangent,也就代表了切线方向
double tangent(double u)
{
return ( ( 3 * d * u ) + 2 * c ) * u + b;
}
};

//-----------------------------------------------------------------------------
// Name: class NaturalCubicSpline
// Desc: representation of NaturalCubicSpline
//-----------------------------------------------------------------------------

class NaturalCubicSpline
{
protected:
vector<Cubic> mYCubics;
vector<Cubic> mXCubics;
vector<double> mXCoords;
vector<double> mYCoords;

vector<Point> mPoints;
vector<FPoint> mSpline;

vector<double> mSplineSegmentLengths;

virtual void RegenerateSpline(vector<double>& theInput, vector<Cubic>& theOutput);
virtual void RegenerateClosedSpline(vector<double>& theInput, vector<Cubic>& theOutput);
virtual double GetMinUFromLineAB(FPoint A, FPoint B, Point C);
virtual double GetMinDistanceFromLineAB(FPoint A, FPoint B, Point C);

double mArcLength;
unsigned int mGranularity;
bool mClosed;

public:
NaturalCubicSpline(void);
virtual ~NaturalCubicSpline(void);

// Drawing Functions
virtual void Draw(IDirect3DDevice9* pd3dDevice);
virtual void DrawControlPoint(IDirect3DDevice9* pd3dDevice, int theControlPointId, int theWidth);
virtual void DrawSplineSegment(IDirect3DDevice9* pd3dDevice, int theSplineSegmentId, D3DCOLOR color = D3DCOLOR_XRGB(0x00,0xff,0x00) );

// The main functions
virtual void AddPoint(Point thePoint);
virtual void RegenerateSplines(); // You Shouldn't have to call this.
virtual FPoint GetPointAt(double theDistanceOnTheSpline);
virtual FPoint GetTangentAt(double theLength);

// ADT functions
virtual int GetNumControlPoints(){return (int)mPoints.size();};
virtual int GetNumSplineSegments(){return (int)mXCubics.size();};
virtual double GetArcLength(){return mArcLength;};
virtual void SetClosed(bool bClosed){mClosed = bClosed; RegenerateSplines();};
virtual bool isClosed(){return mClosed;};
virtual int GetGranularity(){return mGranularity;};
virtual void SetGranularity(int theGranularity){mGranularity = theGranularity; RegenerateSplines();};

// For Curve Refinement
virtual void BisectSegment(int theSplineSegmentId);
virtual void DeleteControlPoint(int theControlPointId);
virtual void ClearAllPoints();

// Picking Helper Functions
virtual double GetClosestPointOnSegmentToPoint(Point thePoint);
virtual int GetControlPointIdNear(Point thePoint);
virtual int GetSegmentIdNear(Point thePoint);
virtual Point GetControlPoint(int theControlPointId);
virtual void SetControlPoint(int theControlPointId, Point thePoint);

virtual int GetNextSegmentId(int theId);
virtual int GetNextControlPointId(int theId);
virtual int GetPrevSegmentId(int theId);
virtual int GetPrevControlPointId(int theId);

//Serialization
virtual HRESULT SaveToFile(CString theFileName);
virtual HRESULT OpenFile(CString theFileName);
};


#endif// !defined(__NATURALCUBICSPLINE_H__)
leechrockgames 2010-03-16
  • 打赏
  • 举报
回复
游戏我已经开发完成了.就差(球沿着曲线路径滚动,根据曲线上点坐标可以很方便的得出切线方向)这个计算角度的公式了.请教大虾.希望大虾能大方解救.
DarthVader 2010-03-15
  • 打赏
  • 举报
回复
Popcap的SexyApp是开源的,用来开发小游戏是个不错的选择 ^^
DarthVader 2010-03-15
  • 打赏
  • 举报
回复
楼主不要着急,SexyCurve应该可以解答你的迷惑:
http://www.mooktown.com/sexyfaq/sexycurves.html

这个例子是基于Popcap SexyAppSDK的,而这个SDK,成就了许多著名的Popcap休闲小游戏(祖玛,吞食鱼,宝石迷阵,植物大战僵尸……)。

例子代码的精髓就是CubicSpline(3次样条曲线)的实现,但有较大的改进余地,否则达不到实时运行的要求。
leechrockgames 2010-03-15
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 darthvader 的回复:]
正如楼上各位所说,路径是用曲线来实现的,球沿着曲线路径滚动,根据曲线上点坐标可以很方便的得出切线方向,根据这个方向对球的图片进行一定角度的旋转即可。我自己的代码里面就是这么做的。楼主注意看下面截图中每个球的朝向:
[/Quote]
大虾.请教其数学公式!!能给我吗?
leechrockgames 2010-03-15
  • 打赏
  • 举报
回复
如果谁有(路径是用曲线来实现),请教小弟.能用的话.用钱买.我也接受.
DarthVader 2010-03-12
  • 打赏
  • 举报
回复
Zuma游戏的核心和难点之一就是曲线路径的实现,曲线模型决定了后续处理的繁简
DarthVader 2010-03-12
  • 打赏
  • 举报
回复
正如楼上各位所说,路径是用曲线来实现的,球沿着曲线路径滚动,根据曲线上点坐标可以很方便的得出切线方向,根据这个方向对球的图片进行一定角度的旋转即可。我自己的代码里面就是这么做的。楼主注意看下面截图中每个球的朝向:

antimatterworld 2010-03-11
  • 打赏
  • 举报
回复
俺觉得也可以定义一个数组有N个元素,每个元素代表一个位置。
球从一个位置移动到下一个位置。
两点之间可以直线插值。位置数组的内存的需求量还可以接受。
当然这个办法比较低级。
加载更多回复(18)

8,325

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧