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.

3 Dimensional Chat / Getting the roll value of an object in DBPro

Author
Message
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 12th Jul 2003 20:49
I'm writing some code to add wingmen to my 3d game.

I'm trying to discover if there is any relatively straightforward way of finding out what the roll value of a model actually is. (The model is a *.x model though I don't think that matters).

I've looked at the object angle commands but whilst the x and y commands together return the model's direction, they don't help with the model's roll.

Any assistance gratefully received.

Phil
What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 04:13
object angle z?

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 13:42
I've tried that but whatever direction I roll my object in, it doesn't seem to return any value other than 0. It is... perplexing, to say the least.

My solution has been to to just increment a positive rotation or a negative rotation variable by 1 for each degree the ship is rotated, then just return the rotation variable as modified by wrapvalue. Its an awfully slow way around the problem but, hey ho, there you go.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 13:58
yea...object angle z will always return 0 unless you change it ;p
rotate object is a useful commmand for this ;p

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 14:16
Right! Oddly enough, I've just discovered this myself. I was using the roll object left and roll object right commands. But they don't return any value on object angle z. Is that a bug do you think?

Instead, I'm now using the zrotate command.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 14:21
omg...a bug in DBP!? no way!
nah...I actually haven't touched the roll commands yet ;p

read my post on the following thread for a rant about errors in DBP ;p
http://www.darkbasicpro.com/apollo/view.php?t=13197&b=3

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 14:25
Actually, I should engage my brain before posting. I've just realised that z_rotate is NOT the same angle of rotation as roll. Roll is obviously the z angle of the object by reference to its angle of direction. z_rotate, on the other hand, rotates through the z axis on an absolute world basis. Which is quite different.

I'm going to have to write custom functions to calculate the z axis on a roll. The word that springs to mind is "crap".

Ok. *sigh* - where is my trig and calculus books??

I'm just very lucky that bears are good mathematicians...

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 14:30
actually, its not too hard to pull off calculations like that seeing as DBP included cos sin tan arctan arcsin arccos and what not. i really HATE languages that dont include trig functions ;p
TAYLOR SERIES CAN EAT ME!! (btw TI-81 ownz) anyway... you shouldn't have to, zrotate should roll your object at whatever angle its facing.

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 14:33
It doesn't. Trust me. I've just tried. Its not relative to the direction that the model points.

I'm going to have a look at the set rotation commands and see if they help.

If not, its either my unsatisfying "cheap hack" method (the rotation variable and wrapvalue) or out comes the trig maths books.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 14:35
and the rotate object obj number, x, y, z command I mean

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 14:42
Unsurprisingly that didn't work either.

However, in the process, I discovered something else interesting. If you keep returning a value for object angle z whilst either using z rotate object or rotate object ,,,z unlike the object angle x and y commands, the object angle z value just keeps incrementing permanently, i.e. it goes over 360 degrees.

Thats got to be a bug as well.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 15:03
And, of course, I've just realised that my "cheap hack" won't work either - its dangerously two dimensional thinking.

Well, out come the maths books.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 15:08
nah, i have another solution for you
create a joint for your aircraft, just one.
parent the whole mesh to it, i KNOW the rotate limb commands are relative to whatever angle they are at.

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 15:47
Huh? I don't follow. You mean add a limb?

Using trig, I've been trying to work out how I calculate either the X or Y value to get the angle. It occurred to me I might have to add an invisible object on the wing of the craft, then contrast the x pos or y pos of both objects (the pivot of the main object, versus the x pos of the small object) to return the length of the X or Y value for the purposes of sin or cos.

I'll try your method first.

Frankly, this is all very annoying. It should be simple. I can't help feeling slightly let down by the DBPro guys on this one.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 15:48
Also, why are there limb direction x, y, z commands but not object direction x, y, z commands???

A bit of an obvious oversight, perchance?

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 13th Jul 2003 16:35
thats why i said use limbs

Live as if to die tomorrow...
Learn as if to live forever.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 16:54
Well, the bad news is that I just tried limbs, and they didn't work either.

I tried superimposing a masked limb over the object and then testing the values of the limb.

The relevant sections of code read:


Unfortunately, y_limbdir# is always a 0, just like the value returned by object angle z()

Back to the trig books for yours truly

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jul 2003 16:55
Whoops. I mean z_limbdir#, not y_limbdir#

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 14th Jul 2003 01:48 Edited at: 14th Jul 2003 01:51
try the 'work arounds.'
use height (y) difference between the object and an offset limb. ( or object)
If the offset is i unit on the x axis, the z angle is equal to asin( height difference) when the object is rolled over.
It's not true z angle, since it incorporates the cosine pitch but it is commonly used.

try ...
1. a mesh attached as limb and offset 1 unit on x, read limb postion y.

2. turn the object right 90, move 1unit, read height, move object back 1 and turn to original angle again.
3. use the dp pro command for moving/ displacing an object left or right of an object. it worked relative to roll angle, when i first tried the db pro demo .. before giving up in disgust!

cheers.
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Jul 2003 16:35
Seems awfully complex.

Mind you, I am using an offset limb, then transposing the 3D world coordinates of the offset limb and origin of the object to a pure cartesian system 2D right angle triangle (by calculating the vectors of the hypotenuse - being the radius of the vessel and the vector of the height angle y), then calculating the cosine of the right angle triangle.

Its really incredibly frustrating and probably equally complex. Why oh why could DBPro have not just included a bespoke command for this?

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
3dZmaster
21
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 14th Jul 2003 17:17
I think the solution is this. Or this worked with me:
Make a object to handle the rotation, let's say make sphere 1,4
then "glue object to limb (aircraft object number),1,0"
then make every moving and rotating commands to the sphere. Then the zrotate command should work.

Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Jul 2003 18:17
Nope. Remember that the zrotate command rotates around the z axis in the cartesian world coordinate system. It doesn't rotate around the z axis of the cartesian local model coordinate system.

It'd help if DBPro had some code to create an arbitrary axis for the purposes of rotation, just as DirectX has, but it doesn't.

Not to worry. I've solved the issue by calculating two 3D vectors and the arccosine using custom functions.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
Philip
22
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Jul 2003 19:30
This problem is now solved in a mathematically correct and pleasing method, thanks to DBPro's asin() function.

Full code attached.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
WindTech
22
Years of Service
User Offline
Joined: 7th Jun 2003
Location: United States
Posted: 18th Jul 2003 13:17
good ol' trig, never fails

Live as if to die tomorrow...
Learn as if to live forever.

Login to post a reply

Server time is: 2025-06-26 09:02:50
Your offset time is: 2025-06-26 09:02:50