Using X_ROTATION properly? phi?

Previous topic - Next topic

Amon

I'm at a loss as to what phi does and how to use X_ROTATION properly.

If I had a gun that moved according to MOUSESTATE and X_ROTATION how would I use phi with this? Here's some code:

Code (glbasic) Select

SETCURRENTDIR("Media") // go to media files

SETSCREEN 1024, 768, 0

GLOBAL GunM4 = 1
GLOBAL GunM4$ = "M4a1.ddd"
X_LOADOBJ GunM4$, GunM4
LOADSPRITE "M4a1.jpg", GunM4

WHILE NOT KEY(1)
X_MAKE3D 1, 5000, 45
LOCAL mx, my, b1, b2, rot#, mx2, my2
LOCAL gx, gy, gz
gx = 150
gy = -100
gz = -250

mx2 = MOUSEAXIS(0)
my2 = MOUSEAXIS(1)
MOUSESTATE mx, my, b1, b2

X_CAMERA 0, 20, -500, 0, 0, 0

X_DRAWAXES 0,0,0

X_MOVEMENT -50, -100, -250


IF mx <> 0
IF my <> 0
// IF mx > 360 THEN mx = 1
// IF mx < -360 THEN mx = -1
SETMOUSE mx, my
X_ROTATION , gx + -mx, gy + my, 0
ENDIF
ENDIF

X_SETTEXTURE GunM4, -1
X_DRAWOBJ GunM4, 0

SHOWSCREEN
WEND
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Ruidesco

#1
Phi are the degrees you want the model to rotate. X, Y and Z are the flags for the axes in which the model will be rotated by phi degrees.

So, for example, if you wanted to rotate the model 90 degrees in the Y axis you would state: X_ROTATION 90, 0, 1, 0
90 for the degrees (phi), 0 for both X and Z since you don't want the model to rotate in these axes, and 1 for Y because that is the axis you want the model to rotate in.

Amon

Thank You!

Setting it to say 90 rotates the given axis by that amount. Using the mouse, how would I rotate my object by using phi? Is phi a -359 | 359 angled number?

- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Ruidesco

Phi can be any number that fits in a floating point variable, so you can rotate a model 10000 degrees even if it makes little sense.
As for the mouse, you would have to get the mouse position, do your calculations as to how many degrees does that make and rotate X and Y in separate X_ROTATION calls, I'd say.

Slydog

#4
I'm not sure how your game is displayed (top view?), but to rotate an object to point towards your mouse, you would use something like this:  (this works for a 2D display, but can easily be adapted for a 3D environment, just pick your two axes you need)

Code (glbasic) Select
LOCAL mx, my, b1, b2 // Mouse state
LOCAL rotation# // Player rotation
LOCAL px, py // Player x, y

MOUSESTATE mx, my, b1, b2
rotation = ATAN(my-py, mx-px)


You may have to adjust the rotation to suit you, such as add / subtract 90, but it may work as is.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]