?
Solved

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

Posted on 2004-04-03
5
Medium Priority
?
1,942 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Accepted Solution

by:
PCT earned 140 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’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

649 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