>>> what i want is a function like
>>>
>>> void moveWherePointed(Transform t1,float moveAmt)
>>>
>>> that updates t1's translation values from its rotational matix. Am I
>>> missing something somewhere. Does such a thing exist ?
first of all, you should look for a matrix algebra tutorial on the net and
try to understand how matrices work, and how a scene graph works. this is
essential for any 3d programming.
also i find that you should only post messages to this list that are
j3d-specific. there are a lots of places on the net that deal with general,
interactive and realtime 3d and with the underlying math. for example, look
up the comp.graphics.algorithms faq which you can find easily by searching
the internet or the java3d-archive on this server. the faq will probably
contain links to good vector/matrix algebra tutorials.
nevertheless, here is a brief explanation:
say you have a spaceship object in its own TransformGroup. within this
transform group (that is, in the spaceships local coordinate system), the
spaceship is oriented along the positive Z axis (its nose points into that
direction, locally.)
now let this be the direction into which you want to have the spaceship
travel - "forwards". take a vector that specifies this direction in the
spaceship's LOCAL transform group:
Vector3d dir=new Vector3d(0.,0.,1.); // points along positive z-axis
now transform this vector to WORLD coordinates:
Transform3D local2vworld = new Transform3D();
spaceshipNode.getLocalToVworld(local2vworld);
local2vworld.transform(dir);
your vector is now in world coordinates (depending on the Transform3D set
for your spaceshipNode, it points into different directions). you can
normalize this vector, scale it by say .001 (this is what you call
'moveAmt') and then add it to your spaceshipNode's translation in order to
move the ship into the direction it is pointing.
but this is true ONLY IF you specify the spaceship's position in WORLD
coordinates (i.e. if there is no other TransformNode between the
spaceshipNode and the root node, and if you multiply the spaceship
translation last). clearly, you could also move the ship into the same
direction by adding the vector (0.,0.,.001) to the LOCAL position of your
spaceship (if it is not scaled). it all depends on which TransformGroup you
want to apply the translation to, and how (at what time) the translational
value is multiplied into the Transform3D matrix of this group. again, take a
look at the math!
basically, the trick with all stuff like this is transforming vectors
between different TransformGroups by using the localToVworld matrix and its
inverse
(localToVworld.invert()==vworldToLocal).
>> I'd like to see this one answered, as I'm having the same problem, which
is
>> how to position a 3D object relative to the existing ViewPlatform, such
that
>> it seems to stay just ahead of the moving, rotating ViewPlatform.
say you want to have the object stay 10 units ahead, 2 units above your
viewplatform. take the vector (0.,2.,-10.), transform it to world
coordinates using the local2vworld matrix of your view platform, and use the
world coordinates to position the object.
afterwards, you might have to translate the world coordinates back to the
local coordinates of the parent TransformNode of your target node (if there
is such a node and if it has a non-identity matrix). in this case, use the
invert() of the target parent node's Transform3D to transform the
translation vector before you apply it.
BTW, beware of the following pitfall: Transform3D.transform(Vector3D)
behaves _different_ from Transform3D.transform(Point3D)!! If your coordinate
is a vector (that means, a direction "pointer" like in this case), you have
to use the Vector3D variant! if your coordinate is however a true, fixed
point, you have to use the other variant. if you have a Vector coordinate
stored in a Point3x object and apply a transformation to it, you will get
incorrect results.
the Point3D variant is the one which behaves as you would expect
(mathematically) - the vector is transformed by the matrix. the Vector3D
variant however subtracts the transformed null vector (0,0,0) from the
result, keeping the directional aspect of the vector.
hope it helps
-- julian
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".