Skip to content

Commit

Permalink
Removed PathUtils, moved remaining non-path functionality in Vector3D…
Browse files Browse the repository at this point in the history
…Utils.as
  • Loading branch information
DerSchmale committed Jul 11, 2012
1 parent 14b9c44 commit ae4b904
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 98 deletions.
7 changes: 4 additions & 3 deletions src/away3d/animators/PathAnimator.as
@@ -1,14 +1,15 @@
package away3d.animators
{
import away3d.core.base.Object3D;
import away3d.core.math.Vector3DUtils;
import away3d.events.PathEvent;
import away3d.paths.IPath;
import away3d.paths.IPathSegment;
import away3d.paths.utils.PathUtils;

import flash.events.EventDispatcher;
import flash.geom.Vector3D;

[Deprecated]
public class PathAnimator extends EventDispatcher
{
private var _path:IPath;
Expand Down Expand Up @@ -148,7 +149,7 @@ package away3d.animators
_upAxis.x = 0;
_upAxis.y = 1;
_upAxis.z = 0;
_upAxis = PathUtils.rotatePoint(_upAxis, _rot);
_upAxis = Vector3DUtils.rotatePoint(_upAxis, _rot);

_target.lookAt(_basePosition, _upAxis);

Expand Down Expand Up @@ -433,7 +434,7 @@ package away3d.animators
_tmpOffset.x = _offset.x;
_tmpOffset.y = _offset.y;
_tmpOffset.z = _offset.z;
_tmpOffset = PathUtils.rotatePoint(_tmpOffset, _rot);
_tmpOffset = Vector3DUtils.rotatePoint(_tmpOffset, _rot);

_position.x += _tmpOffset.x;
_position.y += _tmpOffset.y;
Expand Down
70 changes: 69 additions & 1 deletion src/away3d/core/math/Vector3DUtils.as
Expand Up @@ -157,6 +157,74 @@ package away3d.core.math

return result;
}


public static function rotatePoint(aPoint : Vector3D, rotation : Vector3D) : Vector3D
{
if (rotation.x != 0 || rotation.y != 0 || rotation.z != 0) {

var x1 : Number;
var y1 : Number;

var rad : Number = MathConsts.DEGREES_TO_RADIANS;
var rotx : Number = rotation.x * rad;
var roty : Number = rotation.y * rad;
var rotz : Number = rotation.z * rad;

var sinx : Number = Math.sin(rotx);
var cosx : Number = Math.cos(rotx);
var siny : Number = Math.sin(roty);
var cosy : Number = Math.cos(roty);
var sinz : Number = Math.sin(rotz);
var cosz : Number = Math.cos(rotz);

var x : Number = aPoint.x;
var y : Number = aPoint.y;
var z : Number = aPoint.z;

y1 = y;
y = y1 * cosx + z * -sinx;
z = y1 * sinx + z * cosx;

x1 = x;
x = x1 * cosy + z * siny;
z = x1 * -siny + z * cosy;

x1 = x;
x = x1 * cosz + y * -sinz;
y = x1 * sinz + y * cosz;

aPoint.x = x;
aPoint.y = y;
aPoint.z = z;
}

return aPoint;
}

public static function subdivide(startVal : Vector3D, endVal : Vector3D, numSegments : int) : Vector.<Vector3D>
{
var points : Vector.<Vector3D> = new Vector.<Vector3D>();
var numPoints : int;
var stepx : Number = (endVal.x - startVal.x) / numSegments;
var stepy : Number = (endVal.y - startVal.y) / numSegments;
var stepz : Number = (endVal.z - startVal.z) / numSegments;

var step : int = 1;
var scalestep : Vector3D;

while (step < numSegments) {
scalestep = new Vector3D();
scalestep.x = startVal.x + (stepx * step);
scalestep.y = startVal.y + (stepy * step);
scalestep.z = startVal.z + (stepz * step);
points[numPoints++] = scalestep;

step++;
}

points[numPoints] = endVal;

return points;
}
}
}
3 changes: 1 addition & 2 deletions src/away3d/extrusions/PathDuplicator.as
Expand Up @@ -4,12 +4,11 @@ package away3d.extrusions {
import away3d.containers.Scene3D;
import away3d.entities.Mesh;
import away3d.paths.IPath;
import away3d.paths.SegmentedPathBase;
import away3d.paths.utils.PathUtils;

import flash.geom.Matrix3D;
import flash.geom.Vector3D;

[Deprecated]
public class PathDuplicator
{
private var _transform:Matrix3D;
Expand Down
9 changes: 5 additions & 4 deletions src/away3d/extrusions/PathExtrude.as
Expand Up @@ -7,19 +7,20 @@ package away3d.extrusions
import away3d.core.base.SubMesh;
import away3d.core.base.data.UV;
import away3d.core.base.data.Vertex;
import away3d.core.math.Vector3DUtils;
import away3d.entities.Mesh;
import away3d.loaders.parsers.data.DefaultBitmapData;
import away3d.materials.MaterialBase;
import away3d.materials.TextureMaterial;
import away3d.paths.IPath;
import away3d.paths.IPathSegment;
import away3d.paths.utils.PathUtils;
import away3d.textures.BitmapTexture;
import away3d.tools.helpers.MeshHelper;

import flash.geom.Matrix3D;
import flash.geom.Vector3D;

[Deprecated]
public class PathExtrude extends Mesh
{
private var _varr : Vector.<Vertex>;
Expand Down Expand Up @@ -1114,14 +1115,14 @@ package away3d.extrusions
lastrotate = (_rotations[i] == null) ? lastrotate : _rotations[i];
nextrotate = (_rotations[i + 1] == null) ? lastrotate : _rotations[i + 1];
rotation = Vector.<Vector3D>([lastrotate]);
rotation = rotation.concat(PathUtils.step(lastrotate, nextrotate, _subdivision));
rotation = rotation.concat(Vector3DUtils.subdivide(lastrotate, nextrotate, _subdivision));
}

if (rescale) lastscale = (!_scales[i]) ? lastscale : _scales[i];

if (_smoothScale && rescale) {
nextscale = (!_scales[i + 1]) ? (!_scales[i]) ? lastscale : _scales[i] : _scales[i + 1];
vScales = vScales.concat(PathUtils.step(lastscale, nextscale, _subdivision));
vScales = vScales.concat(Vector3DUtils.subdivide(lastscale, nextscale, _subdivision));
}

for (j = 0; j < vSegPts[i].length; ++j) {
Expand Down Expand Up @@ -1167,7 +1168,7 @@ package away3d.extrusions
tmppt.z = atmp[k].x * _trans.rawData[2] + atmp[k].y * _trans.rawData[6] + atmp[k].z * _trans.rawData[10] + _trans.rawData[14];

if (rotate)
tmppt = PathUtils.rotatePoint(tmppt, tweenrot);
tmppt = Vector3DUtils.rotatePoint(tmppt, tweenrot);

tmppt.x += vSegPts[i][j].x;
tmppt.y += vSegPts[i][j].y;
Expand Down
12 changes: 7 additions & 5 deletions src/away3d/paths/IPath.as
Expand Up @@ -4,33 +4,33 @@ package away3d.paths

public interface IPath
{
// TODO: pointOnPath(phase : Number) --> samplePoint
// TODO: getSegmentAt vs get segments


/**
* The number of <code>CubicPathSegment</code> instances in the path.
*/
[Deprecated]
function get numSegments():uint;


/**
* The <code>IPathSegment</code> instances which make up this path.
*/
[Deprecated]
function get segments():Vector.<IPathSegment>;

/**
* Returns the <code>CubicPathSegment</code> at the specified index
* @param index The index of the segment
* @return A <code>CubicPathSegment</code> instance
*/
[Deprecated]
function getSegmentAt(index:uint):IPathSegment;


/**
* Adds a <code>CubicPathSegment</code> to the end of the path
* @param segment
*/
[Deprecated]
function addSegment(segment:IPathSegment):void;


Expand All @@ -39,6 +39,7 @@ package away3d.paths
* @param index The index of the <code>CubicPathSegment</code> to be removed
* @param join Determines if the segments on either side of the removed segment should be adjusted so there is no gap.
*/
[Deprecated]
function removeSegment(index:uint, join:Boolean = false):void;


Expand All @@ -52,8 +53,9 @@ package away3d.paths
*
* @param numSegments The amount of segments to split the sampling in. The amount of points returned is numSegments + 1
*
* TODO: is this really even necessary? We should be able to simply call samplePoint(t) instead
* TODO: is this really even necessary? We should be able to simply call getPointOnCurve(t) instead
*/
[Deprecated]
function getPointsOnCurvePerSegment(numSegments : uint) : Vector.<Vector.<Vector3D>>;
}
}
82 changes: 0 additions & 82 deletions src/away3d/paths/utils/PathUtils.as

This file was deleted.

@@ -1,4 +1,4 @@
package away3d.tools.utils
package away3d.utils
{

import away3d.errors.CastError;
Expand Down

0 comments on commit ae4b904

Please sign in to comment.