My favorites
|
Sign in
as3dmod
cross-engine modifier library for Flash 3d
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r102
Source path:
svn
/
trunk
/
src
/
com
/
as3dmod
/
modifiers
/
Wheel.as
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.as3dmod.modifiers {
import com.as3dmod.IModifier;
import com.as3dmod.core.Matrix4;
import com.as3dmod.core.MeshProxy;
import com.as3dmod.core.Modifier;
import com.as3dmod.core.Vector3;
import com.as3dmod.core.VertexProxy;
/**
* <b>Wheel modifier.</b> Use it with vehicle models for wheels.
* <br>
* <p>The usual problem with a 3d wheel in a vahicle is that if it is
* supposed to turn (steer) and roll in the same time. So, this code:
* <br>
* <br><code><pre>
* wheel.rotationY = 10; // Steer 10deg to the left
* wheel.rotationZ +- 5; // Roll with a speed of 5
* </pre></code><br>
* This will make the wheel roll incorectly.</p>
*
* <p>A usual way to solve this problem is to put the wheel in another DisplayObject3D/Mesh,
* turn the parent and roll the child, like that:
* <br><code><pre>
* steer.rotationY = 10; // Steer 10deg to the left
* steer.wheel.rotationZ +- 5; // Roll with a speed of 5
* </pre></code><br>
* That will make the wheel behave correctly. But it can be uncomfortanble to apply, especially
* to imported complex Collada models.</p>
*
* <p>The Wheel modifier elegantly solves this problem by doind the proper math in order to steer and roll
* a single mesh at the same time. The only thing you need to do is to specify a steer vector and
* roll vector - usually it will be 2 of the cardinal axes. The default value is:
* <ul>
* <li>steer - along the Y axis / new Vector3(0, 1, 0)</li>
* <li>roll - along the Z axis / new Vector3(0, 0, 1)</li>
* </ul></p>
*
* <p>It should work with most car models imported from 3D editors as this is the natural position of a wheel.<br>
* <i>Please note, that Papervision primitive cylinder, which may also be used as wheel, will require different axes
* (Y for roll and Z or X for steer).</i></p>
*
* @version 1.0
* @author Bartek Drozdz
*/
public class Wheel extends Modifier implements IModifier {
public var speed:Number;
public var turn:Number;
private var roll:Number;
private var _radius:Number;
public var steerVector:Vector3 = new Vector3(0, 1, 0);
public var rollVector:Vector3 = new Vector3(0, 0, 1);
public function Wheel() {
speed = 0;
turn = 0;
roll = 0;
}
override public function setModifiable(mod:MeshProxy):void {
super.setModifiable(mod);
_radius = mod.width / 2;
}
public function apply():void {
roll += speed;
var vs:Array = mod.getVertices();
var vc:int = vs.length;
var ms:Matrix4;
if(turn != 0) {
var mt:Matrix4 = Matrix4.rotationMatrix(steerVector.x, steerVector.y, steerVector.z, turn);
var rv:Vector3 = rollVector.clone();
Matrix4.multiplyVector(mt, rv);
ms = Matrix4.rotationMatrix(rv.x, rv.y, rv.z, roll);
} else {
ms = Matrix4.rotationMatrix(rollVector.x, rollVector.y, rollVector.z, roll);
}
for (var i:int = 0;i < vc; i++) {
var v:VertexProxy = vs[i] as VertexProxy;
var c:Vector3 = v.vector.clone();
if(turn != 0) Matrix4.multiplyVector(mt, c);
Matrix4.multiplyVector(ms, c);
v.x = c.x;
v.y = c.y;
v.z = c.z;
}
}
public function get step():Number {
return _radius * speed / Math.PI;
}
public function get perimeter():Number {
return _radius * 2 * Math.PI;
}
public function get radius():Number {
return _radius;
}
}
}
Show details
Hide details
Change log
r89
by drojdjou on Feb 07, 2009
Diff
[No log message]
Go to:
...nk/bin/as3dmod-alternativa3d.swf
/trunk/bin/as3dmod-away3d.swf
/trunk/bin/as3dmod-pv3d.swf
/trunk/bin/as3dmod-sandy3d.swf
/trunk/build.properties
/trunk/build.xml
/trunk/demo/Alternativa3dDemo.as
/trunk/demo/Away3dDemo.as
/trunk/demo/DemoBase.as
/trunk/demo/Pv3dDemo.as
/trunk/demo/Sandy3dDemo.as
...om/as3dmod/demo/skew/SkewDemo.as
...dmod/tutorial/AS3DmodTutorial.as
/trunk/src/com/as3dmod/IMeshInfo.as
...src/com/as3dmod/ModifierStack.as
...src/com/as3dmod/core/Matrix3D.as
.../src/com/as3dmod/core/Matrix4.as
...rc/com/as3dmod/core/MeshProxy.as
.../src/com/as3dmod/core/Vector3.as
...src/com/as3dmod/core/Vector3D.as
.../com/as3dmod/core/VertexProxy.as
...rc/com/as3dmod/modifiers/Bend.as
.../modifiers/BitmapDisplacement.as
...c/com/as3dmod/modifiers/Bloat.as
...c/com/as3dmod/modifiers/Break.as
.../com/as3dmod/modifiers/Perlin.as
...c/com/as3dmod/modifiers/Pivot.as
...rc/com/as3dmod/modifiers/Skew.as
...c/com/as3dmod/modifiers/Taper.as
...c/com/as3dmod/modifiers/Twist.as
...c/com/as3dmod/modifiers/Wheel.as
...ternativa3d/Alternativa3dMesh.as
...mod/plugins/away3d/Away3dMesh.as
...as3dmod/plugins/pv3d/Pv3dMesh.as
...d/plugins/sandy3d/Sandy3dMesh.as
...m/as3dmod/util/LinearFunction.as
/trunk/src/com/as3dmod/util/Log.as
...nk/src/com/as3dmod/util/Phase.as
...nk/src/com/as3dmod/util/Range.as
...nk/src/com/as3dmod/util/Value.as
/trunk/src/com/as3dmod/util/bitmap
...3dmod/util/bitmap/PerlinNoise.as
/trunk/src/com/carlcalderon
/trunk/src/nl
/trunk/src/nl/demonsters
/trunk/src/nl/demonsters/debugger
...ters/debugger/MonsterDebugger.as
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3493 bytes, 106 lines
View raw file
Hosted by