Skip to content

Commit

Permalink
Fixes for #156, #155 & #83. Corrections to pivot and gizmo controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg209 committed Jun 19, 2013
1 parent dba0d15 commit f032f70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package awaybuilder.view.scene.controls
{
import flash.geom.Matrix3D;
import away3d.containers.ObjectContainer3D;
import away3d.entities.Entity;
import away3d.lights.DirectionalLight;
import away3d.materials.ColorMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
Expand Down Expand Up @@ -74,11 +74,13 @@ package awaybuilder.view.scene.controls
content.scaleX = scale;
content.scaleY = scale;
content.scaleZ = scale;

//trace("this.position:"+this.position)
if (!active && currentMesh != null)
{
if (!(isLightGizmo && isLightGizmo.type == LightGizmo3D.DIRECTIONAL_LIGHT))
this.position = currentMesh.scenePosition;
if (!(isLightGizmo && isLightGizmo.type == LightGizmo3D.DIRECTIONAL_LIGHT)) {
// var pivot:Vector3D = currentMesh.transform.deltaTransformVector(currentMesh.pivotPoint);
// this.position = currentMesh.scenePosition.add(pivot);
}
}

ambientLight.direction = Scene3DManager.camera.forwardVector;
Expand All @@ -91,14 +93,15 @@ package awaybuilder.view.scene.controls
isLightGizmo = currentMesh.parent as LightGizmo3D;
isContainerGizmo = currentMesh.parent as ContainerGizmo3D;
isTextureProjectorGizmo = currentMesh.parent as TextureProjectorGizmo3D;

var pivot:Vector3D = currentMesh.transform.deltaTransformVector(currentMesh.pivotPoint);
this.position = currentMesh.scenePosition.add(pivot);
if (isLightGizmo)
{
this.position = isLightGizmo.sceneObject.scenePosition;
content.rotationX = content.rotationY = content.rotationZ = 0;
}
else if (isTextureProjectorGizmo)
{
this.position = isTextureProjectorGizmo.sceneObject.scenePosition;
if (type == TRANSLATE_GIZMO) {
content.rotationX = content.rotationY = content.rotationZ = 0;
} else {
Expand All @@ -109,7 +112,6 @@ package awaybuilder.view.scene.controls
}
else
{
this.position = sceneObject.scenePosition;
if (type == TRANSLATE_GIZMO) {
content.rotationX = content.rotationY = content.rotationZ = 0;
} else {
Expand All @@ -118,7 +120,6 @@ package awaybuilder.view.scene.controls
content.rotationZ = (isContainerGizmo) ? isContainerGizmo.parent.rotationZ : sceneObject.rotationZ;
}
}


this.visible = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ package awaybuilder.view.scene.controls

private var startValue:Vector3D;

private var actualMesh:ObjectContainer3D;
private var actualMesh : ObjectContainer3D;
private var startScenePosition : Vector3D;

public function TranslateGizmo3D()
{
Expand Down Expand Up @@ -172,15 +173,17 @@ package awaybuilder.view.scene.controls

protected function handleMouseDown(e:Event):void
{
currentAxis = e.target.name
currentAxis = e.target.name;

click.x = Scene3DManager.stage.mouseX;
click.y = Scene3DManager.stage.mouseY;

if (currentMesh.parent is ISceneRepresentation) actualMesh = (currentMesh.parent as ISceneRepresentation).sceneObject;
else actualMesh = currentMesh;

startValue = actualMesh.position;
startValue = new Vector3D(actualMesh.x, actualMesh.y, actualMesh.z);
var pivot:Vector3D = actualMesh.transform.deltaTransformVector(actualMesh.pivotPoint);
startScenePosition = actualMesh.scenePosition.add(pivot);

switch(currentAxis)
{
Expand Down Expand Up @@ -266,19 +269,15 @@ package awaybuilder.view.scene.controls

click.x = Scene3DManager.stage.mouseX;
click.y = Scene3DManager.stage.mouseY;

var pos:Vector3D = this.position.clone();
var rad:Number = 180/Math.PI;
var objectEulers:Vector3D = Vector3DUtils.matrix2euler(actualMesh.parent.transform);
objectEulers.x *= -rad;
objectEulers.y *= -rad;
objectEulers.z *= -rad;
pos = Vector3DUtils.rotatePoint(pos, objectEulers);
actualMesh.position = pos;

var pos:Vector3D = this.position.subtract(startScenePosition).add(startValue);
actualMesh.x = pos.x;
actualMesh.y = pos.y;
actualMesh.z = pos.z;

Scene3DManager.updateDefaultCameraFarPlane();

dispatchEvent(new Gizmo3DEvent(Gizmo3DEvent.MOVE, GizmoMode.TRANSLATE, actualMesh, actualMesh.position, startValue, actualMesh.position));
dispatchEvent(new Gizmo3DEvent(Gizmo3DEvent.MOVE, GizmoMode.TRANSLATE, actualMesh, pos, startValue, pos));
}

protected function handleMouseUp(event:Event):void
Expand All @@ -297,7 +296,8 @@ package awaybuilder.view.scene.controls
zCone.material = zAxisMaterial;
zCylinder.material = zAxisMaterial;

dispatchEvent(new Gizmo3DEvent(Gizmo3DEvent.RELEASE, GizmoMode.TRANSLATE, actualMesh, actualMesh.position, startValue, actualMesh.position.clone()));
var pos:Vector3D = this.position.subtract(actualMesh.pivotPoint).subtract(actualMesh.parent.scenePosition);
dispatchEvent(new Gizmo3DEvent(Gizmo3DEvent.RELEASE, GizmoMode.TRANSLATE, actualMesh, pos, startValue, pos));
}

}
Expand Down

0 comments on commit f032f70

Please sign in to comment.