Re: Rotation around Arbitrary axis addition to DisplayObject3D

35 messages Options
Embed this post
Permalink
1 2
Dustin Sparks

Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Hi,
I would like to rotate a DisplayObject3D arround an axis !
So what i would like to do is to rotate an object arround its center, using the following code makes a rotation arround the ORIGIN of the object which in my case doesn't match with its center:
 
-----------------------------------------------------------------------------------------
var rootNode:DisplayObject3D = new DisplayObject3D();
 
Then when I press a specific key:
 
rootNode.rotationY += 5 ;
-----------------------------------------------------------------------------------------
 
Can i use your method to make the rotation arround the center.
 
You said that it was incomplet !!!!!!!!!!!!!!


Dustin Sparks <[hidden email]> a écrit :
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dustin Sparks
I copied and pasted the following method, there is two errors, the first one is that IDENTITY is not a method so we have to put: IDENTITY instead of IDENTITY().
The second is :
calculateMultiply !!!!!!  It doesn't find this method !!

Dustin Sparks <[hidden email]> a écrit :
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Sorry I thing that I don't understand the errors !!  Please ignore the precedent email.
These are the errors:
 
Error1
Attempted access of inaccessible method IDENTITY through a reference with static type
 
Error2
Call to a possibly undefined method calculateMultiply through a reference with static type org.papervision3d.core:Matrix3D. DisplayObject3D.as 


Moon Moon <[hidden email]> a écrit :
I copied and pasted the following method, there is two errors, the first one is that IDENTITY is not a method so we have to put: IDENTITY instead of IDENTITY().
The second is :
calculateMultiply !!!!!!  It doesn't find this method !!

Dustin Sparks <[hidden email]> a écrit :
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses._______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Peter Kapelyan

Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
I think you are trying a very hard way - if you are doing something very simple.
You can send me code I a promise I will not show anyone - and send back just to you if you want..
I think I can do what you want in 2-3 lines of code - no more. After that you can always do any other method :)

 
On 6/26/07, Moon Moon <[hidden email]> wrote:
Sorry I thing that I don't understand the errors !!  Please ignore the precedent email.
These are the errors:
 
Error1
Attempted access of inaccessible method IDENTITY through a reference with static type
 
Error2
Call to a possibly undefined method calculateMultiply through a reference with static type org.papervision3d.core:Matrix3D. DisplayObject3D.as 
 


Moon Moon <[hidden email]> a écrit :
I copied and pasted the following method, there is two errors, the first one is that IDENTITY is not a method so we have to put: IDENTITY instead of IDENTITY().
The second is :
calculateMultiply !!!!!!  It doesn't find this method !!

Dustin Sparks <[hidden email]> a écrit :
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses._______________________________________________

Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Peter Kapelyan

Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Actually send me your first code (if you still have it) or test code that I can show you easy way in - the smaller the faster you'll get it back :)

On 6/26/07, Peter Kapelyan <[hidden email]> wrote:
I think you are trying a very hard way - if you are doing something very simple.
You can send me code I a promise I will not show anyone - and send back just to you if you want..
I think I can do what you want in 2-3 lines of code - no more. After that you can always do any other method :)

 
On 6/26/07, Moon Moon <[hidden email]> wrote:
Sorry I thing that I don't understand the errors !!  Please ignore the precedent email.
These are the errors:
 
Error1
Attempted access of inaccessible method IDENTITY through a reference with static type
 
Error2
Call to a possibly undefined method calculateMultiply through a reference with static type org.papervision3d.core:Matrix3D. DisplayObject3D.as 
 


Moon Moon <[hidden email]> a écrit :
I copied and pasted the following method, there is two errors, the first one is that IDENTITY is not a method so we have to put: IDENTITY instead of IDENTITY().
The second is :
calculateMultiply !!!!!!  It doesn't find this method !!

Dustin Sparks <[hidden email]> a écrit :
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
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses._______________________________________________

Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
So to explain what I want to do:
 
I have a scene, I put in it a rootNode which is a displayObject3D representing a collada fille created from a 3ds file.
 
