This topic is now archived and is closed to further replies.


Simple movement in 3D space problem

Recommended Posts

takumi    122
Hello everyone. I am now implementing a small fish tank project, which the fish can swim freely in the tank. My problem is that I don't know how to implement the movement in 3D space and quite confused on it. I have think the following stuff for implementation: 1) use a vector varialbe to store the direction which the fish is facing. eg: direction = CVector(0, 0, 0); means face to the north 2) use another vector variable to store the speed of the fish. eg: speed = CVector(0.0, 0.0, 1.0); means the swimming speed in z-axis = 1.0. 3) use this function to calculate the direction that the fish is facing by passing the pitch and yaw angle. mPitch = up & down angle mYaw = left & right angle rX += cos(mPitch / 180 * M_PI) * sin(mYaw / 180 * M_PI); rY += sin(mPitch / 180 * M_PI); rZ += cos(mPitch / 180 * M_PI) * cos(mYaw / 180 * M_PI); direction.x = rX; direction.y = rY; direction.z = rZ; 4) use this function to calculate the new position of the fish and then render it. newposition = position + (speed * deltaTime); Actually, I just want my fish first rotate to a desired direction and then start swimming forward to that direction is enough. My concept maybe wrong, I hope someone can make some sense out of it because I can't. Please tell me anything I have left? Or you can give me some suggestions or tutorials to reference. Thx you very much [edited by - takumi on October 3, 2002 1:00:23 AM]

Share this post

Link to post
Share on other sites