|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
03-16-2008 08:06
Imagine "master" and "slave" prims, which communicate between each other with chat; the master prim can tell the slave where to position itself (in regional coordinates) as as to always be a certain distance from the precise centre of a certain face of the master. The two prims are not linked, nor can they be.
How can a prim determine, say, the regional position of the centre of one of its faces, given that said prim may be in any regional position and/or rotation at any time?
|
|
Snowman Jiminy
Registered User
Join date: 23 Dec 2007
Posts: 424
|
03-16-2008 08:16
You need two steps in the code, one to get the position and rotation of the "slave" prim, and an offset to the point on the face you are interested in (worked out manually, assuming the prim stays the same size). this should be possible, but I am no master at LSL.
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
03-16-2008 08:44
From: Snowman Jiminy ... an offset to the point on the face you are interested in (worked out manually, assuming the prim stays the same size). This is really the only tricky part. You need to prepare your object at zero rotation, and record global normal vectors for each of the faces you're interested in. For a cube, that's relatively straightforward. Then once you have them, you can just rotate the face-vector you want by the object's current rotation (face-vector * llGetRot).
|
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
03-16-2008 09:00
Both prims are fixed-size cuboids, so I know the relative position of each face - that's not a problem. This is more to do with calculating the region coordinate vector of a face given that information together with the master prim's own llGetPos() vector. It looks like me to be an issue of 3D trigonometry, but I'm wondering if there's an easier way before I break out my old maths textbooks.
Rezzing the objects with a certain rotation first is not an option - it needs to be able to be rezzed quickly in any position and rotation. The current position of the slave prim is irrelevant - all the master prim is going to do is instruct the slave to move to a position and rotation relative to itself.
It might help to think of it as a duck with a duckling that always follows on the duck's tail. If the duck moves forward, so does the duckling; if the duck turns 30 degrees, the duckling describes an arc, maintaining its position directly behind the duck and a certain distance away. Quack quack. The difference is that the master prim (the duck) isn't propelling itself; it's being moved by the user, and it knows not where other than llGetPos() and llGetRot().
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-16-2008 12:24
Given the position and rotation of the objects at any time: vector masterObjPos = ...; vector slaveObjRot = ...; rotation masterObjRot = ...; rotation slaveObjRot = ...;
Get the original relative position of the prim: vector initialRelativePos = (slaveObjPos-masterObjPos)/masterObjRot; rotation initialRelativeRot = slaveObjRot/masterObjRot;
Then when you want to calculate a new position at a point in time (once 'masterObjPos' and 'masterObjRot' are recalculated): vector newSlavePos = masterObjPos+initialRelativePos*masterObjRot; rotation newSlaveRot = initialRelativeRot*masterObjRot;
|
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
03-17-2008 08:36
Thanks - turns out it's unnecessary. There is a way of linking the slave prim in after all, thank goodness, and it's then easier and more efficient in other ways too.
Thanks again for the help.
|