I want that when the user clicks on 'M', the camera rotates arround the object (arround the 3d model).
 
 
FIRST IDEA:
 
My first idea was to do:
 
rootNode.pan(5);
 
But the problem is that rootNode rotates attound its ORIGIN which doesn't match with ITS center. so it dosn't show a rotation of a camera arround the object but a rotation of rootNode arround its origin. I know that rotating the rootNode is a Fake of rotation the camera arround the object , it is a trick.  SO If i can rotate the rootNode arround its CENTER it will be perfect.
 
 
THE SECOND IDEA: some people gave me this solution:
 
private function moveCamera():void
  {   
    var dist:Number = camera.distanceTo(rootNode);  
    camera.moveForward(dist);
    camera.pan(5);  
    camera.moveForward(-dist);
  }
 
 
But is is the same problem, the distance between the camera and the rootNode is calculated not to the center of the rootNode but its ORIGIN, so the movement is horrible. In addition to that when i press many times on the 'm' key, the camera became far and far from the rootNode.
 
SO I want to use my first idea, the only problem is HOW to make a rotation on the rootNode arround ITS center instead of its origin.
 
DO YOU HAVE ANY IDEA ?
 
PS: which code do you want exactly ?


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Peter Kapelyan

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Ok I understand now - yes you will need Math for this unless you want a messy hack (which i can really try to think of) :) But I can't promise anything...hope you get that other code to work for now...
 
On 6/26/07, Moon Moon <[hidden email]> wrote:
So to explain what I want to do:
 
I have a scene, I put in it a rootNode which is a displayObject3D representing a collada fille created from a 3ds file.
 
I want that when the user clicks on 'M', the camera rotates arround the object (arround the 3d model).
 
 
FIRST IDEA:
 
My first idea was to do:
 
rootNode.pan(5);
 
But the problem is that rootNode rotates attound its ORIGIN which doesn't match with ITS center. so it dosn't show a rotation of a camera arround the object but a rotation of rootNode arround its origin. I know that rotating the rootNode is a Fake of rotation the camera arround the object , it is a trick.  SO If i can rotate the rootNode arround its CENTER it will be perfect.
 
 
THE SECOND IDEA: some people gave me this solution:
 
private function moveCamera():void
  {   
    var dist:Number = camera.distanceTo(rootNode);  
    camera.moveForward(dist);
    camera.pan(5);  
    camera.moveForward(-dist);
  }
 
 
But is is the same problem, the distance between the camera and the rootNode is calculated not to the center of the rootNode but its ORIGIN, so the movement is horrible. In addition to that when i press many times on the 'm' key, the camera became far and far from the rootNode.
 
SO I want to use my first idea, the only problem is HOW to make a rotation on the rootNode arround ITS center instead of its origin.
 
DO YOU HAVE ANY IDEA ?
 
PS: which code do you want exactly ?


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Peter Kapelyan

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
In reply to this post by Moon Moon
Ok i thought of a way - If you send me all the files I can do it for you but it will be a simple hack...not very hard.
This is the idea

Make a node
Always look at node with camera.
Always make your object (DAE?) look at node also.
 
Now , when you move your camera around - it will rotate the node.
Since object is always looking at node it will rotate too (but so will camera on an axis so might have to lock it afterwards)
 
So finally just use MYDAE.moveBackward to move it away from the node (depending on rotation- already done lol)
 
So it is very easy and could work and could try to get it to wrk for you if you want-but would rather get it to work for you than start from scratch file....so you can still send file and I will try - maybe tommorow...but I am done thinking! :)
Sorry but today will be very busy with my son (his last day of school-half day) and have tonight booked for some other projects (away3d)...
 
-Pete

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Dustin Sparks

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
calculateMultiply is part of your Mesh3D class. You should already have it. Make sure that its in your Matrix3D class, and also make sure that your DisplayObject3D class is importing the Mesh3D class. It might help if you grab the most recent SVN.

Also, i havent tried it with a collada file with more than 1 object in it yet. (Moon, can you send me your collada file so i can test that out? I dont have any that act as you describe).

In the example i gave, the camera rotates around the earth object like you said. I dont see why it wouldnt work if you tell it to rotate around the nested object.
===============

From the way it sounds.. you want to rotate the object around a central point, but the central point isnt an object?  I overlooked this in my code, but the way you can do it is fairly simple.

Modify the rotationArbitrary method in your DisplayObject3D class to be

rotateArbitrary( angle:Number, axis:Number3D = null, targetObject:* = null)

now... instead of sending the object, or not sending anything at all as your targetObject, you'll need to send the Number3D representing the center of your object...

once you change that... try these:

rootNode.rotationArbitrary(.05, new Number3D(0,1,0), new Number3D(x,y,z));

x being the X coordinate that you want to be the new center.
y being the Y coordinate of your new center.
z being the Z coordinate of your new center.

Note that rotations can be in any direction based on the first Number3D;
in this example its a rotation around the Y axis (0,1,0). You dont have to use integers. You can rotate it on any axis ( 2.1, 0.45, 5)  if you want.



========== everyone...
test this out and let me know if it works, i've tried a few tests, but I havent tried with multiple nested objects, and I havent been able to test it many times.

==========

I also want to add an offset value to the function, which would allow you to specify a rotation distance. Currently, it just rotates from where its placed in the file.

On 6/26/07, Peter Kapelyan <[hidden email] > wrote:
Ok i thought of a way - If you send me all the files I can do it for you but it will be a simple hack...not very hard.
This is the idea

Make a node
Always look at node with camera.
Always make your object (DAE?) look at node also.
 
Now , when you move your camera around - it will rotate the node.
Since object is always looking at node it will rotate too (but so will camera on an axis so might have to lock it afterwards)
 
So finally just use MYDAE.moveBackward to move it away from the node (depending on rotation- already done lol)
 
So it is very easy and could work and could try to get it to wrk for you if you want-but would rather get it to work for you than start from scratch file....so you can still send file and I will try - maybe tommorow...but I am done thinking! :)
Sorry but today will be very busy with my son (his last day of school-half day) and have tonight booked for some other projects (away3d)...
 
-Pete

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
Dustin Sparks
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Collin Cusce

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
John Dyer-2

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Here is a quick method (including math) that will do this for you. Basically you can orbit one object (object) around the other (target). If you leave out the target, the object will orbit around 0,0,0.
 
  public static function setAngularPosition(obj:DisplayObject3D, theta:Number, phi:Number, radius:Number, target:DisplayObject3D = null):void {
   
   // get current position
   var x:Number = obj.x;
   var y:Number = obj.y;
   var z:Number = obj.z;
   
   // offset by the target object
   if (target != null) {
    
    x -= target.x;
    y -= target.y;
    z -= target.z;     
   }   
   
   // limit phi (normally -pi/2 - pi/2)
   if (phi < -Math.PI/2) {   
    phi = -Math.PI/2;
   } else if (phi > Math.PI/2) {
    phi = Math.PI/2;
   }
   
   // adjust theta (0 - 2pi)
   if (theta < -Math.PI) {
    theta = Math.PI*2 + theta;
   } else if (theta > Math.PI) {
    theta =  theta - Math.PI*2;
   }  
   
   // note: Z and Y have been flipped to make Y be the central axis
   // see http://mathworld.wolfram.com/SphericalCoordinates.html for explanation
   var sinPhi:Number = Math.sin(phi);
   var newX:Number = radius*Math.cos(theta)*sinPhi;
   var newZ:Number = radius*Math.sin(theta)*sinPhi ;
   var newY:Number = radius*Math.cos(phi);   
   
   // re-adjust to target
   if (target != null) {
    newX += target.x;
    newY += target.y;   
    newZ += target.z;     
   }
   
   obj.x = newX;
   obj.y = newY;
   obj.z = newZ;
   
  }


