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.

Work in Progress / Useful Rotation Functions

Author
Message
lower logic
17
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 4th Jan 2007 01:52 Edited at: 31st Jan 2007 01:54
I'm working on a list of functions that will enable you to do all sorts of rotations to objects in your games. I originally posted this in the code snippets board but I'm adding more and more functionality everyday that it's more of a WIP than a little code snippet. If anyone has ideas for other rotation functions I could try to code them up.

First here's an example of a ball rolling on a matrix using one of the functions:


Here's the current function list:

Source code & a basic interactive example showing how to use all the functions.

Attachments

Login to view attachments
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 4th Jan 2007 03:12
Good bye EZRotate

lower logic
17
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 4th Jan 2007 06:44 Edited at: 4th Jan 2007 06:54
Turret example using some new axis-angle rotation commands I just finished coding:


There's a turret on each face of both cubes. Screen shot:


You can see that the turrets mounted on each face of the cubes are pointing at the ship (box) in the center of the screen.

Even though the turrets are on every face of both cube and the cubes are rotated at random angles, the code that controls each turret is simply this:

Here's what each part does:

The first line, "targ_y#=FindAxisAngleYtoPoint(turret(t).base,turret(t).ax,turret(t).ay,turret(t).az,tx#,ty#,tz#)", finds the local Y angle to the point based on the Axis-Angle system. Each turret has it's own ax,ay,az, which is the "up" direction. Each face of a cube has a different up direction, so this is set when the turret is created.

The next two lines rotate the base of the turret and the barrel to this angle using the RotateAxisAngleY() function.

The next line, "targ_x#=FindAxisAngleXtoPoint(turret(t).barrel,turret(t).ax,turret(t).ay,turret(t).az,tx#,ty#,tz#)", finds the X angle to the target, again based on the Axis-Angle system.

After that, "if targ_x#<180 then targ_x#=0" and "if targ_x#<270 and targ_x#>180 then targ_x#=270" limit the rotation to make sure it can only be between 360 and 270 degrees (so it can't point down relative to the way it is mounted).

"RotateAxisAngleX(turret(t).barrel,turret(t).ax,turret(t).ay,turret(t).az,curveangle(targ_x#,Axis_Angle_X(turret(t).barrel,turret(t).ax,turret(t).ay,turret(t).az),20))" rotates the barrel so it has the right pitch.

A few other lines are called to make sure the base of the turret has no x or z angle relative to the up direction. Also, some code makes the barrel roll when the ship gets close, like a shooting animation of some sort. Also, when you get to far away the barrel will stop rolling and will return to a relative Z angle of 0 in the Axis-Angle system.

Edit:Updated first post with new rotation functions
TEH_CODERER
20
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 4th Jan 2007 22:23
I had been considering purchasing EZRotate but alas it is now redundant! Very nice code!

Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 7th Jan 2007 19:34
Wow, brilliant.
I've been looking for something like this (local Z-Rotation) but solved the problem with limbs.. is it also possible to z-rotate the camera local? It doesn't work like I did it with objects.. would be cool if it works in another way. Thanks.

Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
MExe
17
Years of Service
User Offline
Joined: 11th Jan 2007
Location:
Posted: 13th Jan 2007 18:35
Fantastic programming and my biggest compliments but... I ask, this will take maybe a big amount of cpu time or not?
It's sure good for small programs that don't push a system to the limit, but maybe some DLL remains the best option if you need SPEED.
lower logic
17
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 16th Jan 2007 12:39 Edited at: 16th Jan 2007 12:39
Mr Kohlenstoff:
I don't think it would be hard to make these rotation functions work with the camera. You'd just need to edit the code that finds the x,y, and z axises, which is
, so that it finds the x,y, and z axis of the camera, and edit the final rotate object command so that it rotates the camera instead.

MExe:
Yeah just looking at all the lines of code to do a single rotation shows that a lot of calculations are needed. I haven't tried to optimize the code very much, but I bet with some work the functions could be made to use with less lines of code. I don't know how much performance would improve by calling a DLL since either way the program would still need to do the same calculations.
lower logic
17
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 31st Jan 2007 02:05 Edited at: 31st Jan 2007 02:14
While programming the space ship AI for the Battlestar Galactica game I noticed that I really needed some good relative/local angle functions, so decided to add the functions I needed. Well, I got carried away (as usual) and ended up adding 17 angle-returning functions .

As you know, rotate_axis() is like an extreme/pro function that can rotating an object about any axis, making the local and global rotation functions nearly redundant, similarly, Angle_Axis() is like that for angle-getting, except 3 times more complicated ;P.

Angle_Axis() doesn't actually take an object, so everything is in terms of global space. It takes an axis of rotation (or measurement, i guess), a base vector/axis, and a offset/destination vector/axis, and the function will measure the angle offset - base around the axis of rotation. Angle_Axis_GL(), Angle_Axis_LG(), and Angle_Axis_LL() are all functions that convert one or more local axes to global ones and then call Angle_Axis().

I had to put the actual code in an attached dba since the post was getting so long (1300+ of source code plus the rolling ball example). I updated the first post with the new code in the attachment and list of commands.

I tried to make the angle/direction returned consistent with the rotation functions, and those functions are consistent with the dbp rotation functions. That means if, say Angle_GY_Z(1) returns some value q#, then if you do Rotate_GX(1,-q#), the next time you call Angle_GY_Z() it should return 0. The other angle-returning functions are also consistent in a similar way with the local rotate functions.

Oh, and if you were wondering, I only needed Angle_LY_Z() and Angle_LX_Z() for my space fighter AI .

Login to post a reply

Server time is: 2024-04-23 13:45:46
Your offset time is: 2024-04-23 13:45:46