# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### DarkBASIC Discussion / 3D space flight using real phsyics

Message
Posted: 11th Dec 2002 07:00
I've been screwing around with the simple maths example from DB.. I managed to get the ship rotating up and down... But I have a problem, every time I rotate or point the ship in many different ways and move it, the ship goes a different direction rather then it goes dependings whatever the ships pointing at. I rotate my ship 180 degrees(its facing me upside down) and press the forard key, its still going away from me. is there a solution for this?
Posted: 11th Dec 2002 07:13
p.s. I'm moving the ship besides using the "Move object" command.
Posted: 11th Dec 2002 12:11
Hmm... well firstly if you're going for real physics you'll need to learn a little about Vectored Maths, or XYZ updating maths.

As Vectors actually give the greatest control and mean you don't have to repeat everything you calculate 3 times are probably the better option.

Now as DarkBasic doesn't actually have a Vector function - mainly because you can specify values for variables this mean you'll have to make your own.
Also it doesn't have structures which makes it slighty harder to setup ... but what i'd recommend is making it a single value though bitshifting.

Simply take the float XYZ values your using (may want to a W for speed) and give them say 4bits each.

so X would be Vector# bitLeft(X#,0), y would be step 4, z step 4 and w step 12
i'd recommend 4 bit because it keeps it under 16bit - this is for speed reasons mostly - but if you try to make bit values bigger you'll understand the second reason.

Now you can use this value to add, subtract, multiply, blah blah against other vectors and then you interpol that value. Why do this?
again a speed reason, but with your value as a single value vector you can do alot of complex calculations to all three points at one time then once its all done you can simply bitRight and get the values you require.

To get rotation you base this on 2 Vector points and the current horizon plane - so imagine you're doing Triginometry math, and you have the base line for the 180° now that should always be level to the planes axis planes, so you'll have three for that as well which i'll try to explain later. But as vector base is always you're current objects Center of Gravity and the length|width determines the current speed ... the means your end vector is the currently projected heading. So it should be easy to calculate with simple trig using the objects axis points as a base where you're interpoling the rotational value to.

To interpol a value all your doing is creating a value which can be added within a time frame to smooth out calculations. I'd suggest the amount of interpols should be set to 30 as that will always keep things smooth

So like
Vector# - Vector2# / 30 = Interpol#
Vector1# + Interpol#

but of course you'll have to make sure the whole loop is working to a timeframe rather than irratic FPS, and perhaps for somthing more realistic you'll later wanna change these for dynamic interpols which can curve the values by creating algorithms

(^_^) well that's something to look into really.

However if you keep using what your being i'd use newxvalue|newyvalue|newzvalue functions

Anata aru kowagaru no watashi!