>>> On 6/26/2007 at 12:59 PM, in message <[hidden email]>, "Collin Cusce" <[hidden email]> wrote:
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Dustin Sparks

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
In reply to this post by Collin Cusce
Some javascript/style in this post has been disabled (why?)
yep, thats how its done in the rotationArbitrary. The only thing is, it works directly with Matrix3D to do the movements. I'm sure theres probably an easier/better way, but the hack-together with moving the camera backward continuously just wasnt working for me. It required the entire scene to follow the camera, which isnt all that hard, but I dont really like the fact that its not really a stationary scene, but a scene flying through space continuously.

I'm working on making it more usable, where you can specify an altitude along with the angle, 2 objects or an object and a point.

On 6/26/07, Collin Cusce <[hidden email]> wrote:
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
Dustin Sparks
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Collin Cusce

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
You realllllly dont need to use this class. The effect is pretty simple.... takes 7 lines (not including lookAt and render).

Check out the positionAndUpdate() function.

Here's the SWF. http://larry.onlinekarma.net/flash/RotationTest.swf

package {
    import flash.display.*;
    import flash.events.*;
   
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.* ;
    import org.papervision3d.materials.*
    import org.papervision3d.scenes.MovieScene3D;

    public class RotationTest extends Sprite
    {
        private var earth:DisplayObject3D;
        private var sun:DisplayObject3D;
        private var moon:DisplayObject3D;
        private var scene:MovieScene3D;
        private var camera:FreeCamera3D;
        private var sunGroup:DisplayObject3D;
        private var earthGroup:DisplayObject3D;
        private var earthToSun:int = 6000;
        private var moonToEarth:int = 800;
        private var moonSpeed:int = 10; //degrees
        private var earthSpeed:int = 5; //degrees;
        private var earthAngle:int = 0;
        private var moonAngle:int = 0;
        public function RotationTest()
        {
            var emat:WireframeMaterial = new WireframeMaterial(0x44FF33,100);
            var smat:WireframeMaterial = new WireframeMaterial(0xFF4433,100);
            var mmat:WireframeMaterial = new WireframeMaterial(0x666666,100);
           
            earth = new Sphere(emat, 400, 20, 20);
            sun = new Sphere(smat,2000,20,20);
            moon = new Sphere(mmat,100,20, 20);
            camera = new FreeCamera3D();
            scene = new MovieScene3D(new Sprite());
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
            stage.stageFocusRect = false;
           
            scene.container.x = 300;
            scene.container.y = 400;
            camera.x = 10000;
            camera.z = 10000;
            addChild(scene.container);
           
            earthGroup = new DisplayObject3D();
            earthGroup.addChild(earth);
            earthGroup.addChild(moon);
           
            sunGroup = new DisplayObject3D();
            sunGroup.addChild(earthGroup);
            sunGroup.addChild(sun);
            moon.y = moon.z = earth.y = earth.z = sun.y = sun.z = 0;
            //the following is just for emphasis to show the positions start at 0
            moon.x = 0;
            earth.x = 0;
            sun.x = 0;
           
            //view.scene.addChild(sun);
          //  scene.addChild(earth);
            //scene.addChild(moon);
           
            scene.addChild(sunGroup);
           
            stage.addEventListener(Event.ENTER_FRAME, positionAndUpdate);
        }
        private function positionAndUpdate(e:Event):void{
            moon.x = moon.y = moon.z = 0;
            moonAngle += moonSpeed;
            earthAngle += earthSpeed;
            moon.x = moonToEarth;
            earthGroup.rotationY = moonAngle;
            earthGroup.x = earthToSun;
            sunGroup.rotationY = earthAngle;
            camera.lookAt(sun);
            scene.renderCamera(camera);
        }
    }
}

See, no math. Very simple.

On 6/26/07, Dustin Sparks <[hidden email]> wrote:
yep, thats how its done in the rotationArbitrary. The only thing is, it works directly with Matrix3D to do the movements. I'm sure theres probably an easier/better way, but the hack-together with moving the camera backward continuously just wasnt working for me. It required the entire scene to follow the camera, which isnt all that hard, but I dont really like the fact that its not really a stationary scene, but a scene flying through space continuously.

I'm working on making it more usable, where you can specify an altitude along with the angle, 2 objects or an object and a point.

On 6/26/07, Collin Cusce <[hidden email]> wrote:
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
Dustin Sparks
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Peter Kapelyan

