Solved

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

Posted on 2004-04-03
5
1,897 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

21 Experts available now in Live!

Get 1:1 Help Now