?
Solved

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

Posted on 2004-04-03
5
Medium Priority
?
1,932 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

752 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