Re: RE : Re: RE : RE : Re: Rotation around Arbitrary axis addition to DisplayObject3D

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Thank you Collin - no math :) And I didn't have to write it (the no-math part) :)
Moon Moon you should be very happy now!

 
On 6/26/07, Collin Cusce <[hidden email]> wrote:
You realllllly dont need to use this class. The effect is pretty simple.... takes 7 lines (not including lookAt and render).

Check out the positionAndUpdate() function.

Here's the SWF. http://larry.onlinekarma.net/flash/RotationTest.swf

package {
    import flash.display.*;
    import flash.events.*;
   
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.* ;
    import org.papervision3d.materials.*
    import org.papervision3d.scenes.MovieScene3D;

    public class RotationTest extends Sprite
    {
        private var earth:DisplayObject3D;
        private var sun:DisplayObject3D;
        private var moon:DisplayObject3D;
        private var scene:MovieScene3D;
        private var camera:FreeCamera3D;
        private var sunGroup:DisplayObject3D;
        private var earthGroup:DisplayObject3D;
        private var earthToSun:int = 6000;
        private var moonToEarth:int = 800;
        private var moonSpeed:int = 10; //degrees
        private var earthSpeed:int = 5; //degrees;
        private var earthAngle:int = 0;
        private var moonAngle:int = 0;
        public function RotationTest()
        {
            var emat:WireframeMaterial = new WireframeMaterial(0x44FF33,100);
            var smat:WireframeMaterial = new WireframeMaterial(0xFF4433,100);
            var mmat:WireframeMaterial = new WireframeMaterial(0x666666,100);
           
            earth = new Sphere(emat, 400, 20, 20);
            sun = new Sphere(smat,2000,20,20);
            moon = new Sphere(mmat,100,20, 20);
            camera = new FreeCamera3D();
            scene = new MovieScene3D(new Sprite());
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
            stage.stageFocusRect = false;
           
            scene.container.x = 300;
            scene.container.y = 400;
            camera.x = 10000;
            camera.z = 10000;
            addChild(scene.container);
           
            earthGroup = new DisplayObject3D();
            earthGroup.addChild(earth);
            earthGroup.addChild(moon);
           
            sunGroup = new DisplayObject3D();
            sunGroup.addChild(earthGroup);
            sunGroup.addChild(sun);
            moon.y = moon.z = earth.y = earth.z = sun.y = sun.z = 0;
            //the following is just for emphasis to show the positions start at 0
            moon.x = 0;
            earth.x = 0;
            sun.x = 0;
           
            //view.scene.addChild(sun);
          //  scene.addChild(earth);
            //scene.addChild(moon);
           
            scene.addChild(sunGroup);
           
            stage.addEventListener(Event.ENTER_FRAME, positionAndUpdate);
        }
        private function positionAndUpdate(e:Event):void{
            moon.x = moon.y = moon.z = 0;
            moonAngle += moonSpeed;
            earthAngle += earthSpeed;
            moon.x = moonToEarth;
            earthGroup.rotationY = moonAngle;
            earthGroup.x = earthToSun;
            sunGroup.rotationY = earthAngle;
            camera.lookAt(sun);
            scene.renderCamera(camera);
        }
    }
}

See, no math. Very simple.


On 6/26/07, Dustin Sparks <[hidden email]> wrote:
yep, thats how its done in the rotationArbitrary. The only thing is, it works directly with Matrix3D to do the movements. I'm sure theres probably an easier/better way, but the hack-together with moving the camera backward continuously just wasnt working for me. It required the entire scene to follow the camera, which isnt all that hard, but I dont really like the fact that its not really a stationary scene, but a scene flying through space continuously.

I'm working on making it more usable, where you can specify an altitude along with the angle, 2 objects or an object and a point.

On 6/26/07, Collin Cusce <[hidden email]> wrote:
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
Dustin Sparks
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

Rotation around Arbitrary axis addition to DisplayObject3D, ROtation CAMERA SOLVED

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
THINK you guys, it works very good. This is my final solution:
 
