Spaceship Movement

Started by Schakal, July 24, 2013, 05:41:27 PM

Previous topic - Next topic

Schakal

Hallo everybody,

The next Newbee who wants to develop a spaceship game:)
At first, sorry for my bad English. I try to do my best.

Let me explain my problems:

I (want to) make a 3dgame, in that you fly with a spaceship trough an endless space with endless asteroids.
All the time the spaceship move forward , but you can change the direction point up/down and left/right.
That mean, theoretical you can fly eg. head-over in the "Matrix" and if you want to move the direction point up at the player view, in the matrix the direction down must move down.

This demo is a very good example to discripe the Movementfunction(the demo only support Camera rotating, but it shows what i need):

http://www.jpct.net/jpct-ae/download/alpha/Demo.java     (if somebody knows this Demo, i get this link from google, i cant find a way to it on the homepage...)

Some Facts:

I have an ship class with following (important) variables/classes:

Object3d mesh

SimpleVector position   (eg 0,0,0)
SimpleVector direction   (eg 0,0,1)

float AxisXchange  (eg 0°)
float AxisYchange  (eg 5°, this value comes from the Movement functions, because the player wants to move the direction point up)


And i think i need an Vector/variable, which shows the ..ARGHH i cant explain... but seems I need to;)

Imaging the ship is at the position vector and "looks" at the direction vector.
We need an another information which show which "roll" status the ship has.
But this we need at the second step i think.

ok, enough enough...

First i want to understand on what way i can rotate the direction point around the position point.


This code isn't correct:


SimpleVector currentXAxis = mesh.getXAxis();
SimpleVector currentYAxis = mesh.getYAxis();

direction.rotateAxis(currentXAxis,AxisXchange);
direction.rotateAxis(currentYAxis,AxisYchange);

this.positiontranslate.x = delta * direction.x * speeddirection;
this.positiontranslate.y = delta * direction.y * speeddirection;
this.positiontranslate.z = delta * direction.z * speeddirection;


this.mesh.translate(this.positiontranslate);



I think I need to create a translation matrix with the position and direction Vector, but  i am not the best in math-things like this.,
I would be very glad if someone could help me a bit with that. If you (yes you! are very probably the person who can help me ;)  ) need more information, please tell me.

With best regards

Jan

EgonOlsen

I'm not sure if i got this right, but the direction vector of the ship (in my understanding, this is the direction in which the ship's nose points) actually is the result of ship.getZAxis();

Schakal

#2
ups sorry for the long answering time:(

But this time i can explain the problem better.

Now the Movenfunction of the game runs over the Camera.class :


// RotateX/RotateY value = -1 | 0 | 1 for up/down and left/right
//AxisXchange/AxisYchange value = 1-360   (°)
//speeddirection value = 1 (unit per s)
//speeddirectionchange value = 1 (° per s)
//Ship and camera created at Vector (0,0,0)

//Camera move behind ship
world.getCamera().moveCamera(2, 10);

//player change direction to upper direction
RotateX = 1

//Camera move to ship position
world.getCamera().moveCamera(1, 10);

//camera rotate the direction to upper direction

                if(RotateX != 0)
{
AxisXchange= RotateX * speeddirectionchange * deltaTime;
activity.world.getCamera().rotateX(AxisXchange/360);
}

if( RotateY != 0)
{
AxisYchange= -RotateY * speeddirectionchange * deltaTime;
activity.world.getCamera().rotateY(AxisYchange/360);
}


//camera move the distance which the ship must move
world.getCamera().moveCamera(1,.speeddirection *activity.deltaTime);

//ship get the new position of the camera
newshipposition= world.getCamera().getPosition();

//camera move behind the ship
world.getCamera().moveCamera(2, 10);


Like this i want to make the new moventfunction of the ship.
I wish there where functions in the Object3D.class names move(forward|back, distance) and rotateX/rotateY like the Camera.
But the roatex function from Object3D rotate at the world-axes wight?
not like the camera.rotateX function, which calculate with  his own direction vector?

Because in the future i want to move only the ship object and command the camera to follow.

I hope this was eraser to understand.

Jan

EgonOlsen

As far as i got it, i would still say that a translation along the vector returned by Object3D.getZAxis() is what you want.