diff --git a/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt b/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt
new file mode 100644
index 00000000..25ac526e
Binary files /dev/null and b/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt differ
diff --git a/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf b/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf
new file mode 100644
index 00000000..8ee3faea
Binary files /dev/null and b/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf differ
diff --git a/Code/Dokumentation/Other/angular momentum to angular velocity.odt b/Code/Dokumentation/Other/angular momentum to angular velocity.odt
new file mode 100644
index 00000000..9cb22720
Binary files /dev/null and b/Code/Dokumentation/Other/angular momentum to angular velocity.odt differ
diff --git a/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf b/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf
new file mode 100644
index 00000000..820bf412
Binary files /dev/null and b/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf differ
diff --git a/Code/Dokumentation/Physics_Sprint3.uxf b/Code/Dokumentation/Physics_Sprint3.uxf
new file mode 100644
index 00000000..6b74de3e
--- /dev/null
+++ b/Code/Dokumentation/Physics_Sprint3.uxf
@@ -0,0 +1,1059 @@
+
+
+ 7
+
+
+ com.umlet.element.Class
+
+ 357
+ 518
+ 252
+ 406
+
+ Formula : <<namespace>>
+<<extern>>
+--
+LinearMomentum( .. ) : Vector
+LinearVelocity( .. ) : Vector
+AngularMomentum( .. ) : Vector
+AngularVelocity( .. ) : Vector
+TangientialLinearMomentum( .. ) : Vector
+LinearKineticEnergy( .. ) : Float
+AngularKineticEnergy( .. ) : Float
+TangientialImpulseForce( .. ) : Vector
+AngularImpulseAcceleration( .. ) : Vector
+TangientialImpulseAcceleration( .. ) : Vector
+TangientialLinearVelocity( .. ) : Vector
+LinearImpulseAcceleration( .. ) : Vector
+ImpulseForce( .. ) : Vector
+ImpulseTorque( .. ) : Vector
+Forcefield( .. ) : Float
+
+
+
+ com.umlet.element.Class
+
+ 364
+ 728
+ 238
+ 189
+
+ MomentOfInertia : <<namespace>>
+<<extern>>
+--
+CalculateSphere( .. ) : Float
+Sphere( .. ) : Matrix
+CalculateHollowSphere( .. ) : Float
+HollowSphere( .. ) : Matrix
+CalculateCuboidX( .. ) : Float
+CalculateCuboidY( .. ) : Float
+CalculateCuboidZ( .. ) : Float
+Cuboid( .. ) : Matrix
+CalculateRodCenter( .. ) : Float
+RodCenter( .. ) : Matrix
+CalculateCylinderXY( .. ) : Float
+CalculateCylinderZ( .. ) : Float
+Cylinder( .. ) : Matrix
+
+
+
+ com.umlet.element.Class
+
+ 616
+ 518
+ 210
+ 35
+
+ RigidBody : struct
+--
+Update_LeapFrog( deltatime : Float ) : void
+
+
+
+ com.umlet.element.Class
+
+ 616
+ 581
+ 210
+ 203
+
+ MomentOfInertia : struct
+--
+CalculateAngularVelocity( .. ) : Vector
+CalculateAngularMomentum( .. ) : Vector
+--
+<<static>> CalculateSphere( .. ) : Float
+<<static>> Sphere( .. ) : MomentOfInertia
+<<static>> CalculateHollowSphere( .. ) : Float
+<<static>> HollowSphere( .. ) : MomentOfInertia
+<<static>> CalculateCuboidX( .. ) : Float
+<<static>> CalculateCuboidY( .. ) : Float
+<<static>> CalculateCuboidZ( .. ) : Float
+<<static>> Cuboid( .. ) : MomentOfInertia
+<<static>> CalculateRodCenter( .. ) : Float
+<<static>> RodCenter( .. ) : MomentOfInertia
+<<static>> CalculateCylinderXY( .. ) : Float
+<<static>> CalculateCylinderZ( .. ) : Float
+<<static>> Cylinder( .. ) : MomentOfInertia
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 847
+ 98
+ 21
+
+ FluidDrag : struct
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 875
+ 98
+ 21
+
+ Particle : struct
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 903
+ 98
+ 21
+
+ Spring : struct
+
+
+
+ com.umlet.element.Relation
+
+ 644
+ 532
+ 132
+ 62
+
+ lt=<-
+<<uses>>
+ 119;49;119;35;21;35;21;21
+
+
+ com.umlet.element.Class
+
+ 350
+ 483
+ 483
+ 448
+
+ Physics3D : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 560
+ 420
+ 161
+ 49
+
+ Constant : <<namespace>>
+<<extern>>
+--
+gravity_constant : const Float
+
+
+
+
+ com.umlet.element.Class
+
+ 224
+ 385
+ 329
+ 84
+
+ Default : <<namespace>>
+<<intern>>
+--
+EventAction_Destruction : <<PhysicsAPI::EventAction_Destruction>>
+EventAction_Collision : <<ICustomBody::EventAction_Collision>>
+EventAction_CollisionResponse : <<ICustomBody::EventAction_Collision>>
+EventAction_Move : <<ICustomBody::EventAction_Collision>>
+
+
+
+
+ com.umlet.element.Class
+
+ 245
+ 63
+ 224
+ 196
+
+ API : <<interface>>
+--
+{innerclass
+ EventAction_Destruction : <<FunctionPointer>>
+innerclass}
+
+Init( .. ) : void
+SetFrameTimeLength( .. ) : void
+SetGravityConstant( .. ) : void
+SetSubscription( .. ) : void
+Update() : void
+IsInLimbo( .. ) : bool
+MoveToLimbo( .. ) : void
+ReleaseFromLimbo( .. ) : void
+AddObject( .. ) : void
+ExtractObject( .. ) : ICustomBody*
+DestroyObject( .. ) : void
+AddGravity( .. ) : void
+RemoveGravity( .. ) : void
+ApplyEffect( .. ) : void
+CreateRigidBody( .. ) : ICustomBody*
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 280
+ 133
+ 28
+
+ API_Impl : <<class>>
+--
+<<uses>> OctTree : class
+
+
+
+ com.umlet.element.Class
+
+ 476
+ 63
+ 280
+ 287
+
+ ICustomBody : <<interface>>
+
+{innerclass
+ SubscriptMessage : Enum
+innerclass}
+
+{innerclass
+ EventAction_Collision : <<Subscription : SubscriptMessage>>
+innerclass}
+
+{innerclass
+ EventAction_CollisionResponse : <<Subscription : void>>
+innerclass}
+
+{innerclass
+ EventAction_Move : <<Subscription : void>>
+innerclass}
+
+Clone() : ICustomBody*
+CallSubscription_Collision( .. ) : SubscriptMessage
+CallSubscription_CollisionResponse( .. ) : void
+CallSubscription_Move() : void
+GetState( .. ) : State
+SetState( .. ) : void
+IsAffectedByGravity() : bool
+Intersects( .. ) : bool
+GetBoundingSphere : Sphere
+GetNormalAt( .. ) : Vector
+GetGravityNormal( .. ) : Vector
+GetCustomTag() : void*
+Update( .. ) : UpdateState
+Predict( .. ) : void
+SetScene( .. ) : void
+SetSubscription( .. ) : void
+SetGravity( .. ) : void
+SetGravityNormal( .. ) : void
+SetCustomTag( .. ) : void
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 315
+ 175
+ 28
+
+ SimpleRigidBody : <<class>>
+--
+<<uses>> Physics3D::RigidBody : struct
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 350
+ 175
+ 28
+
+ SphericalRigidBody : <<class>>
+--
+<<uses>> Physics3D::RigidBody : struct
+
+
+
+ com.umlet.element.Class
+
+ 21
+ 273
+ 196
+ 196
+
+ Formula : <<namespace>>
+<<intern>>
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 308
+ 175
+ 84
+
+ MomentOfInertia : <<namespace>>
+<<intern>>
+--
+CreateSphereMatrix( .. ) : Matrix
+CreateHollowSphereMatrix( .. ) : Matrix
+CreateCuboidMatrix( .. ) : Matrix
+CreateCylinderMatrix( .. ) : Matrix
+CreateRodMatrix( .. ) : Matrix
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 406
+ 175
+ 56
+
+ CollisionResponse : <<namespace>>
+<<intern>>
+--
+Bounce( .. ) : Float
+Friction( .. ) : Vector
+
+
+
+ com.umlet.element.Relation
+
+ 308
+ 238
+ 34
+ 55
+
+ lt=<<.
+ 21;21;21;42
+
+
+ com.umlet.element.Relation
+
+ 427
+ 308
+ 97
+ 76
+
+ lt=<<.
+ 84;42;84;63;35;63;35;21;21;21
+
+
+ com.umlet.element.Class
+
+ 560
+ 371
+ 203
+ 42
+
+ OctTree : <<class>>
+--
+<<uses>> Collision3D::Sphere : struct
+<<uses>> Collision3D::BoxAxisAligned : struct
+
+
+
+ com.umlet.element.Relation
+
+ 518
+ 329
+ 100
+ 55
+
+ lt=<-
+ <<uses>>
+ 56;21;56;42
+
+
+ com.umlet.element.Relation
+
+ 427
+ 329
+ 97
+ 55
+
+ lt=.
+ 84;21;84;42;21;42
+
+
+ com.umlet.element.Class
+
+ 21
+ 63
+ 182
+ 196
+
+ Struct : <<namespace>>
+<<extern>>
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 203
+ 168
+ 14
+
+ SimpleBodyDescription : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 231
+ 168
+ 14
+
+ SimpleSphericalDescription : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 175
+ 168
+ 14
+
+ CustomBodyState : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 91
+ 168
+ 63
+
+ Gravity : struct
+{innerclass
+ GravityWell
+innerclass}
+{innerclass
+ GravityDirected
+innerclass}
+{innerclass
+ GravityDirectedField
+innerclass}
+
+
+
+ com.umlet.element.Relation
+
+ 182
+ 105
+ 104
+ 195
+
+ lt=<-
+ <<uses>>
+ 21;21;56;21;56;168;91;168;91;182
+
+
+ com.umlet.element.Relation
+
+ 182
+ 161
+ 104
+ 139
+
+ lt=<-
+ 21;21;56;21;56;112;91;112;91;126
+
+
+ com.umlet.element.Relation
+
+ 385
+ 252
+ 104
+ 49
+
+ lt=<-
+<<uses>>
+ 91;35;21;35
+
+
+ com.umlet.element.Relation
+
+ 182
+ 189
+ 104
+ 181
+
+ lt=<-
+ 21;21;42;21;42;168;91;168
+
+
+ com.umlet.element.Relation
+
+ 175
+ 217
+ 111
+ 153
+
+ lt=<-
+ <<uses>>
+ 28;21;49;21;49;140;98;140
+
+
+ com.umlet.element.Relation
+
+ 231
+ 301
+ 55
+ 69
+
+ lt=-
+ 42;21;42;21;21;21;21;56
+
+
+ com.umlet.element.Class
+
+ 14
+ 35
+ 756
+ 441
+
+ Physics : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 0
+ 0
+ 847
+ 945
+
+ Oyster : <<namespace>>
+<<extern>>
+bg=orange
+--
+
+
+
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 546
+ 126
+ 21
+
+ Box : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 518
+ 126
+ 21
+
+ ICollideAble : <<interface>>
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 574
+ 126
+ 21
+
+ AxisAlignedBox : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 602
+ 126
+ 21
+
+ Point : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 630
+ 126
+ 21
+
+ Sphere : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 770
+ 126
+ 21
+
+ Frustrum : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 658
+ 126
+ 21
+
+ Ray : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 700
+ 126
+ 21
+
+ Line : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 728
+ 126
+ 21
+
+ Plane : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 798
+ 126
+ 21
+
+ Universe : class
+
+
+
+ com.umlet.element.Class
+
+ 21
+ 518
+ 126
+ 70
+
+ Utility : <<namespace>>
+<<extern>>
+--
+Compare( .. ) : void
+Intersect( .. ) : bool
+Contain( .. ) : bool
+
+
+
+ com.umlet.element.Relation
+
+ 280
+ 504
+ 55
+ 321
+
+ lt=<<.
+ 21;21;42;21;42;308;21;308
+
+
+ com.umlet.element.Relation
+
+ 280
+ 721
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 693
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 651
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 763
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 623
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 595
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 567
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 539
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 196
+ 658
+ 83
+ 55
+
+ lt=<-
+<<uses>>
+ 21;21;21;35;70;35;70;42
+
+
+ com.umlet.element.Relation
+
+ 35
+ 567
+ 153
+ 84
+
+ lt=<-
+ <<uses>>
+ 49;21;49;70;140;70
+
+
+ com.umlet.element.Relation
+
+ 133
+ 504
+ 55
+ 286
+
+ lt=-
+ 42;21;21;21;21;273;42;273
+
+
+ com.umlet.element.Relation
+
+ 196
+ 728
+ 83
+ 55
+
+ lt=<-
+<<uses>>
+ 21;21;21;35;70;35;70;42
+
+
+ com.umlet.element.Relation
+
+ 133
+ 714
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 644
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 588
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 560
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 532
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Class
+
+ 14
+ 483
+ 329
+ 343
+
+ Collision3D : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+
+ com.umlet.element.Class
+
+ 938
+ 77
+ 98
+ 28
+
+ OysterPhysics3D
+<<lib>>
+bg=green
+
+
+
+ com.umlet.element.Class
+
+ 896
+ 175
+ 42
+ 21
+
+ Misc
+bg=green
+
+
+
+ com.umlet.element.Class
+
+ 952
+ 175
+ 70
+ 21
+
+ OysterMath
+bg=green
+
+
+
+ com.umlet.element.Relation
+
+ 896
+ 98
+ 34
+ 90
+
+ lt=())
+ 21;77;21;21
+
+
+ com.umlet.element.Relation
+
+ 966
+ 98
+ 28
+ 84
+
+ lt=())
+ 21;77;21;21
+
+
+ com.umlet.element.Class
+
+ 896
+ 28
+ 161
+ 28
+
+ GamePhysics
+<<dll>>
+bg=green
+
+
+
+ com.umlet.element.Relation
+
+ 896
+ 35
+ 48
+ 97
+
+ lt=-
+ 35;84;21;84;21;21
+
+
+ com.umlet.element.Class
+
+ 889
+ 0
+ 175
+ 133
+
+ Project Dependencies
+--
+bg=blue
+
+
+
+ com.umlet.element.Relation
+
+ 910
+ 84
+ 90
+ 48
+
+ lt=-
+ 21;35;77;35;77;21
+
+
+ com.umlet.element.Relation
+
+ 1036
+ 21
+ 105
+ 28
+
+ lt=<()
+r1=provide
+ 98;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 1015
+ 70
+ 126
+ 28
+
+ lt=<()
+r1=provide
+ 119;21;21;21
+
+
+
diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp
index 3faff29e..b4395516 100644
--- a/Code/GamePhysics/Implementation/Octree.cpp
+++ b/Code/GamePhysics/Implementation/Octree.cpp
@@ -128,13 +128,13 @@ void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction )
}
}
-void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction)
+void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, void* args, VisitorActionCollideable hitAction)
{
for(unsigned int i = 0; ileafData.size(); i++)
{
if(collideable.Intersects(this->leafData[i].container))
{
- hitAction( this->GetCustomBody(i) );
+ hitAction( this->GetCustomBody(i), args );
}
}
}
diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h
index 7b350795..50b9569a 100644
--- a/Code/GamePhysics/Implementation/Octree.h
+++ b/Code/GamePhysics/Implementation/Octree.h
@@ -18,7 +18,7 @@ namespace Oyster
static const unsigned int invalid_ref;
typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int);
- typedef void(*VisitorActionCollideable)(ICustomBody*);
+ typedef void(*VisitorActionCollideable)(ICustomBody*, void*);
struct Data
{
@@ -53,7 +53,7 @@ namespace Oyster
std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList);
std::vector& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList);
void Visit(ICustomBody* customBodyRef, VisitorAction hitAction );
- void Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction );
+ void Visit(const Oyster::Collision3D::ICollideable& collideable, void* args, VisitorActionCollideable hitAction );
ICustomBody* GetCustomBody(const unsigned int tempRef);
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
index ead748e4..14c4d9e4 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
@@ -31,16 +31,16 @@ namespace
ICustomBody::State protoState; proto->GetState( protoState );
ICustomBody::State deuterState; deuter->GetState( deuterState );
- Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact ),
- deuterG = deuterState.GetLinearMomentum( worldPointOfContact );
+ Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
+ deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
// calc from perspective of deuter
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
- Float protoG_Magnitude = protoG.Dot( normal ),
+ Float protoG_Magnitude = protoG.Dot( normal ),
deuterG_Magnitude = deuterG.Dot( normal );
// if they are not relatively moving towards eachother, there is no collision
- Float deltaPos = normal.Dot( deuterState.GetCenterPosition() - protoState.GetCenterPosition() );
+ Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) );
if( deltaPos < 0.0f )
{
if( protoG_Magnitude >= deuterG_Magnitude )
@@ -95,12 +95,15 @@ namespace
// }
+ Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
// protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis );
- protoState.ApplyImpulse( bounce, worldPointOfContact, normal );
+ protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
proto->SetState( protoState );
- proto->CallSubscription_CollisionResponse( deuter, protoState.GetLinearMomentum().GetMagnitude()/(protoState.GetMass() + protoState.GetLinearMomentum().GetMagnitude()));
+ Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() );
+
+ proto->CallSubscription_CollisionResponse( deuter, kineticEnergyPBefore - kineticEnergyPAFter );
}
break;
@@ -176,7 +179,7 @@ void API_Impl::Update()
{
case Gravity::GravityType_Well:
{
- Float4 d = Float4( this->gravity[i].well.position, 1.0f ) - state.GetCenterPosition();
+ Float4 d = Float4( this->gravity[i].well.position, 1.0f ) - Float4( state.GetCenterPosition(), 1.0f );
Float rSquared = d.Dot( d );
if( rSquared != 0.0 )
{
@@ -198,11 +201,9 @@ void API_Impl::Update()
if( gravityImpulse != Float4::null )
{
- state.ApplyLinearImpulse( gravityImpulse );
- //state.SetGravityNormal( gravityImpulse.GetNormalized());
- //(*proto)->SetGravityNormal( gravityImpulse.GetNormalized().xyz );
- (*proto)->SetState( state );
+ state.ApplyLinearImpulse( gravityImpulse.xyz );
(*proto)->SetGravityNormal( gravityImpulse.GetNormalized().xyz );
+ (*proto)->SetState( state );
}
// Step 2: Apply Collision Response
@@ -275,9 +276,9 @@ void API_Impl::RemoveGravity( const API::Gravity &g )
}
}
-void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) )
+void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) )
{
- this->worldScene.Visit(collideable, hitAction);
+ this->worldScene.Visit(collideable, args, hitAction);
}
//void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
index b9343ae6..63d8ff08 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
@@ -35,7 +35,7 @@ namespace Oyster
void AddGravity( const API::Gravity &g );
void RemoveGravity( const API::Gravity &g );
- void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) );
+ void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) );
//void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF );
diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
index 5a9bf53f..2f6a6c0c 100644
--- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
+++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
@@ -56,7 +56,7 @@ SimpleRigidBody::SimpleRigidBody()
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
{
- this->rigid.SetRotation( desc.rotation );
+ //this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition;
this->rigid.SetSize( desc.size );
this->rigid.SetMass_KeepMomentum( desc.mass );
@@ -143,8 +143,8 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
if( state.IsForwarded() )
{
- this->deltaPos += state.GetForward_DeltaPos();
- this->deltaAxis += state.GetForward_DeltaAxis();
+ this->deltaPos += Float4(state.GetForward_DeltaPos(), 0);
+ this->deltaAxis += Float4(state.GetForward_DeltaAxis(), 0);
this->isForwarded;
}
@@ -205,7 +205,7 @@ Sphere & SimpleRigidBody::GetBoundingSphere( Sphere &targetMem ) const
Float4 & SimpleRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
{
- Float4 offset = worldPos - this->rigid.centerPos;
+ Float4 offset = worldPos.xyz - this->rigid.centerPos;
Float distance = offset.Dot( offset );
Float3 normal = Float3::null;
@@ -295,7 +295,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
{
if( this->isForwarded )
{
- this->rigid.Move( this->deltaPos, this->deltaAxis );
+ this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
this->isForwarded = false;
@@ -310,7 +310,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
void SimpleRigidBody::Predict( Float4 &outDeltaPos, Float4 &outDeltaAxis, const Float4 &actingLinearImpulse, const Float4 &actingAngularImpulse, Float deltaTime )
{
- this->rigid.Predict_LeapFrog( outDeltaPos, outDeltaAxis, actingLinearImpulse, actingAngularImpulse, deltaTime );
+ this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
}
void SimpleRigidBody::SetScene( void *scene )
diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
index 9fd8d219..a164cbe1 100644
--- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
+++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
@@ -24,11 +24,11 @@ SphericalRigidBody::SphericalRigidBody()
SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc )
{
this->rigid = RigidBody();
- this->rigid.SetRotation( desc.rotation );
+ //this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition;
this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f );
this->rigid.SetMass_KeepMomentum( desc.mass );
- this->rigid.SetMomentOfInertia_KeepMomentum( Formula::MomentOfInertia::CreateSphereMatrix( desc.mass, desc.radius ) );
+ this->rigid.SetMomentOfInertia_KeepMomentum( MomentOfInertia::Sphere(desc.mass, desc.radius) );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
@@ -108,8 +108,8 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
if( state.IsForwarded() )
{
- this->deltaPos += state.GetForward_DeltaPos();
- this->deltaAxis += state.GetForward_DeltaAxis();
+ this->deltaPos += Float4(state.GetForward_DeltaPos(), 0);
+ this->deltaAxis += Float4(state.GetForward_DeltaAxis());
this->isForwarded = false;
}
@@ -171,7 +171,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
Float4 & SphericalRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
{
- targetMem = worldPos - this->rigid.centerPos;
+ targetMem = worldPos.xyz - this->rigid.centerPos;
Float magnitude = targetMem.GetMagnitude();
if( magnitude != 0.0f )
{ // sanity check
@@ -220,7 +220,7 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
{
if( this->isForwarded )
{
- this->rigid.Move( this->deltaPos, this->deltaAxis );
+ this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
this->isForwarded = false;
@@ -235,7 +235,7 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
void SphericalRigidBody::Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime )
{
- this->rigid.Predict_LeapFrog( outDeltaPos, outDeltaAxis, actingLinearImpulse, actingAngularImpulse, deltaTime );
+ this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
}
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h
index 7f20fcf7..3ced2a55 100644
--- a/Code/GamePhysics/PhysicsAPI.h
+++ b/Code/GamePhysics/PhysicsAPI.h
@@ -139,9 +139,11 @@ namespace Oyster
/********************************************************
* Applies an effect to objects that collide with the set volume.
* @param collideable: An ICollideable that defines the volume of the effect.
- * @param hitAction: A function that contains the effect.
+ * @param args: The arguments needed for the hitAction function.
+ * @param hitAction: A function that contains the effect. Parameterlist contains the custom body
+ the collideable hits, and the arguments sent to the function.
********************************************************/
- virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(ICustomBody*) ) = 0;
+ virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) ) = 0;
///********************************************************
// * Apply force on an object.
diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h
index 46de90cc..fa5533fa 100644
--- a/Code/GamePhysics/PhysicsStructs-Impl.h
+++ b/Code/GamePhysics/PhysicsStructs-Impl.h
@@ -13,13 +13,13 @@ namespace Oyster
inline SimpleBodyDescription::SimpleBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
- this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
- this->size = ::Oyster::Math::Float4( 1.0f );
+ this->centerPosition = ::Oyster::Math::Float3::null;
+ this->size = ::Oyster::Math::Float3( 1.0f );
this->mass = 12.0f;
this->restitutionCoeff = 1.0f;
this->frictionCoeff_Dynamic = 0.5f;
this->frictionCoeff_Static = 0.5f;
- this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
+ this->inertiaTensor = ::Oyster::Physics3D::MomentOfInertia();
this->subscription_onCollision = NULL;
this->subscription_onCollisionResponse = NULL;
this->subscription_onMovement = NULL;
@@ -29,7 +29,7 @@ namespace Oyster
inline SphericalBodyDescription::SphericalBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
- this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
+ this->centerPosition = ::Oyster::Math::Float3::null;
this->radius = 0.5f;
this->mass = 10.0f;
this->restitutionCoeff = 1.0f;
@@ -41,7 +41,7 @@ namespace Oyster
this->ignoreGravity = false;
}
- inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &gravityNormal )
+ inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Physics3D::MomentOfInertia &inertiaTensor, const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Float3 &rotation, const ::Oyster::Math::Float3 &linearMomentum, const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &gravityNormal )
{
this->mass = mass;
this->restitutionCoeff = restitutionCoeff;
@@ -53,8 +53,8 @@ namespace Oyster
this->angularAxis = rotation;
this->linearMomentum = linearMomentum;
this->angularMomentum = angularMomentum;
- this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null;
- this->deltaPos = this->deltaAxis = ::Oyster::Math::Float4::null;
+ this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float3::null;
+ this->deltaPos = this->deltaAxis = ::Oyster::Math::Float3::null;
this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false;
this->gravityNormal = gravityNormal;
}
@@ -102,92 +102,92 @@ namespace Oyster
return this->kineticFrictionCoeff;
}
- inline const ::Oyster::Math::Float4x4 & CustomBodyState::GetMomentOfInertia() const
+ inline const ::Oyster::Physics3D::MomentOfInertia & CustomBodyState::GetMomentOfInertia() const
{
return this->inertiaTensor;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetReach() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetReach() const
{
return this->reach;
}
- inline ::Oyster::Math::Float4 CustomBodyState::GetSize() const
+ inline ::Oyster::Math::Float3 CustomBodyState::GetSize() const
{
return 2.0f * this->GetReach();
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetCenterPosition() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetCenterPosition() const
{
return this->centerPos;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularAxis() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularAxis() const
{
return this->angularAxis;
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const
{
- return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis().xyz );
+ return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis() );
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation() const
{
- return ::Oyster::Math3D::OrientationMatrix( this->angularAxis.xyz, this->centerPos.xyz );
+ return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, this->centerPos );
}
- inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation( const ::Oyster::Math::Float4 &offset ) const
+ inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation( const ::Oyster::Math::Float3 &offset ) const
{
- return ::Oyster::Math3D::OrientationMatrix( this->angularAxis.xyz, (this->centerPos + offset).xyz );
+ return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, (this->centerPos + offset) );
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetView() const
{
- return ::Oyster::Math3D::ViewMatrix( this->angularAxis.xyz, this->centerPos.xyz );
+ return ::Oyster::Math3D::ViewMatrix( this->angularAxis, this->centerPos );
}
- inline ::Oyster::Math::Float4x4 CustomBodyState::GetView( const ::Oyster::Math::Float4 &offset ) const
+ inline ::Oyster::Math::Float4x4 CustomBodyState::GetView( const ::Oyster::Math::Float3 &offset ) const
{
- return ::Oyster::Math3D::ViewMatrix( this->angularAxis.xyz, (this->centerPos + offset).xyz );
+ return ::Oyster::Math3D::ViewMatrix( this->angularAxis, (this->centerPos + offset) );
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearMomentum() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearMomentum() const
{
return this->linearMomentum;
}
- inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const
+ inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
{
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos );
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
{
return this->angularMomentum;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearImpulse() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearImpulse() const
{
return this->linearImpulse;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularImpulse() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularImpulse() const
{
return this->angularImpulse;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetForward_DeltaPos() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaPos() const
{
return this->deltaPos;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetForward_DeltaAxis() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaAxis() const
{
return this->deltaAxis;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetGravityNormal() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetGravityNormal() const
{
return this->gravityNormal;
}
@@ -219,47 +219,51 @@ namespace Oyster
this->kineticFrictionCoeff = kineticU;
}
- inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor )
+ inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &tensor )
{
this->inertiaTensor = tensor;
}
- inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor )
+ inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &tensor )
{
- if( tensor.GetDeterminant() != 0.0f )
- { // sanity block!
- ::Oyster::Math::Float4x4 rotation = ::Oyster::Math3D::RotationMatrix(this->angularAxis.xyz);
- ::Oyster::Math::Float4 w = ::Oyster::Physics3D::Formula::AngularVelocity( (rotation * this->inertiaTensor).GetInverse(), this->angularMomentum );
- this->inertiaTensor = tensor;
- this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w );
- }
+ ::Oyster::Math::Quaternion rotation = ::Oyster::Math3D::Rotation(this->angularAxis);
+ ::Oyster::Math::Float3 w = this->inertiaTensor.CalculateAngularVelocity( rotation, this->angularMomentum );
+ this->inertiaTensor = tensor;
+ this->angularMomentum = this->inertiaTensor.CalculateAngularMomentum( rotation, w );
}
- inline void CustomBodyState::SetSize( const ::Oyster::Math::Float4 &size )
+ inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size )
{
this->SetReach( 0.5f * size );
}
- inline void CustomBodyState::SetReach( const ::Oyster::Math::Float4 &halfSize )
+ inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize )
{
- this->reach.xyz = halfSize;
- this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float4::null );
+ this->reach = halfSize;
+ this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float3::null );
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float4 ¢erPos )
+ inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos )
{
- this->centerPos.xyz = centerPos;
+ this->centerPos = centerPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4 &angularAxis )
+ inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis )
{
- this->angularAxis.xyz = angularAxis;
+ this->angularAxis = angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation )
+ inline void CustomBodyState::SetOrientation( const ::Oyster::Math::Float3 &angularAxis, const ::Oyster::Math::Float3 &translation )
+ {
+ this->angularAxis = angularAxis ;
+ this->centerPos = translation;
+ this->isSpatiallyAltered = this->isDisturbed = true;
+ }
+
+ /*inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation )
{
this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation) );
}
@@ -268,72 +272,74 @@ namespace Oyster
{
this->SetRotation( ::Oyster::Math3D::ExtractAngularAxis(orientation) );
this->SetCenterPosition( orientation.v[3] );
- }
+ }*/
- inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float4 &g )
+
+
+ inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float3 &g )
{
- this->linearMomentum.xyz = g;
+ this->linearMomentum = g;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float4 &h )
+ inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float3 &h )
{
- this->angularMomentum.xyz = h;
+ this->angularMomentum = h;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float3 &j )
{
- this->linearImpulse.xyz = j;
+ this->linearImpulse = j;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float3 &j )
{
- this->angularImpulse.xyz = j;
+ this->angularImpulse = j;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float4 &gravityNormal )
+ inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float3 &gravityNormal )
{
this->gravityNormal = gravityNormal;
}
- inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis )
+ inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float3 &angularAxis )
{
this->angularAxis += angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float4 &deltaPos )
+ inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float3 &deltaPos )
{
this->centerPos += deltaPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float3 &j )
{
this->linearImpulse += j;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float3 &j )
{
this->angularImpulse += j;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal )
+ inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal )
{
- ::Oyster::Math::Float4 offset = at - this->centerPos;
- ::Oyster::Math::Float4 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
+ ::Oyster::Math::Float3 offset = at - this->centerPos;
+ ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset );
this->angularImpulse += deltaAngularImpulse;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyForwarding( const ::Oyster::Math::Float4 &deltaPos, const ::Oyster::Math::Float4 &deltaAxis )
+ inline void CustomBodyState::ApplyForwarding( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis )
{
this->deltaPos += deltaPos;
this->deltaAxis += deltaAxis;
diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h
index 1bc1736f..49cf6993 100644
--- a/Code/GamePhysics/PhysicsStructs.h
+++ b/Code/GamePhysics/PhysicsStructs.h
@@ -3,6 +3,7 @@
#include "OysterMath.h"
#include "PhysicsAPI.h"
+#include "Inertia.h"
namespace Oyster { namespace Physics
{
@@ -11,13 +12,13 @@ namespace Oyster { namespace Physics
struct SimpleBodyDescription
{
::Oyster::Math::Float4x4 rotation;
- ::Oyster::Math::Float4 centerPosition;
- ::Oyster::Math::Float4 size;
+ ::Oyster::Math::Float3 centerPosition;
+ ::Oyster::Math::Float3 size;
::Oyster::Math::Float mass;
::Oyster::Math::Float restitutionCoeff;
::Oyster::Math::Float frictionCoeff_Static;
::Oyster::Math::Float frictionCoeff_Dynamic;
- ::Oyster::Math::Float4x4 inertiaTensor;
+ ::Oyster::Physics3D::MomentOfInertia inertiaTensor;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
@@ -29,7 +30,7 @@ namespace Oyster { namespace Physics
struct SphericalBodyDescription
{
::Oyster::Math::Float4x4 rotation;
- ::Oyster::Math::Float4 centerPosition;
+ ::Oyster::Math::Float3 centerPosition;
::Oyster::Math::Float radius;
::Oyster::Math::Float mass;
::Oyster::Math::Float restitutionCoeff;
@@ -50,13 +51,13 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float restitutionCoeff = 1.0f,
::Oyster::Math::Float staticFrictionCoeff = 1.0f,
::Oyster::Math::Float kineticFrictionCoeff = 1.0f,
- const ::Oyster::Math::Float4x4 &inertiaTensor = ::Oyster::Math::Float4x4::identity,
- const ::Oyster::Math::Float4 &reach = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 ¢erPos = ::Oyster::Math::Float4::standard_unit_w,
- const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 &linearMomentum = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 &angularMomentum = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 &gravityNormal = ::Oyster::Math::Float4::null);
+ const ::Oyster::Physics3D::MomentOfInertia &inertiaTensor = ::Oyster::Physics3D::MomentOfInertia(),
+ const ::Oyster::Math::Float3 &reach = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 ¢erPos = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &rotation = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &linearMomentum = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &angularMomentum = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &gravityNormal = ::Oyster::Math::Float3::null);
CustomBodyState & operator = ( const CustomBodyState &state );
@@ -64,50 +65,51 @@ namespace Oyster { namespace Physics
const ::Oyster::Math::Float GetRestitutionCoeff() const;
const ::Oyster::Math::Float GetFrictionCoeff_Static() const;
const ::Oyster::Math::Float GetFrictionCoeff_Kinetic() const;
- const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
- const ::Oyster::Math::Float4 & GetReach() const;
- ::Oyster::Math::Float4 GetSize() const;
- const ::Oyster::Math::Float4 & GetCenterPosition() const;
- const ::Oyster::Math::Float4 & GetAngularAxis() const;
+ const ::Oyster::Physics3D::MomentOfInertia & GetMomentOfInertia() const;
+ const ::Oyster::Math::Float3 & GetReach() const;
+ ::Oyster::Math::Float3 GetSize() const;
+ const ::Oyster::Math::Float3 & GetCenterPosition() const;
+ const ::Oyster::Math::Float3 & GetAngularAxis() const;
::Oyster::Math::Float4x4 GetRotation() const;
::Oyster::Math::Float4x4 GetOrientation() const;
- ::Oyster::Math::Float4x4 GetOrientation( const ::Oyster::Math::Float4 &offset ) const;
+ ::Oyster::Math::Float4x4 GetOrientation( const ::Oyster::Math::Float3 &offset ) const;
::Oyster::Math::Float4x4 GetView() const;
- ::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float4 &offset ) const;
- const ::Oyster::Math::Float4 & GetLinearMomentum() const;
- ::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const;
- const ::Oyster::Math::Float4 & GetAngularMomentum() const;
- const ::Oyster::Math::Float4 & GetLinearImpulse() const;
- const ::Oyster::Math::Float4 & GetAngularImpulse() const;
- const ::Oyster::Math::Float4 & GetForward_DeltaPos() const;
- const ::Oyster::Math::Float4 & GetForward_DeltaAxis() const;
- const ::Oyster::Math::Float4 & GetGravityNormal() const;
+ ::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
+ const ::Oyster::Math::Float3 & GetLinearMomentum() const;
+ ::Oyster::Math::Float3 GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const;
+ const ::Oyster::Math::Float3 & GetAngularMomentum() const;
+ const ::Oyster::Math::Float3 & GetLinearImpulse() const;
+ const ::Oyster::Math::Float3 & GetAngularImpulse() const;
+ const ::Oyster::Math::Float3 & GetForward_DeltaPos() const;
+ const ::Oyster::Math::Float3 & GetForward_DeltaAxis() const;
+ const ::Oyster::Math::Float3 & GetGravityNormal() const;
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetRestitutionCoeff( ::Oyster::Math::Float e );
void SetFrictionCoeff( ::Oyster::Math::Float staticU, ::Oyster::Math::Float kineticU );
- void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor );
- void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor );
- void SetSize( const ::Oyster::Math::Float4 &size );
- void SetReach( const ::Oyster::Math::Float4 &halfSize );
- void SetCenterPosition( const ::Oyster::Math::Float4 ¢erPos );
- void SetRotation( const ::Oyster::Math::Float4 &angularAxis );
- void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
- void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
- void SetLinearMomentum( const ::Oyster::Math::Float4 &g );
- void SetAngularMomentum( const ::Oyster::Math::Float4 &h );
- void SetLinearImpulse( const ::Oyster::Math::Float4 &j );
- void SetAngularImpulse( const ::Oyster::Math::Float4 &j );
- void SetGravityNormal( const ::Oyster::Math::Float4 &gravityNormal );
+ void SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &tensor );
+ void SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &tensor );
+ void SetSize( const ::Oyster::Math::Float3 &size );
+ void SetReach( const ::Oyster::Math::Float3 &halfSize );
+ void SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos );
+ void SetRotation( const ::Oyster::Math::Float3 &angularAxis );
+ //void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
+ //void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
+ void SetOrientation( const ::Oyster::Math::Float3 &angularAxis, const ::Oyster::Math::Float3 &translation );
+ void SetLinearMomentum( const ::Oyster::Math::Float3 &g );
+ void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
+ void SetLinearImpulse( const ::Oyster::Math::Float3 &j );
+ void SetAngularImpulse( const ::Oyster::Math::Float3 &j );
+ void SetGravityNormal( const ::Oyster::Math::Float3 &gravityNormal );
- void AddRotation( const ::Oyster::Math::Float4 &angularAxis );
- void AddTranslation( const ::Oyster::Math::Float4 &deltaPos );
+ void AddRotation( const ::Oyster::Math::Float3 &angularAxis );
+ void AddTranslation( const ::Oyster::Math::Float3 &deltaPos );
- void ApplyLinearImpulse( const ::Oyster::Math::Float4 &j );
- void ApplyAngularImpulse( const ::Oyster::Math::Float4 &j );
- void ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal );
- void ApplyForwarding( const ::Oyster::Math::Float4 &deltaPos, const ::Oyster::Math::Float4 &deltaAxis );
+ void ApplyLinearImpulse( const ::Oyster::Math::Float3 &j );
+ void ApplyAngularImpulse( const ::Oyster::Math::Float3 &j );
+ void ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal );
+ void ApplyForwarding( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis );
bool IsSpatiallyAltered() const;
bool IsDisturbed() const;
@@ -115,12 +117,12 @@ namespace Oyster { namespace Physics
private:
::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, kineticFrictionCoeff;
- ::Oyster::Math::Float4x4 inertiaTensor;
- ::Oyster::Math::Float4 reach, centerPos, angularAxis;
- ::Oyster::Math::Float4 linearMomentum, angularMomentum;
- ::Oyster::Math::Float4 linearImpulse, angularImpulse;
- ::Oyster::Math::Float4 deltaPos, deltaAxis; // Forwarding data sum
- ::Oyster::Math::Float4 gravityNormal;
+ ::Oyster::Physics3D::MomentOfInertia inertiaTensor;
+ ::Oyster::Math::Float3 reach, centerPos, angularAxis;
+ ::Oyster::Math::Float3 linearMomentum, angularMomentum;
+ ::Oyster::Math::Float3 linearImpulse, angularImpulse;
+ ::Oyster::Math::Float3 deltaPos, deltaAxis; // Forwarding data sum
+ ::Oyster::Math::Float3 gravityNormal;
bool isSpatiallyAltered, isDisturbed, isForwarded;
};
diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h
index d32ea04f..50bcd36b 100644
--- a/Code/OysterMath/LinearMath.h
+++ b/Code/OysterMath/LinearMath.h
@@ -35,7 +35,7 @@ namespace std
// x2
template
-::LinearAlgebra::Matrix2x2 operator * ( const ::LinearAlgebra::Matrix2x2 &left, const ::LinearAlgebra::Matrix2x2 &right )
+inline ::LinearAlgebra::Matrix2x2 operator * ( const ::LinearAlgebra::Matrix2x2 &left, const ::LinearAlgebra::Matrix2x2 &right )
{
return ::LinearAlgebra::Matrix2x2( (left.m11 * right.m11) + (left.m12 * right.m21),
(left.m11 * right.m12) + (left.m12 * right.m22),
@@ -44,14 +44,14 @@ template
}
template
-::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Matrix2x2 &matrix, const ::LinearAlgebra::Vector2 &vector )
+inline ::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Matrix2x2 &matrix, const ::LinearAlgebra::Vector2 &vector )
{
return ::LinearAlgebra::Vector2( (matrix.m11 * vector.x) + (matrix.m12 * vector.y),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) );
}
template
-::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Vector2 &vector, const ::LinearAlgebra::Matrix2x2 &left )
+inline ::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Vector2 &vector, const ::LinearAlgebra::Matrix2x2 &left )
{
return ::LinearAlgebra::Vector2( (vector.x * matrix.m11) + (vector.y * matrix.m21),
(vector.x * matrix.m12) + (vector.y * matrix.m22) );
@@ -60,7 +60,7 @@ template
// x3
template
-::LinearAlgebra::Matrix3x3 operator * ( const ::LinearAlgebra::Matrix3x3 &left, const ::LinearAlgebra::Matrix3x3 &right )
+inline ::LinearAlgebra::Matrix3x3 operator * ( const ::LinearAlgebra::Matrix3x3 &left, const ::LinearAlgebra::Matrix3x3 &right )
{
return ::LinearAlgebra::Matrix3x3( (left.m11 * right.m11) + (left.m12 * right.m21) + (left.m13 * right.m31), (left.m11 * right.m12) + (left.m12 * right.m22) + (left.m13 * right.m32), (left.m11 * right.m13) + (left.m12 * right.m23) + (left.m13 * right.m33),
(left.m21 * right.m11) + (left.m22 * right.m21) + (left.m23 * right.m31), (left.m21 * right.m12) + (left.m22 * right.m22) + (left.m23 * right.m32), (left.m21 * right.m13) + (left.m22 * right.m23) + (left.m23 * right.m33),
@@ -68,7 +68,7 @@ template
}
template
-::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Matrix3x3 &matrix, const ::LinearAlgebra::Vector3 &vector )
+inline ::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Matrix3x3 &matrix, const ::LinearAlgebra::Vector3 &vector )
{
return ::LinearAlgebra::Vector3( (matrix.m11 * vector.x) + (matrix.m12 * vector.y) + (matrix.m13 * vector.z),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) + (matrix.m23 * vector.z),
@@ -76,7 +76,7 @@ template
}
template
-::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Vector3 &vector, const ::LinearAlgebra::Matrix3x3 &left )
+inline ::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Vector3 &vector, const ::LinearAlgebra::Matrix3x3 &left )
{
return ::LinearAlgebra::Vector3( (vector.x * matrix.m11) + (vector.y * matrix.m21) + (vector.z * matrix.m31),
(vector.x * matrix.m12) + (vector.y * matrix.m22) + (vector.z * matrix.m32),
@@ -86,7 +86,7 @@ template
// x4
template
-::LinearAlgebra::Matrix4x4 operator * ( const ::LinearAlgebra::Matrix4x4 &left, const ::LinearAlgebra::Matrix4x4 &right )
+inline ::LinearAlgebra::Matrix4x4 operator * ( const ::LinearAlgebra::Matrix4x4 &left, const ::LinearAlgebra::Matrix4x4 &right )
{
return ::LinearAlgebra::Matrix4x4( (left.m11 * right.m11) + (left.m12 * right.m21) + (left.m13 * right.m31) + (left.m14 * right.m41), (left.m11 * right.m12) + (left.m12 * right.m22) + (left.m13 * right.m32) + (left.m14 * right.m42), (left.m11 * right.m13) + (left.m12 * right.m23) + (left.m13 * right.m33) + (left.m14 * right.m43), (left.m11 * right.m14) + (left.m12 * right.m24) + (left.m13 * right.m34) + (left.m14 * right.m44),
(left.m21 * right.m11) + (left.m22 * right.m21) + (left.m23 * right.m31) + (left.m24 * right.m41), (left.m21 * right.m12) + (left.m22 * right.m22) + (left.m23 * right.m32) + (left.m24 * right.m42), (left.m21 * right.m13) + (left.m22 * right.m23) + (left.m23 * right.m33) + (left.m24 * right.m43), (left.m21 * right.m14) + (left.m22 * right.m24) + (left.m23 * right.m34) + (left.m24 * right.m44),
@@ -95,7 +95,7 @@ template
}
template
-::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Matrix4x4 &matrix, const ::LinearAlgebra::Vector4 &vector )
+inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Matrix4x4 &matrix, const ::LinearAlgebra::Vector4 &vector )
{
return ::LinearAlgebra::Vector4( (matrix.m11 * vector.x) + (matrix.m12 * vector.y) + (matrix.m13 * vector.z) + (matrix.m14 * vector.w),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) + (matrix.m23 * vector.z) + (matrix.m24 * vector.w),
@@ -104,7 +104,7 @@ template
}
template
-::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Matrix4x4 &matrix )
+inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Matrix4x4 &matrix )
{
return ::LinearAlgebra::Vector4( (vector.x * matrix.m11) + (vector.y * matrix.m21) + (vector.z * matrix.m31) + (vector.w * matrix.m41),
(vector.x * matrix.m12) + (vector.y * matrix.m22) + (vector.z * matrix.m32) + (vector.w * matrix.m42),
@@ -204,6 +204,19 @@ namespace LinearAlgebra
}
return output; // error: returning nullvector
}
+
+ /********************************************************************
+ * Spherical Linear Interpolation on Quaternions
+ ********************************************************************/
+ template
+ inline Quaternion Slerp( const Quaternion &start, const Quaternion &end, const ScalarType &t )
+ {
+ ScalarType angle = (ScalarType)::std::acos( Vector4(start.imaginary, start.real).Dot(Vector4(end.imaginary, end.real)) );
+ Quaternion result = start * (ScalarType)::std::sin( angle * (1 - t) );
+ result += end * (ScalarType)::std::sin( angle * t );
+ result *= (ScalarType)1.0f / (ScalarType)::std::sin( angle );
+ return result;
+ }
}
namespace LinearAlgebra2D
@@ -312,23 +325,24 @@ namespace LinearAlgebra2D
namespace LinearAlgebra3D
{
- template
- inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
- }
+ // All Matrix to AngularAxis conversions here is incorrect
+ //template
+ //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
+ //}
- template
- inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
- }
+ //template
+ //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
+ //}
- template
- inline ::LinearAlgebra::Vector4 ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4 &orientationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
- }
+ //template
+ //inline ::LinearAlgebra::Vector4 ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4 &orientationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
+ //}
template
inline ::LinearAlgebra::Matrix4x4 & TranslationMatrix( const ::LinearAlgebra::Vector3 &position, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() )
@@ -756,6 +770,28 @@ namespace LinearAlgebra3D
return rotation; // return no change
return SnapAxisYToNormal_UsingNlerp( rotation, interpolated );
}
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ targetMem.v[0] = ::LinearAlgebra::Nlerp( start.v[0], end.v[0], t );
+ targetMem.v[1] = ::LinearAlgebra::Nlerp( start.v[1], end.v[1], t );
+ targetMem.v[2] = ::LinearAlgebra::Nlerp( start.v[2], end.v[2], t );
+ targetMem.v[3] = ::LinearAlgebra::Lerp( start.v[3], end.v[3], t );
+ return targetMem;
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Quaternion &startR, const ::LinearAlgebra::Vector3 &startT, const ::LinearAlgebra::Quaternion &endR, const ::LinearAlgebra::Vector3 &endT, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ return InterpolateOrientation_UsingNonRigidNlerp( OrientationMatrix(startR, startT), OrientationMatrix(endR, endT), t, targetMem );
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingSlerp( const ::LinearAlgebra::Quaternion &startR, const ::LinearAlgebra::Vector3 &startT, const ::LinearAlgebra::Quaternion &endR, const ::LinearAlgebra::Vector3 &endT, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ return OrientationMatrix( ::LinearAlgebra::Slerp(startR, endR, t), ::LinearAlgebra::Lerp(::LinearAlgebra::Vector4(startT, (ScalarType)1.0f), ::LinearAlgebra::Vector4(endT, (ScalarType)1.0f), t).xyz, targetMem );
+ }
}
#include "Utilities.h"
diff --git a/Code/OysterMath/Matrix.h b/Code/OysterMath/Matrix.h
index c7b6b9e0..5d129431 100644
--- a/Code/OysterMath/Matrix.h
+++ b/Code/OysterMath/Matrix.h
@@ -163,12 +163,18 @@ namespace LinearAlgebra
Vector4 GetRowVector( unsigned int rowID ) const;
const Vector4 & GetColumnVector( unsigned int colID ) const;
};
+}
+template LinearAlgebra::Matrix2x2 operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2 &right );
+template LinearAlgebra::Matrix3x3 operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3 &right );
+template LinearAlgebra::Matrix4x4 operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4 &right );
///////////////////////////////////////////////////////////////////////////////////
// Body
///////////////////////////////////////////////////////////////////////////////////
+namespace LinearAlgebra
+{
// Matrix2x2 ///////////////////////////////////////
template
@@ -753,4 +759,22 @@ namespace LinearAlgebra
{ return this->v[colID]; }
}
+template
+inline LinearAlgebra::Matrix2x2 operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2 &right )
+{
+ return right * left;
+}
+
+template
+inline LinearAlgebra::Matrix3x3 operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3 &right )
+{
+ return right * left;
+}
+
+template
+inline LinearAlgebra::Matrix4x4 operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4 &right )
+{
+ return right * left;
+}
+
#endif
\ No newline at end of file
diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp
index f44de9fd..bbaccf11 100644
--- a/Code/OysterMath/OysterMath.cpp
+++ b/Code/OysterMath/OysterMath.cpp
@@ -81,20 +81,20 @@ namespace Oyster { namespace Math2D
namespace Oyster { namespace Math3D
{
- Float4 AngularAxis( const Float3x3 &rotationMatrix )
- {
- return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
- }
+ //Float4 AngularAxis( const Float3x3 &rotationMatrix )
+ //{
+ // return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
+ //}
- Float4 AngularAxis( const Float4x4 &rotationMatrix )
- {
- return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
- }
+ //Float4 AngularAxis( const Float4x4 &rotationMatrix )
+ //{
+ // return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
+ //}
- Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix )
- {
- return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
- }
+ //Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix )
+ //{
+ // return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
+ //}
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
{
diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h
index 3770bf02..5970face 100644
--- a/Code/OysterMath/OysterMath.h
+++ b/Code/OysterMath/OysterMath.h
@@ -57,59 +57,38 @@ namespace Oyster { namespace Math //! Oyster's native math library
* @return nullvector if Lerp( start, end, t ) is nullvector.
********************************************************************/
using ::LinearAlgebra::Nlerp;
+
+ /********************************************************************
+ * Spherical Linear Interpolation on Quaternions
+ ********************************************************************/
+ using ::LinearAlgebra::Slerp;
} }
inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right )
-{ return ::Oyster::Math::Float2(left) *= right; }
-
-inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float2 &right )
-{ return ::Oyster::Math::Float2(right) *= left; }
+{
+ return left.PiecewiseMultiplication( right );
+}
inline ::Oyster::Math::Float3 & operator *= ( ::Oyster::Math::Float3 &left, const ::Oyster::Math::Float3 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- left.z *= right.z;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float3 &left, const ::Oyster::Math::Float3 &right )
-{ return ::Oyster::Math::Float3(left) *= right; }
-
-inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float3 &right )
-{ return ::Oyster::Math::Float3(right) *= left; }
+{
+ return left.PiecewiseMultiplication( right );
+}
inline ::Oyster::Math::Float4 & operator *= ( ::Oyster::Math::Float4 &left, const ::Oyster::Math::Float4 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- left.z *= right.z;
- left.w *= right.w;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
-inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float4 &left, const ::Oyster::Math::Float4 &right )
-{ return ::Oyster::Math::Float4(left) *= right; }
-
-inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float4 &right )
-{ return ::Oyster::Math::Float4(right) *= left; }
-
-inline ::Oyster::Math::Float2x2 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float2x2 &right )
-{ return ::Oyster::Math::Float2x2(right) *= left; }
-
-inline ::Oyster::Math::Float3x3 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float3x3 &right )
-{ return ::Oyster::Math::Float3x3(right) *= left; }
-
-inline ::Oyster::Math::Float4x4 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float4x4 &right )
-{ return ::Oyster::Math::Float4x4(right) *= left; }
-
namespace Oyster { namespace Math2D //! Oyster's native math library specialized for 2D
{
using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace
@@ -162,13 +141,13 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace
//! Extracts the angularAxis from rotationMatrix
- Float4 AngularAxis( const Float3x3 &rotationMatrix );
+ //Float4 AngularAxis( const Float3x3 &rotationMatrix );
- //! Extracts the angularAxis from rotationMatrix
- Float4 AngularAxis( const Float4x4 &rotationMatrix );
+ ////! Extracts the angularAxis from rotationMatrix
+ //Float4 AngularAxis( const Float4x4 &rotationMatrix );
- //! Extracts the angularAxis from orientationMatrix
- Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
+ ////! Extracts the angularAxis from orientationMatrix
+ //Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
//! Sets and returns targetMem to a translationMatrix with position as translation.
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );
@@ -343,6 +322,8 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
using ::LinearAlgebra3D::SnapAxisYToNormal_UsingNlerp;
using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp;
+ using ::LinearAlgebra3D::InterpolateOrientation_UsingNonRigidNlerp;
+ using ::LinearAlgebra3D::InterpolateOrientation_UsingSlerp;
} }
#endif
\ No newline at end of file
diff --git a/Code/OysterMath/Vector.h b/Code/OysterMath/Vector.h
index 901ea5e4..ea36cfc9 100644
--- a/Code/OysterMath/Vector.h
+++ b/Code/OysterMath/Vector.h
@@ -57,6 +57,12 @@ namespace LinearAlgebra
ScalarType GetMagnitude( ) const;
ScalarType Dot( const Vector2 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y)
+ Vector2 PiecewiseMultiplication( const Vector2 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y)
+ Vector2 & PiecewiseMultiplicationAdd( const Vector2 &vector );
+
Vector2 & Normalize( );
Vector2 GetNormalized( ) const;
};
@@ -112,6 +118,12 @@ namespace LinearAlgebra
ScalarType Dot( const Vector3 &vector ) const;
Vector3 Cross( const Vector3 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y, a.z * b.z)
+ Vector3 PiecewiseMultiplication( const Vector3 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y, a.z * b.z)
+ Vector3 & PiecewiseMultiplicationAdd( const Vector3 &vector );
+
Vector3 & Normalize( );
Vector3 GetNormalized( ) const;
};
@@ -169,14 +181,27 @@ namespace LinearAlgebra
ScalarType GetMagnitude( ) const;
ScalarType Dot( const Vector4 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
+ Vector4 PiecewiseMultiplication( const Vector4 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
+ Vector4 & PiecewiseMultiplicationAdd( const Vector4 &vector );
+
Vector4 & Normalize( );
Vector4 GetNormalized( ) const;
};
+}
+
+template ::LinearAlgebra::Vector2 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector2 &right );
+template ::LinearAlgebra::Vector3 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector3 &right );
+template ::LinearAlgebra::Vector4 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector4 &right );
///////////////////////////////////////////////////////////////////////////////////
// Body
///////////////////////////////////////////////////////////////////////////////////
+namespace LinearAlgebra
+{
// Vector2 ///////////////////////////////////////
template const Vector2 Vector2::null = Vector2( 0, 0 );
@@ -184,22 +209,22 @@ namespace LinearAlgebra
template const Vector2 Vector2::standard_unit_y = Vector2( 0, 1 );
template
- Vector2::Vector2( ) : x(), y() {}
+ inline Vector2::Vector2( ) : x(), y() {}
template
- Vector2::Vector2( const Vector2 &vector )
+ inline Vector2::Vector2( const Vector2 &vector )
{ this->x = vector.x; this->y = vector.y; }
template
- Vector2::Vector2( const ScalarType &_element )
+ inline Vector2::Vector2( const ScalarType &_element )
{ this->x = this->y = _element; }
template
- Vector2::Vector2( const ScalarType _element[2] )
+ inline Vector2::Vector2( const ScalarType _element[2] )
{ this->x = _element[0]; this->y = _element[1]; }
template
- Vector2::Vector2( const ScalarType &_x, const ScalarType &_y )
+ inline Vector2::Vector2( const ScalarType &_x, const ScalarType &_y )
{ this->x = _x; this->y = _y; }
template
@@ -227,7 +252,7 @@ namespace LinearAlgebra
{ return this->element[i]; }
template
- Vector2 & Vector2::operator = ( const Vector2 &vector )
+ inline Vector2 & Vector2::operator = ( const Vector2 &vector )
{
this->element[0] = vector.element[0];
this->element[1] = vector.element[1];
@@ -235,7 +260,7 @@ namespace LinearAlgebra
}
template
- Vector2 & Vector2::operator = ( const ScalarType _element[2] )
+ inline Vector2 & Vector2::operator = ( const ScalarType _element[2] )
{
this->element[0] = _element[0];
this->element[1] = _element[1];
@@ -243,7 +268,7 @@ namespace LinearAlgebra
}
template
- Vector2 & Vector2::operator *= ( const ScalarType &scalar )
+ inline Vector2 & Vector2::operator *= ( const ScalarType &scalar )
{
this->element[0] *= scalar;
this->element[1] *= scalar;
@@ -251,7 +276,7 @@ namespace LinearAlgebra
}
template
- Vector2 & Vector2::operator /= ( const ScalarType &scalar )
+ inline Vector2 & Vector2::operator /= ( const ScalarType &scalar )
{
this->element[0] /= scalar;
this->element[1] /= scalar;
@@ -259,7 +284,7 @@ namespace LinearAlgebra
}
template
- Vector2 & Vector2::operator += ( const Vector2 &vector )
+ inline Vector2 & Vector2::operator += ( const Vector2 &vector )
{
this->element[0] += vector.element[0];
this->element[1] += vector.element[1];
@@ -267,7 +292,7 @@ namespace LinearAlgebra
}
template
- Vector2 & Vector2::operator -= ( const Vector2