So, first:
 I put an cube at the center of my 3d model, then I make it NOT visible.
cubeNode.visible = false;
 
Then:
I calculate the distance between my camera and THE CENTER of my 3d model ( means the distance between the camera and the cube).
 var dist:Number = camera.distanceTo(cubeNode); 
 
Then:
I go forward ( inside the 3d model)
 camera.moveForward(dist);
 
Then:
I do my rotation of the camera
camera.pan(5);
 
Then:
I come back
camera.moveBackward(dist);

AND FINALY the important thing is to put:
camera.lookAt(cubeNode, new Number3D(0,1,0));
 
So the camera will ALWAYS look at the center of the scene.
 
This code aloows me to rotate the CAMERA arround my 3d model. The only lack is that i have to calculate the center of my 3d model by hand !!! means I add a cube and try to locate it at the center of my model, then make is NOT visible.
It is a bit shit but it is the only way which gives me a very nice movment.
 
 
Thinks guys.
Moon.
 
 
 
PS: if you have a way to find the center of a collada file please let me know so i will be able to make an application which calculates the center of the scene. :)

Peter Kapelyan <[hidden email]> a écrit :
Thank you Collin - no math :) And I didn't have to write it (the no-math part) :)
Moon Moon you should be very happy now!

 
On 6/26/07, Collin Cusce <[hidden email]> wrote:
You realllllly dont need to use this class. The effect is pretty simple.... takes 7 lines (not including lookAt and render).

Check out the positionAndUpdate() function.

Here's the SWF. http://larry.onlinekarma.net/flash/RotationTest.swf

package {
    import flash.display.*;
    import flash.events.*;
   
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.* ;
    import org.papervision3d.materials.*
    import org.papervision3d.scenes.MovieScene3D;

    public class RotationTest extends Sprite
    {
        private var earth:DisplayObject3D;
        private var sun:DisplayObject3D;
        private var moon:DisplayObject3D;
        private var scene:MovieScene3D;
        private var camera:FreeCamera3D;
        private var sunGroup:DisplayObject3D;
        private var earthGroup:DisplayObject3D;
        private var earthToSun:int = 6000;
        private var moonToEarth:int = 800;
        private var moonSpeed:int = 10; //degrees
        private var earthSpeed:int = 5; //degrees;
        private var earthAngle:int = 0;
        private var moonAngle:int = 0;
        public function RotationTest()
        {
            var emat:WireframeMaterial = new WireframeMaterial(0x44FF33,100);
            var smat:WireframeMaterial = new WireframeMaterial(0xFF4433,100);
            var mmat:WireframeMaterial = new WireframeMaterial(0x666666,100);
           
            earth = new Sphere(emat, 400, 20, 20);
            sun = new Sphere(smat,2000,20,20);
            moon = new Sphere(mmat,100,20, 20);
            camera = new FreeCamera3D();
            scene = new MovieScene3D(new Sprite());
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
            stage.stageFocusRect = false;
           
            scene.container.x = 300;
            scene.container.y = 400;
            camera.x = 10000;
            camera.z = 10000;
            addChild(scene.container);
           
            earthGroup = new DisplayObject3D();
            earthGroup.addChild(earth);
            earthGroup.addChild(moon);
           
            sunGroup = new DisplayObject3D();
            sunGroup.addChild(earthGroup);
            sunGroup.addChild(sun);
            moon.y = moon.z = earth.y = earth.z = sun.y = sun.z = 0;
            //the following is just for emphasis to show the positions start at 0
            moon.x = 0;
            earth.x = 0;
            sun.x = 0;
           
            //view.scene.addChild(sun);
          //  scene.addChild(earth);
            //scene.addChild(moon);
           
            scene.addChild(sunGroup);
           
            stage.addEventListener(Event.ENTER_FRAME, positionAndUpdate);
        }
        private function positionAndUpdate(e:Event):void{
            moon.x = moon.y = moon.z = 0;
            moonAngle += moonSpeed;
            earthAngle += earthSpeed;
            moon.x = moonToEarth;
            earthGroup.rotationY = moonAngle;
            earthGroup.x = earthToSun;
            sunGroup.rotationY = earthAngle;
            camera.lookAt(sun);
            scene.renderCamera(camera);
        }
    }
}

