Archive

Archive for April, 2009

Tutorial JigLibFlash – How to create basic physics 3d scene.

April 24th, 2009 10 comments


Introduction



Jiglibflash is a open source 3D physics engine. Official Web.
In this tutorial we will create a simple scene with some cubes and spheres. Those object will simulate physics.
The first thing we need is to create a basic 3d scene. JigLibFlash actually support Papervision3D, Away3D and Sandy3D. For this tutorial I will be using Papervision3d.


Lets begin



To create our scene we need a viewport, camera, render engine and scene. All this things are implemented in the BasicView class, for these reason our main class will extends from there. To get more information about it, read the next post by Andy Zupko BasicView – Making Life In Papervision a Little Easier

Our class at this moment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package
{
	import flash.events.Event;
	import org.papervision3d.view.BasicView;
 
	public class Main extends BasicView
	{
		public function Main()
		{
			super(0, 0, true);
			startRendering();
		}
 
		override protected function onRenderTick(event:Event = null):void
		{
			super.onRenderTick(event);
		}
	}
}

If you compile the code now, you won’t see anything, but internally we have all neccesary things to render 3d objects. With this base we can start with the physics. In JigLibFlash you will find the Papervision3DPhysics class, it is a plugin to handle easier the engine and also have some functions to create objects.

For our example we need to add a new instance of Papervision3DPhysics in the main class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package
{
	import flash.events.Event;
	import jiglib.plugin.papervision3d.Papervision3DPhysics;
	import org.papervision3d.view.BasicView;
 
	public class Main extends BasicView
	{
 
		private var _physics:Papervision3DPhysics;
 
		public function Main()
		{
			super(0, 0, true);
 
			initPhysics();
			startRendering();
		}
 
		private function initPhysics():void
		{
                         //need the scene instance (Scene3D) and the speed for the engine
			_physics = new Papervision3DPhysics(scene, 7);
		}
 
		override protected function onRenderTick(event:Event = null):void
		{
                        //update the engine in each frame
			_physics.step();
			super.onRenderTick(event);
		}
	}
}

Now we have the scene ready to add objects. Again Papervision3DPhysics is a very helpful class, because it has some functions to create basic objects like Grounds, Cubes or Spheres.

How To create objects


Create Ground


1
2
3
4
5
private function createGround():void
{
	var mat:WireframeMaterial = new WireframeMaterial(0xCCCCCC);
	var ground:RigidBody = _physics.createGround(mat, 1000, 0);
}

Create Cube


1
2
3
4
5
6
private function createBox():void
{
	var materials:MaterialsList = new MaterialsList();
	materials.addMaterial(new WireframeMaterial(0xFF4444), "all");
	var box:RigidBody = _physics.createCube(materials, 100, 100, 100, 3, 3, 3);
}


Create Sphere


1
2
3
4
private function createSphere():void
{
	var ball:RigidBody = _physics.createSphere(new WireframeMaterial(0xFF44FF), 50);
}

These are the functions that you can use with Papervision3DPhysics. Don’t forget that Papervision3DPhysics is a class to get things easier and faster.
I hope this tutorial results helpful for you and motivates you to learn more about JigLib. Any suggests will be great.

VIEW EXAMPLE
DOWNLOAD TUTORIAL FILES



Categories: JigLibFlash Tags:

Google Realese O3D – open-source web API for creating interactive 3D applications in the browser

April 24th, 2009 1 comment

O3D is an open-source web API for creating rich, interactive 3D applications in the browser. This API is shared at an early stage as part of a conversation with the broader developer community about establishing an open web standard for 3D graphics.

Google Code Page


Categories: etc Tags:

Tutorial actionscript 3 – How to read and save file in Adobe Air

April 22nd, 2009 1 comment

This is a very simple example of how to read and save files with Air.

DOWNLOAD EXAMPLE

Categories: Air, Flash Tags:

Tutorial Actionscript 3 – How to use a webcam on Flash

April 18th, 2009 5 comments

Use the webcam in flash is very easy. You need a Video instance and Camera instance.

1
2
3
4
5
6
7
8
9
10
//Create a video instance
video = new Video(640, 480);
//Get the camera reference.
camara = Camera.getCamera();
//setMode need 3 params, width, height and frame rate.
//Optianally you can set a boolean value at the end for the 	favorArea.
camara.setMode(640, 480, 30);
//put the camera in the video instance
video.attachCamera(camara);
addChild(video);

VIEW EXAMPLE
DOWNLOAD EXAMPLE


Categories: Actionscript 3, Flash Tags:

Facebook game – Football Soccer Challenge

April 9th, 2009 1 comment

footballsoccerchallenge
This game is a personal project. It is about trying to keep a soccer ball in the air by clicking on it. Have a bonus system that do more difficult the game. The game works on Facebook, and you can see your friends ranking or the world ranking.

You could check the game on:
http://apps.facebook.com/footballsoccer/

Your feedback, will be very helpful.



Categories: Flash, Games Tags:
Get Adobe Flash player