My favorites | Sign in
Project Logo
                
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.as3dmod.modifiers {
import com.as3dmod.IModifier;
import com.as3dmod.core.Modifier;
import com.as3dmod.core.Vector3;
import com.as3dmod.core.VertexProxy;

/**
* <b>Pivot modifier.</b> Allows to move the pivot point of a 3D mesh.
* <br>
* <br>The pivot point will be moved by the amount specified by the pivot vector.
* <br>Common use case is to set the values of the pivot vector, add it to the modifier stack
* and collapse the stack. This way the pivot point will be moved and the modifier discarded. The
* same stack can be later resused for other modifiers.
* <br>
* <br>It is also possible to animtate the pivot vector propeties.
*
* @version 1.0
* @author Bartek Drozdz
*/
public class Pivot extends Modifier implements IModifier {

public var pivot:Vector3;

public function Pivot(x:Number=0, y:Number=0, z:Number=0) {
this.pivot = new Vector3(x, y, z);
}

/**
* Sets the values of the pivot vector so that the pivot point of the mesh will be moved to it's center.
*/
public function setMeshCenter():void {
var vx:Number = -(mod.minX + mod.width / 2);
var vy:Number = -(mod.minY + mod.height / 2);
var vz:Number = -(mod.minZ + mod.depth / 2);
pivot = new Vector3(vx, vy, vz);
}

public function apply():void {
var vs:Array = mod.getVertices();
var vc:int = vs.length;

for (var i:int = 0; i < vc; i++) {
var v:VertexProxy = vs[i] as VertexProxy;
v.vector = v.vector.add(pivot);
}

var npivot:Vector3 = pivot.clone();
mod.updateMeshPosition(npivot.negate());
}
}
}
Show details Hide details

Change log

r90 by drojdjou on Feb 07, 2009   Diff
This and the previous commit: new
modifiers: BitmapDisplacement, Pivot,
Break, Wheel. Perlin modifier rewritten.
Interal use classes Matrix3D and Vector3D
renamed to Matrix4 and Vector3. IMeshInfo
interface introduced.
Go to: 
Project members, sign in to write a code review

Older revisions

r89 by drojdjou on Feb 07, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 1643 bytes, 51 lines
Hosted by Google Code