AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

applyMatrix4

applyMatrix4()函数将当前的Vector3对象与给定的Matrix4对象相乘。

语法

vec.applyMatrix4( matrix );

参数

  • matrix:Matrix4类型的对象。

示例

var vec = new Vector3(1, 2, 3);
var mat = new Matrix4();

// 对vec应用变换矩阵
vec.applyMatrix4(mat);

实现

Vector3.prototype.applyMatrix4 = function ( m ) {

    var x = this.x, y = this.y, z = this.z;
    var e = m.elements;

    this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
    this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
    this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];

    return this;
};

说明

在三维空间中,Vector3对象表示一个三维向量,同时被用于表示三维的位置、大小或者方向。Matrix4对象用于表示三维坐标系中的变换矩阵,包括平移、旋转、缩放等变换。

applyMatrix4()函数将当前的三维向量与给定的变换矩阵相乘。具体地,假设当前的向量为vec,变换矩阵为mat,那么根据矩阵乘法的定义,vec.applyMatrix4(mat)将执行下列计算:

let x = vec.x, y = vec.y, z = vec.z;
let e = mat.elements;

vec.x = e[0]*x + e[4]*y + e[8]*z + e[12];
vec.y = e[1]*x + e[5]*y + e[9]*z + e[13];
vec.z = e[2]*x + e[6]*y + e[10]*z + e[14];

执行完毕后,当前的向量对象vec将保存乘积的结果。

参考