msgbartop
Just share my knowledge..It may be a small thing..Read at your own risk.. :-)
msgbarbottom

How rotation camera3d and viewer3d worked in Away3d

Rotation in Away3D Flash engine

In this blog entry we are going to learn about How the Rotation and camera3d and viewer3d in away3d flash engine.

Red line = x-axis

Blue line = y-axis

Green Line = z-axis

How Rotation works ..?

Rotation in away3d based on the three axis . Those are x.y and z.  the component is rotated take any one of this axis as a center then rotated. In my last post the sphere is rotated along with x axis. In that example the axis is like that (see below )


sphere.rotationX = sphere.x + 1;

The sphere takes x axis as a center and rotate like above…

In this example we add two or more components in the ObjectContainer3D then rotate this objects. In this example we are going to learn about how camera3D and Viewer3D works.

How Camera3D works ..?

Camera3d = real camera

view3d = lens the viewr of the camara

renderer = recording in real cam

scen3d = what we seen

This diagram explained in Papervision3d Essential book.. In this diagram your clearly understood about camera3d.

If we assume Camera 3d is like a real camera . we assume it is with in our application in invisible mode.

The viewerport (view3d) is an lens or what you are view using the camera.

The render engine is recording engine in the real camera. In the real camera If  we start the record then only we can see the changes otherwise not. Like same as in camera3d we called

viewer.render()

method each time if anything changed in the components. In the real camara If any person is not inside the seen they are not come in the flim. Same as in the scene3d if we not add add any components in the scene 3d objects  it is not visible.

How Viewer3D Works ..?

Download the source code click here (compatible for Flashdevelop IDE)

Tags: ,

My first 3D flash animation

3D Animathion

Adobe support for native 3D only in cs4. There are lot of opensource flash 3d engines are there. I tried papervision3d and away3d. Both are quite well. There are lot more tutorials for both online for away3d tutorials  click here , for papervision3d download this book . I got the source code of away3d from the google code http://code.google.com/p/away3d/ and for papervison3d svn http://code.google.com/p/papervision3d/. I generate swc using the command. The red5 says about away3d.

D:\sdk\Away3D>compc -include-sources ./src -source-path ./src -target-player 10 -output Away3d.swc

Initially i got this error when compile away3d “Error: Type was not found or was not a compile-time constant: Vector. in away3d”

Then i added the -target-player 10 in command line is fix that error. I think away3d is better than papervision3d.Here is my first animation here

Iam using away3d here…

If not shown http://sites.google.com/site/arulraj1985/list-of-files/away3d.swf

package
{
	import away3d.cameras.Camera3D;
	import away3d.cameras.HoverCamera3D;
	import away3d.cameras.TargetCamera3D;
	import away3d.containers.ObjectContainer3D;
	import away3d.containers.Scene3D;
	import away3d.containers.View3D;
	import away3d.core.math.Number3D;
	import away3d.materials.BitmapMaterial;
	import away3d.materials.WireColorMaterial;
	import away3d.primitives.Cube;
	import away3d.core.render.Renderer;
	import away3d.primitives.Sphere;
	import away3d.primitives.WireSphere;
	import away3d.core.utils.Cast;
	import away3d.core.utils.CastError;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Arul
	 */
	public class FirstApplication extends Sprite
	{
		public var viewer:View3D;
		public var scene:Scene3D;
		public var camera:Camera3D;
		public var cube:Cube;
		public var sphere:Sphere;
		public var wiresphere:WireSphere;
		public var group:ObjectContainer3D;
		public var material:WireColorMaterial;
		public var bitmapMaterial:BitmapMaterial;

		[Embed(source = "assets/favicon.jpg")] private var favicon:Class;
		public var image:Bitmap = new favicon();

		[SWF(backgroundColor="#EEE8DA")]

		public function FirstApplication()
		{
			init3D();
		}

		public function init3D():void {
			stage.frameRate = 30;
			camera = new Camera3D({y:400,z:-1000});
			viewer = new View3D({camera:camera,x:250,y:100,z:100});
			scene = new Scene3D();
			cube = new Cube();
			sphere = new Sphere();
			wiresphere = new WireSphere();
			group = new ObjectContainer3D();
			material = new WireColorMaterial();
			bitmapMaterial = new BitmapMaterial(Cast.bitmap(image));

			material.color = 0xA6111D;

			sphere.x = 100;
			sphere.y = 50;
			sphere.z = 100;
			sphere.radius = 75;
			sphere.bothsides = true;
			sphere.material = material;
			group.addChild(sphere);

			wiresphere.x = 270;
			wiresphere.y = 150;
			wiresphere.z = 150;
			wiresphere.radius = 75;
			wiresphere.bothsides = true;
			wiresphere.material = material;
			group.addChild(wiresphere);

			cube.x = 250;
			cube.y = 250;
			cube.z = 400;
			cube.material = bitmapMaterial;
			group.addChild(cube);

			viewer.scene.addChild(group);
			viewer.render();

			addChild(viewer);

			addEventListener(Event.ENTER_FRAME, groupRotation);
			group.addEventListener(Event.ENTER_FRAME, sphereRotation);
			//addEventListener(MouseEvent.MOUSE_DOWN, lookThere);
		}

		public function groupRotation(e:Event):void {
			group.rotationX = group.x + 1;
			group.applyRotations();

			viewer.render();
		}

		public function sphereRotation(e:Event):void {
			sphere.rotationX = sphere.x + 1;
			sphere.applyRotations();

			wiresphere.rotationZ = wiresphere.z + 1;
			wiresphere.applyRotations();
			viewer.render();
		}

		public function lookThere(e:MouseEvent):void {
			var clickpoint:Point = new Point(e.stageX, e.stageY);
			var hypothines:Number = Point.distance(new Point(0, 0), clickpoint);
			var sine:Number = Math.asin(e.stageX/hypothines);
			var cos:Number = Math.acos(e.stageY/hypothines);
			camera.lookAt(new Number3D(e.stageX, e.stageY, hypothines));
			/**
			 * Horizontal angle
			 */
			camera.pan(cos);
			/**
			 * vertical angle
			 */
			camera.tilt(sine);
			viewer.render();
		}

	}

}

Tags: , ,