Jump to content

Clamping Rotation, physics


Lillani Lowell
 Share

Recommended Posts

So, I am an advanced coder, but when it comes to physics and certain rotations; Second Life tends to have me perplexed (I'm not a math wizard, anyway).

This is what I'm trying to do...

I am working on a vehicle akin to to a hovercraft that when it moves forward, back, left, or right it needs to tilt/lean in the direction its moving (so, I'm using llLookAt) to create a dampened tilt in the direction it needs to move... this vehicle also tracks targets and needs to use llRotLookAt to rotate itself and orient the front of the vehicle toward a target.

And here's the problem I am running into...

llRotLookAt and llLookAt are not playing together nicely; whenever I used llLookAt it seems to orient the X axis of the vehicle with the X axis of the world; which is fine and dandy if the vehicle didn't need to physically turn.

How do I make llLookAt maintain an upward Z axis while ignoring the forward X axis and letting llRotLookAt do its thing? Difficulty, no axis can be locked as it needs to be able to tilt on the X or Y axis freely while being able to rotate around the Z axis.

Also to note, using the built in vehicle features is not an option; all the physic behaviours have to be custom coded.

Link to comment
Share on other sites

May I suggest:

rotation Vec2RotHor( vector V ){    V = llVecNorm( V );    vector UP = < 0.0, 0.0, 1.0 >;    vector LEFT = llVecNorm(UP%V);    V = llVecNorm(LEFT%UP); // you want V confined to the horizontal plane    return llAxes2Rot(V, LEFT, UP);}

Where vector V is the direction you want the X-axis to point
The function returns the requested rotation.

Reference: llAxes2Rot, right and wrong in the wiki

:smileysurprised::):smileyvery-happy:

 

Link to comment
Share on other sites

Hey Dora, thanks for the response, but I don't understand what it's returning or how I would use its results, essentially.

Let's say I want the Z axis of my object to point at <10, 0, 10> (relative of its position, leaning forward)... and I want the X axis of my object pointing to <20, 30, 15> (a random coordinate in the region).

How am I using this function? And am I using it in llLookAt? llRotLookAt?

 

Link to comment
Share on other sites

I was focused on what you said about clamping the Z axis and assumed vertical up
But you can clamp Z by setting UP in the function to what you want
You need to normalize it with UP = llVecNorm( UP );

You may want to use Vec2RotTrue( vector V ) or Vec2RotHor( vector V ) in the reference

The function is returning the rotation of your object, to rotate your object to the indicated rotation:

llSetRot( Vec2RotTrue( V ));

or similar for physical objects

 :smileysurprised::):smileyvery-happy:

Edit: to answer your last question: the function replaces llLookAt and the returned rotation should be used in llRotLookAt

Deep note:
All axes used in llAxes2Rot must  be orthogonal and unit vectors
This means that random z and x vectors will not satisfy the demands in general
The given function recalculate either x or z direction to meet the demand

  1. Vec2RotTrue( vector V ) will calculate new z perpendicular to x and keep x
  2. Vec2RotHor( vector V ) will calculate new x perpendicular to z and keep z
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...