Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

805 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