请教3D祖玛中,球按路径旋转的算法或思想!!!
请大虾指点:
请教3D祖玛中,球按路径旋转的算法或思想!这部分还真难.谢谢.
方法1:计算当前点与下一点的向量夹角.行不通.
[解决办法]
"球按路径旋转"是什么意思呀?
是一边走, 一边转吗?
[解决办法]
楼主的意思是球按照一定路径运动吧
可以利用bezier或bspline曲线,根据公式只要算出不同时刻球的不同位置就可以了
[解决办法]
样条曲线插值吧,根据关键点插值计算出一条连续的曲线。
[解决办法]
路径怎么定义的,球就怎么走呗。
[解决办法]
#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__)
[解决办法]
虽说算法是实现zuma的关键。俺倒是对一些细节比较感兴趣,想跟楼主探讨下,比如球插入队列时候的动态效果如何实现
[解决办法]
你得有一个网络相册,然后就回复框上边的插入图片功能,写上图片的URL就行。
[解决办法]
刚做完一个类似的游戏,当时就是这个问题没办法解决,后来用数据表做的,做表做到手抽筋~~~
[解决办法]
去看看我做的战龙飞燕祖玛!