Solved

Game Movement (Opengl) moving an object in this direction it is pointing

Posted on 2004-04-03
5
1,903 Views
Last Modified: 2012-05-04


Ok im making a 3d spaceship game . I have come to the problem of how do i get my "spaceship" to move in the direction that it has been rotated to . I think I need to use trignometry or maybe matrices but im not sure how. Here are the variables that I am using (if you need to add any tell me) Im thinking at the moment to acheive this by changing the diffrent directional speed (xspeed , yspeed and zspeed) These speeds being added to the translation values these are what i need to figure out from the angles.

player.pxangle , player.pyangle , player.pzangle
[glRotate(pxangle,1,0,0),
glRotate(pyangle,0,1,0),
glRotate(pzangle,0,0,1)]

player.pxspeed
player.pyspeed
player.pzspeed

[player.px = player.px + player.pxspeed ,
player.py = player.py + player.pyspeed ,
player.pz = player.pz + player.pyspeed ;]

if you do submit an answer I would be very thankful if you could include the actual code of how to do it (as well as any variables you might add)

Please help me (this is not homework because im still in y10 of secondary school :) :p)

PS. My understanding of matrices is very small so if you submit an answer to do with matrices and wot not it would be increadbly handy to have the actual code.

Thanks in advance Paladin

----------(Points will be boosted as soon as my refund goes through on another question)----------
0
Comment
Question by:Paladin_VB
5 Comments
 

Accepted Solution

by:
PCT earned 35 total points
ID: 10750035
Well I am no expert, I have been using OpenGL for all but a day, but I will give you my thoughts.
Lets say your spaceship is just a line
glbegin(GL_LINE);
glvertex(x1+vx*t,y1+vy*t,z1+vz*t);
glvertex(x2+vx*t,y2+vy*t,z2+vz*t);
glend();

Let v=[x,y,z]
then to change direction
glrotate();
v = v*(rotation matrix);
update display;

go to http://www.makegames.com/3drotation/
to find out how to make a rotation matrix.
0
 
LVL 4

Expert Comment

by:Fippy_Darkpaw
ID: 10800011
Here's links to a complete OpenGL space shooter I did for graphics class. Source and VC++ 6.0 workspce is included. Also included is a simple physics/player movement demo, a simple AI demo, and a simple model viewer demo. The code in the demos shows you exactly how to move a ship through game space.

http://www.cs.ucf.edu/~hastings/index.php?id=opengl 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now