This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > February 2004 > implementing look-at (target) vectors instead of orientation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
implementing look-at (target) vectors instead of orientation
|
|
| Chris Weaver 2004-02-09, 11:39 am |
| Hi,
I've written a VRML2 exporter which animates spotlights and Viewpoint
nodes using the PositionInterpolator and OrientationInterpolator.
These nodes are very often in a fairly deep parent/child hierarchy. I
now need to export animations where the PositionInterpolator is used
but instead of the OrientationInterpolator I need to make certain node
transforms always look-at a certain point (or other animated nodes).
In other words, I need to animate node positions with the
PositionInterpolator and at the same time implement a look-at vector
or target instead of setting the orientation. With this a viewpoint or
a spotlight could always look at a moving object or a fixed point.
Any ideas or examples how I could do this would be appreciated.
Chris.
| |
|
|
|
|
| Eckhard M. J?ger 2004-02-10, 12:30 pm |
| The Code is of LookAt is:
PROTO LookAt [
eventIn SFVec3f set_position
eventIn SFVec3f set_targetPos
eventIn SFVec3f set_upVector
field SFVec3f position 0 0 10
field SFVec3f targetPos 0 0 0
field SFVec3f upVector 0 1 0
field SFVec3f defaultLosVector 0 0 -1
eventOut SFRotation orientation_changed
]
{
Group {
children [
Script {
eventIn SFVec3f set_from IS set_position
eventIn SFVec3f set_to IS set_targetPos
eventIn SFVec3f set_upVec IS set_upVector
field SFVec3f from IS position
field SFVec3f to IS targetPos
field SFVec3f up IS upVector
field SFVec3f defLosVec IS defaultLosVector
field SFVec3f yAxis 0 1 0
eventOut SFRotation orientation_changed IS
orientation_changed
url ["java script:
// private:
// quaternion code from michael wagner
(http://vienna.eas.asu.edu/~wagner/academic/vrml98/)
// --michael wagner _is_ Dr. Quaternion!
function rot2quat(rot) {
s=Math.sin(rot[3]/2);
return new MFFloat(rot[0]*s, rot[1]*s, rot[2]*s,
Math.cos(rot[3]/2));
}
function quat2rot(quat) {
s=Math.sqrt(quat[0]*quat[0] + quat[1]*quat[1] +
quat[2]*quat[2]);
if(s<0.01) { return new SFRotation(1, 0, 0, 0); }
else { return new SFRotation(quat[0]/s,
quat[1]/s, quat[2]/s, 2*Math.acos(quat[3]));}
}
function quatMult(a,b) {
return new MFFloat(
a[3]*b[0] + a[0]*b[3] + a[1]*b[2] - a[2]*b[1],
a[3]*b[1] + a[1]*b[3] + a[2]*b[0] - a[0]*b[2],
a[3]*b[2] + a[2]*b[3] + a[0]*b[1] - a[1]*b[0],
a[3]*b[3] - a[0]*b[0] - a[1]*b[1] - a[2]*b[2]
);
}
function computeRot() {
// compute line of sight vector
var losVec = to.subtract(from);
// compute orientation of camera
var rotA = new SFRotation(defLosVec, losVec);
var cameraUp = rotA.multVec(yAxis);
var N2 = losVec.cross(up);
var N1 = losVec.cross(cameraUp);
var rotB = new SFRotation(N1, N2);
//orientation_changed = rotA.multiply(rotB);
orientation_changed = quat2rot(
quatMult(rot2quat(rotB), rot2quat(rotA)) );
}
// public:
function set_from(value) { from = value; computeRot();
}
function set_to(value) { to = value; computeRot(); }
function set_upVec(value) { up = value; computeRot(); }
"]
}
]
}
}
| |
| Chris Weaver 2004-02-18, 5:28 am |
| Thanks,Ihavenowdiscoveredanotherproblem.Mytargetnodesand
viewpoint/spotlightnodesarethemselveschildnodesdeepina
transformhierarchy.TheLookAtconversionworksbutonlyifthe
coordinatesareinabsoluteworldcoordinates,butbecausemy
positionsandorientationsarerelativetotheirparenttransformsit
doesn'twork.
HowcanIfindtheabsoluteworldpositionsofthechildnodestosend
totheLookAtproto?Thiswillresultinanabsoluteorientationin
worldspace,sothenhowcanconvertthistoarelativeorientation
forthechildnode?
Thisisallgettingverycomplicatednow.
Thanksagain,
Chris.
bart@neeneenee.de(EckhardM.J?ger)wroteinmessagenews:<15525540.0402100826.4c88dd11@posting.google.com>...
>TheCodeisofLookAtis:
>
>
>PROTOLookAt[
>}
| |
| Joerg Scheurich aka MUFTI 2004-02-18, 7:28 am |
| >HowcanIfindtheabsoluteworldpositionsofthechildnodes
Takealookat
http://www.csv.ica.uni-stuttgart.de...messurement.wrl
Thisworkswith2center000Proximitysensors(oneinthescenegraphbranch
oftheobjectandoneontherootleveloftheworld)andasimplescript.
toaccountthedifferencebetweenthe2Sensors.
solong
MUFTI
--
DannPresse<tretenSieein>
(auseinemSoftwarehandbuch)
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|