Hacking Papervision3D (vidoes 1 – 7)

Intro: Hacking Papervision3D

In this seven part video series you learn to hack PV3D using the powerful error checking in Flash Builder. You’ll learn to remove the Number3D and Number2D classes form PV3D and use the native classes in the Flash Player.

Hacking Videos Removing Number3D

Chapter 2: Hacking Papervision3D Part 1

Chapter 2: Hacking Papervision3D Part 2

Chapter 2: Hacking Papervision3D Part 3

Chapter 2: Hacking Papervision3D Part 4

Chapter 2: Hacking Papervision3D Part 5

Chapter 2: Hacking Papervision3D Part 6

Hacking Videos Remove Number3D

Chapter 2: Hacking Papervision3D Part 7

In the class notes, you’ll find many of the Number3D math methods that are explained in the video. Understanding how these functions work will be essential for the rest of the book.

Click the link below to read the class notes:

Hacking Papervision3D

Review videos (Away3d, will do for PV4D)

http://www.youtube.com/watch?v=Fmn4jECx24I

http://www.youtube.com/watch?v=U8WW19k7jfU

A. Create a Flash Builder Project
Transfer in appropriate classes

B. Transfer package from Chapter 2 into
flash builder and follow procedure in
previous video on Away3d

C. Once program is running remove
Number3D from
org/papervison3d/core/math
and fix bugs

D. Remove Number2D from
org/papervison3d/core/math
and fix bugs

E. Discuss mathematical replacements

Replace Number3D with Vector3D:

The Vector3D class represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z. As in a two-dimensional space, the x property represents the horizontal axis and the y property represents the vertical axis. In three-dimensional space, the z property represents depth. The value of the x property increases as the object moves to the right. The value of the y property increases as the object moves down. The z property increases as the object moves farther from the point of view. Using perspective projection and scaling, the object is seen to be bigger when near and smaller when farther away from the screen. As in a right-handed three-dimensional coordinate system, the positive z-axis points away from the viewer and the value of the z property increases as the object moves away from the viewer’s eye. The origin point (0,0,0) of the global space is the upper-left corner of the stage.

The Vector3D class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint; or a floating-point component of an RGB (Red, Green, Blue) color model.
Quaternion notation introduces a fourth element, the w property, which provides additional orientation information. For example, the w property can define an angle of rotation of a Vector3D object. The combination of the angle of rotation and the coordinates x, y, and z can determine the display object’s orientation. Here is a representation of Vector3D elements in matrix notation:
Randian to Degrees … Human readable to math readable!
static public var toDEGREES :Number = 180/Math.PI;

static public var toRADIANS :Number = Math.PI/180;

Replace Vector3D.ZERO with new Vector3D();

private var _position :Number3D = Number3D.ZERO;

static public function get ZERO():Number3D

{

return new Number3D( 0, 0, 0 );

}

static private var n3Di : Vector3D = new Vector3D();

static private var n3Dj : Vector3D = new Vector3D();

static private var n3Dk : Vector3D = new Vector3D();

Clone

public function clone():Number3D

{

return new Number3D( this.x, this.y, this.z );

}

CopyTo and CopyFrom

public function copyTo(n:Number3D):void

{

n.x = x;

n.y = y;

n.z = z;

}

/**

* Copies the values of this Number3d to the passed Number3d.

*

*/

public function copyFrom(n:Number3D):void

{

x = n.x;

y = n.y;

z = n.z;

}

Increment and Decrement

/**

* Adds the vector passed to this vector. The same as the += operator.

*/

public function plusEq(v:Number3D):void

{

x+=v.x;

y+=v.y;

z+=v.z;

}

/**

* Subtracts the vector passed to this vector. The same as the -= operator.

*/

public function minusEq(v:Number3D):void

{

x -= v.x;

y -= v.y;

z -= v.z;

}

Modulo (length)

public function get modulo() : Number

{

return Math.sqrt( this.x*this.x + this.y*this.y + this.z*this.z );

}

Normalize (unit vector)

public function normalize():void

{

var mod:Number = Math.sqrt( this.x*this.x + this.y*this.y + this.z*this.z );

if( mod != 0 && mod != 1)

{

mod = 1 / mod; // mults are cheaper then divs

this.x *= mod;

this.y *= mod;

this.z *= mod;

}

}

Cross Product a(cros)b = |a||b|sin(theta), give perpendicular vector

public static function cross( v:Number3D, w:Number3D, targetN:Number3D = null ):Number3D

{

if(!targetN) targetN = ZERO;

targetN.reset((w.y * v.z) – (w.z * v.y), (w.z * v.x) – (w.x * v.z), (w.x * v.y) – (w.y * v.x));

return targetN;

}

Dot Product a(dot)b = |a||b|cos(theta), gives angle between vectors

public static function dot( v:Number3D, w:Number3D ):Number

{

return ( v.x * w.x + v.y * w.y + w.z * v.z );

}

Add and Subtract

/**

* Add

*/

public static function add( v:Number3D, w:Number3D ):Number3D

{

return new Number3D

(

v.x + w.x,

v.y + w.y,

v.z + w.z

);

}

/**

* Subtract.

*/

public static function sub( v:Number3D, w:Number3D ):Number3D

{

return new Number3D

(

v.x – w.x,

v.y – w.y,

v.z – w.z

);

}

Rotation x, y, z

public function rotateX(angle:Number) :void

{

if(Papervision3D.useDEGREES) angle*= toRADIANS;

var cosRY:Number = Math.cos(angle);

var sinRY:Number = Math.sin(angle);

temp.copyFrom(this);

this.y = (temp.y*cosRY)-(temp.z*sinRY);

this.z = (temp.y*sinRY)+(temp.z*cosRY);

}

public function rotateY(angle:Number) :void

{

if(Papervision3D.useDEGREES) angle*= toRADIANS;

var cosRY:Number = Math.cos(angle);

var sinRY:Number = Math.sin(angle);

temp.copyFrom(this);

this.x= (temp.x*cosRY)+(temp.z*sinRY);

this.z= (temp.x*-sinRY)+(temp.z*cosRY);

}

public function rotateZ(angle:Number) :void

{

if(Papervision3D.useDEGREES) angle*= toRADIANS;

var cosRY:Number = Math.cos(angle);

var sinRY:Number = Math.sin(angle);

temp.copyFrom(this);

//this.x= temp.x;

this.x= (temp.x*cosRY)-(temp.y*sinRY);

this.y= (temp.x*sinRY)+(temp.y*cosRY);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: