Erain 3D
-->

My rotation goes mad


For performance reason, Sandy offers a class which wraps the native Math.cos and Math.sin functions for some precomputed ones.

While it is much faster, it has some limitations :

  1. Initialization time. To be quite accurate, the precomputed values must be quite big. This long loop may take some time on slow computers. Sandy default settings is 0×020000 which is be a good compromise.
  2. The accuracy. Even if the precision is hight, in some special cases, the accuracy can be too low and results may be surprising. To avoid that, there's a simple line to add in your application
Matrix4.USE_FAST_MATH = false;

Example

Code example to illustrate the problem:

package
{
   import flash.display.Sprite; 
   import flash.events.*;
   import sandy.core.Scene3D;
   import sandy.core.data.*;
   import sandy.core.scenegraph.*;
   import sandy.materials.*;
   import sandy.materials.attributes.*;
   import sandy.primitive.*;
 
   public class TestBug extends Sprite 
   {
      private var scene:Scene3D;
      private var camera:Camera3D;
      private var sphere:Sphere;
 
      public function TestBug()
      { 
	 // We create the camera
	 camera = new Camera3D( 300, 300 );
	 camera.z = -200;
	 //Matrix4.USE_FAST_MATH = false;
	 // We create the "group" that is the tree of all the visible objects
	 var root:Group = createScene();
	 // We create a Scene and we add the camera and the objects tree 
	 scene = new Scene3D( "scene", this, camera, root ); 
	 // Listen to the heart beat and render the scene
	 addEventListener( Event.ENTER_FRAME, enterFrameHandler );         
      }
 
      // Create the scene graph based on the root Group of the scene
      private function createScene():Group
      {
         // Create the root Group
         var g:Group = new Group(); 
         // Create a sphere so we have something to show
         sphere = new Sphere("sphere", 50,20,20); 
	 // We need to add the cube to the group
	 g.addChild( sphere );
	return g;
      }
 
      // The Event.ENTER_FRAME event handler tells the world to render
      private function enterFrameHandler( event : Event ) : void
      {
         sphere.pan += 10;
	 sphere.roll += 10;
	 scene.render();
      }
   }
}