See, no math. Very simple.


On 6/26/07, Dustin Sparks <[hidden email]> wrote:
yep, thats how its done in the rotationArbitrary. The only thing is, it works directly with Matrix3D to do the movements. I'm sure theres probably an easier/better way, but the hack-together with moving the camera backward continuously just wasnt working for me. It required the entire scene to follow the camera, which isnt all that hard, but I dont really like the fact that its not really a stationary scene, but a scene flying through space continuously.

I'm working on making it more usable, where you can specify an altitude along with the angle, 2 objects or an object and a point.

On 6/26/07, Collin Cusce <[hidden email]> wrote:
Let me make sure I have this right. You have two objects, one representing a stationary object (such as the sun), the other rotates around it (like the earth does around the sun)?

If this is correct... move the sun and earth group to the origin, apply rotation on earth, move sun and earth group back to their spots.

No math required.

At least this is how I'd do it in OpenGL.

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
Dustin Sparks
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

Changing textures in real time

Reply Threaded More More options
Print post
Permalink
Hi guys,
I am building a 3d apllication, importing a collada file, and visualizing the 3d model using pv3d.
Everything is going right.
I just want to try to change the textures of my 3d model in real time.
My solution is to create another collada scene (the same model but changing just the textures)
 
But this is a bit messy, because i have already done it, so I am looking for a solution which allows me just to modify the textures without rebuilding all the scene from the begining ( coz the geometry doesn't change, it is only the textures)
 
If you have any suggestions please let me know.
 
Thinks.


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
John Grden

Re: Changing textures in real time

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
I ran up against that very issue with the CS3 component.  I didn't find an elegant solution around it in time for launch :)

On 7/2/07, Moon Moon < [hidden email]> wrote:
Hi guys,
I am building a 3d apllication, importing a collada file, and visualizing the 3d model using pv3d.
Everything is going right.
I just want to try to change the textures of my 3d model in real time.
My solution is to create another collada scene (the same model but changing just the textures)
 
But this is a bit messy, because i have already done it, so I am looking for a solution which allows me just to modify the textures without rebuilding all the scene from the begining ( coz the geometry doesn't change, it is only the textures)
 
If you have any suggestions please let me know.
 
Thinks.


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
[  JPG  ]
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Moon Moon

Changing textures in real time

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
It's a shame lol.
I am gonna go throw it, I'll let you know if I find something.
Peace.
 
Moon

John Grden <[hidden email]> a écrit :
I ran up against that very issue with the CS3 component.  I didn't find an elegant solution around it in time for launch :)

On 7/2/07, Moon Moon < [hidden email]> wrote:
Hi guys,
I am building a 3d apllication, importing a collada file, and visualizing the 3d model using pv3d.
Everything is going right.
I just want to try to change the textures of my 3d model in real time.
My solution is to create another collada scene (the same model but changing just the textures)
 
But this is a bit messy, because i have already done it, so I am looking for a solution which allows me just to modify the textures without rebuilding all the scene from the begining ( coz the geometry doesn't change, it is only the textures)
 
If you have any suggestions please let me know.
 
Thinks.

Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org




--
[  JPG  ] _______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Dan R-4

Re: Changing textures in real time

Reply Threaded More More options
Print post
Permalink
In reply to this post by Moon Moon
Some javascript/style in this post has been disabled (why?)
Couldn't you just assing the model a new MaterialList?

On 7/2/07, Moon Moon <[hidden email]> wrote:
Hi guys,
I am building a 3d apllication, importing a collada file, and visualizing the 3d model using pv3d.
Everything is going right.
I just want to try to change the textures of my 3d model in real time.
My solution is to create another collada scene (the same model but changing just the textures)
 
But this is a bit messy, because i have already done it, so I am looking for a solution which allows me just to modify the textures without rebuilding all the scene from the begining ( coz the geometry doesn't change, it is only the textures)
 
If you have any suggestions please let me know.
 
Thinks.


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
1 2