# 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 Professional Discussion / Euler angles and Freeflight commands

Message
Posted: 23rd Jun 2018 13:36
In my game, I use many commands to rotate stuff all the time, but sometimes I need to rotate an object to a specific angle and in others I need to rotate and move them based in their current position - using MOVE OBJECT and ROLL OBJECT - but in the help files it's said that I should not mix ROTATE OBJECT with these commands.
In fact, sometimes it results in some bizarre ocurrences like an object being moved with the wrong angle.

What I need to do is:

Is there a way to use both commands together related to the same object without having to rewrite the code? Is there a command that "resets" the object in such way Freeflight commands can be performed correctly even after Euler rotation is done?

I need help, because if it is not possible, I'll need to find another way to "strafe" my rotated objects left and right from their current positions without MOVE OBJECT LEFT and MOVE OBJECT RIGHT - and I am unsure about how using sine and cosine to produce such result.
[size=+2]Forever and one[/size]
Posted: 26th Jun 2018 04:08 Edited at: 26th Jun 2018 04:43
The difference is how the functions work internally. When you rotate an object you are giving the function an angle. This angle is saved in a variable to be used to return that angle. When you use one of the free-flight commands, a flag is set to cause the object angle functions to return the value through a matrix calculation and not use the saved angle. This method returns a value that is not what we expect. Object orientation turns out the same, however. It's when you use the returned angle value in calculations, where you'll run in to trouble.

Do not use the free-flight functions, instead; see code.

Posted: 7th Jul 2018 13:28
I kind of solved my problem.

I had to remove all freeflight movement commands and - using your suggestion - to write equivalents that used Euler angles to avoid discrepancies between the object angle and the rendered object osition.

The rotation was easy. I know how to make incremental rotation that works exactly the same way as TURN OBJECT and ROLL OBJECT.

The hardest part was to convert MOVE OBJECT, that is a freeflight command although it doesn't involve rotation - into something usable.

I was in need of Euler angle and movement commands that allowed me to move a 3D plain in the exact same way I would do with a 2D sprite. This is what I did:

function moveobject(obj,speed#,direction)
//this will define the direction to move the ob ject
if direction = 0 then amod = 0 //move forward
if direction = 1 then amod = 180 //move backwards
if direction = 2 then amod = 90 //move right
if direction = 3 then amod = 270 //move left

speed# = 1 //how much to move the object
x# = object position x(obj)
y# = object position y(obj)
angle# = object angle z(obj)
nx# = sin(angle#)*speed#
ny# = cos(angle#)*speed#
position object obj,x#+nx#,y#-ny#,0
endfunction
[/code}

To rotate objects in the same way you would with TURN, ROLL and PITCH, is easier - turn is Y axis, roll is Z axis and pitch is X axis. No mystery here

By the way, I need to know a single thing about geometry:

I know how to use SINE and COSINE, but I don't know how to use TANGENT, ARCSINE, HYPERBOLLIC SINE, et cetera. Simple examples are welcome - and brazilian poor schools and my laziness are to blame.
[size=+2]Forever and one[/size]