My favorites | Sign in
Project Logo
                
Changes to /trunk/src/com/as3dmod/modifiers/Pivot.as
r0 vs. r89   Edit
  Compare: vs.   Format:
Revision r89
Go to: 
Project members, sign in to write a code review
/trunk/src/com/as3dmod/modifiers/Pivot.as   r0 /trunk/src/com/as3dmod/modifiers/Pivot.as   r89
  1 package com.as3dmod.modifiers {
  2 import com.as3dmod.IModifier;
  3 import com.as3dmod.core.Modifier;
  4 import com.as3dmod.core.Vector3;
  5 import com.as3dmod.core.VertexProxy;
  6
  7 /**
  8 * <b>Pivot modifier.</b> Allows to move the pivot point of a 3D mesh.
  9 * <br>
  10 * <br>The pivot point will be moved by the amount specified by the pivot parameter.
  11 * <br>Common use case is to set the values of the pivot vector, add it to the modifier stack
  12 * and collapse the stack. This way the pivot point will be moved and the modifier discarded. The
  13 * same stack can be later resused for other modifiers.
  14 * <br>
  15 * <br>It is possible to animtate the pivot vector propeties also.
  16 *
  17 * @version 1.0
  18 * @author Bartek Drozdz
  19 */
  20 public class Pivot extends Modifier implements IModifier {
  21
  22 public var pivot:Vector3;
  23
  24 public function Pivot(x:Number=0, y:Number=0, z:Number=0) {
  25 this.pivot = new Vector3(x, y, z);
  26 }
  27
  28 /**
  29 * Sets the values of the pivot vector so that the pivot point of the mesh will be moved to it's center.
  30 */
  31 public function setMeshCenter():void {
  32 var vx:Number = -(mod.minX + mod.width / 2);
  33 var vy:Number = -(mod.minY + mod.height / 2);
  34 var vz:Number = -(mod.minZ + mod.depth / 2);
  35 pivot = new Vector3(vx, vy, vz);
  36 }
  37
  38 public function apply():void {
  39 var vs:Array = mod.getVertices();
  40 var vc:int = vs.length;
  41
  42 for (var i:int = 0; i < vc; i++) {
  43 var v:VertexProxy = vs[i] as VertexProxy;
  44 v.vector = v.vector.add(pivot);
  45 }
  46
  47 var npivot:Vector3 = pivot.clone();
  48 mod.updateMeshPosition(npivot.negate());
  49 }
  50 }
  51 }
Hosted by Google Code