« Return to Thread: Re: Rotation around Arbitrary axis addition to DisplayObject3D
Hi all,
I couldnt find a better way to do this, so i went ahead and added it into my DisplayObject3D class.
It rotates any DisplayObject3D around another DisplayObject3D (including itself) on any give axis... it basically replaces rotation. ( i saw that there was some little hack-together people had to use to achieve the same effect).
Below is the addition to displayObect3D, link to an example, and usage.
====================================================
SOURCE
http://pixelmixer.mine.nu/papervision/main.as
http://pixelmixer.mine.nu/papervision/DisplayObject3D.as
====================================================
EXAMPLE
http://djsparks.iweb.bsu.edu/papervision/arbitraryRotation_example1.html
====================================================
CLASS ADDITION
/**
* ________________________________________________________________________________________________
* ------------------------------------ I N C O M P L E T E ---------------------------------------
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Rotates the displayObject around an arbitrary axis of a given displayObject.
*
* @param angle:Number The angle to rotate;
* @param axis:Number3D The "axis" around which to rotate;
* @param targetObject:DisplayObject3D The object to rotate around.
*/
public function rotateArbitrary( angle:Number, axis:Number3D = null, targetObject:DisplayObject3D = null):void
{
if(!targetObject) targetObject = this;
if(!axis) axis = new Number3D(1,0,0);
var direction:Number3D = axis;
var originPoint:Number3D = new Number3D(targetObject.x , targetObject.y, targetObject.z);
var v:Number = Math.sqrt(direction.x*direction.x + direction.y*direction.y);
var w:Number = Math.sqrt(v*v + direction.z*direction.z);
var oF:Matrix3D = new Matrix3D([1,0,0,- originPoint.x,
0,1,0,-originPoint.y,
0,0,1,-originPoint.z,
0,0,0,1]);
var iF:Matrix3D = Matrix3D.inverse(oF);
var oG:Matrix3D;
if(v != 0)
{
oG = new Matrix3D([direction.x/v,direction.y/v,0,0,
- direction.y/v,direction.x/v,0,0,
0,0,1,0,
0,0,0,1]);
}
else
{
oG = Matrix3D.IDENTITY ();
}
var iG:Matrix3D = Matrix3D.inverse(oG);
var oH:Matrix3D = new Matrix3D([direction.z/w,0,-v/w,0,
0,1,0,0,
v/w,0, direction.z/w,0,
0,0,0,1]);
var iH:Matrix3D = Matrix3D.inverse(oH);
var W:Matrix3D = new Matrix3D([Math.cos(angle),-Math.sin(angle),0,0,
Math.sin(angle),Math.cos(angle),0,0,
0,0,1,0,
0,0,0,1]);
var P:Matrix3D = Matrix3D.multiply (Matrix3D.multiply(Matrix3D.multiply(Matrix3D.multiply(Matrix3D.multiply(Matrix3D.multiply(iF,iG),iH),W),oH),oG),oF);
this.transform.calculateMultiply( P ,transform );
if( this._transformDirty ) updateTransform();
}
=============================================================
USAGE
moon.rotateArbitrary (.02, new Number3D(1,1,1), earth);
earth.rotateArbitrary(.01, new Number3D(-1,1,1));
camera.rotateArbitrary(.02, new Number3D(1,1,1), earth);
camera.lookAt(earth);
--
Dustin Sparks _______________________________________________
Papervision3D mailing list
Papervision3D@...
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
« Return to Thread: Re: Rotation around Arbitrary axis addition to DisplayObject3D
| Free embeddable forum powered by Nabble | Forum Help |