Advertisement

Simple Trig Question

Started by February 15, 2002 05:46 AM
6 comments, last by Lazarus404 22 years, 11 months ago
I''m having a problem orientating a model to match for points of varying height. What I have so far is:- across#=((frontright#-frontleft#)+(backright#-backleft#))/2.0 length#=((backleft#-frontleft#)+(backright#-frontright#))/2.0 rotate object 1,wrapvalue(asin(length#/4.0)),wrapvalue(angle#),wrapvalue(asin(across#/4.0)) (simplified version) But this is obviously wrong as it doesn''t work! Anyone know how I can sort this? Thanks Lazarus404
Lazarus404
I don''t completely follow your example. First, what do you mean by "match for points of varying height." Please provide a more detail description.

Also, what does your "rotate" function do? The parameters seem odd. I thought it might be a rotation specified as a quaternion, but its strange that your angle value is placed between two directional parameters (vector components?). And what is "wrapvalue"?

If you clarify what you want to do, we can probably come up with an approach.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Advertisement
Thats darkbasic, isn''t it ?
~V'lionBugle4d
quote:
Original post by Vlion
Thats darkbasic, isn't it ?


You're right, it is darkbasic. Basically, the rotate value accepts the object number and then the coords x,y,z where x and z are the coords across a plain and y is the verticle coord. If you imagine a plain to contain rolling hills, I'd like a cube to orientate itself to match the contours of the hills so that it looks like it is flat to the hills. Taking the length and width of the cube (the four corners) I now want to use the rotate object command to rotate the object to the angle of the terrain.

Hope that makes the code clearer???

Thanks

Lazarus404

Edited by - lazarus404 on February 25, 2002 4:09:09 AM
Lazarus404
I still don't know what "wrapvalue" is. If it is a darkbasic function then I'm clueless since I know nothing about darkbasic.

I think that description makes the code clear. Let's see if I have this right,

rotate object 1,wrapvalue(asin(length#/4.0)),wrapvalue(angle#),wrapvalue(asin(across#/4.0))  


I get that "1" is the object number (or is "object" the object number and "1" something else?. And the other 3 parameters are supposed to be rotation angles about x, y, z? If so, then:

angle_about_x = wrapvalue(asin(length#/4.0))
angle_about_y = wrapvalue(angle#)
angle_about_z = wrapvalue(asin(across#/4.0))

The x and y values sort of make sense. You're computing the angles of rotation about x and z based on the slope of the terrain? And angle# is an orientation angle----basically the angle of locomotion across the terrain when viewed from above.

So, that code could be correct. But again, not knowing darkbasic, I do not know if these are really the correct parameters to send to rotate object. Tell me this. What is the full description (from the darkbasic manual) of the rotate object function? Or if that is a function you wrote, what do you intend for it to do specifically? I assume that function constructs a rotation matrix. But you're passing in 3 angle, and so it must apply those rotations in some order. Does it rotate about x first, then y, then z? Or z, y, x? Or y, x, z? Also important, are those rotations specific about the object local axes or about world axes? These are important things to understand when using that function! Also, are you making sure that angle# is in radians? Without knowing some of these details, we probably can't provide any specific help---only suggestions.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on February 25, 2002 10:27:00 AM
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Good Points, all of them. I''ll try to be more specific next time.

The definition for the rotate object command is

quote:

This command will rotate the specified 3D object around all three dimensions. The object number should be specified using an integer value. The rotation angles should be specified using real numbers.

ROTATE OBJECT object number, x value, y value, z value



the function WRAPVALUE makes sure the float value is between 0 and 360. If the value exceeds 360 then it wraps the value back round to 0 and vice versa.

Due to this, I would assume the rotate function uses degrees and not radians.

As for which angle is worked on first, I have absolutely no idea. I guess it goes from x to y then to z.

Hope this helps,




Lazarus404
Lazarus404
Advertisement
Okay,

That description of rotate object still does not provide enough information to know what it does. It confirms what I suspected---that the function constructs and applies a rotation based on 3 separate rotation actions (one about each axis separately), but it does not specify which rotation comes first.

I did download the documentation, and discovered that by default rotate object rotates about x axis first, then y, then z. There is a function to reverse that order. It is impossible to rotate about y first if you use rotate object, but if you use yrotate object you can rotate about y first. We still need to know whether the rotations are done about world vs. local axes.

The documentation sort of sounds like the rotations are made about object axes (because of the word "dimensions") but it isn't totally clear. It could just as easily be about the world axes.

There is another set of functions, pitch object, roll object, yaw object, that provide alternate ways to rotate the object. Those functions most definitely rotate about the object local axes (pitch should be about local y, roll about local x, and yaw about local z). Because these other local rotation functions exist, it makes me want to think rotate object does rotate about world axes. This documentation leaves a lot to be desired.

The DarkBasic documentation is incomplete. I just don't like their descriptions of functions at all!

Your life will be easier if you are specifying rotations about the world axes. Your code is close to being correct in this case.

Do you know enough about this rotate object function to confirm that the rotations are performed about the world or object axes? If not, you can find out. Do this:

yrotate object 1, 1.5708
rotate object 1, 0.7854, 0., 0.

The first line rotates the object 90 degrees, so that its x axis points in the negative world z direction. This will be true whether the yrotate acts in the world space or local space. The second line rotates the object by 45 degrees about the "x" axis.

If rotate object acts about the world axes, then the object will be rotated about its local z axis (global z). If rotate object acts about the local axes, then the object will be rotated about its local x (global z).

This would work better with a picture, but I don't have time to make one and no place to host it.

Also, in your world, does "across" (left to right) correspond to the x axis or z axis of the terrain?

We're narrowing in on a solution here. If DarkBasic let you specific a rotation matrix directly, it would be straightforward. Using just DarkBasic functions we have to figure out exactly what the hell the functions are really doing first.

BTW, sorry for the rambling post, .

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on February 25, 2002 2:53:32 PM
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Okay, first things first.

After using your radian angles that you supplied, I rotated the object within a game loop and found negligable effect. I then added the code * (180 / M_PI#) where M_PI# is a user defined constant, so as to convert the value to degrees, and once run, the model rotated 45 degrees about the worlds x axis.

Therefore, this then must mean that the rotate object command accepts units in degrees and rotates about the world axis. Whereas to rotate about the local axis, it will require the yaw, roll, and pitch commands.

We''re getting there I hope


Lazarus404
Lazarus404

This topic is closed to new replies.

Advertisement