123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- Namespace mojo3d
- Private
- Const DegreesToRadians:=Pi/180.0
- Const RadiansToDegrees:=180.0/Pi
- Public
- #rem monkeydoc Utility extension methods for entities.
- #end
- Class Entity Extension
-
- #rem monkeydoc The rigid body attached to the entity.
- #end
- Property RigidBody:RigidBody()
-
- Return GetComponent<RigidBody>()
- End
-
- #rem monkeydoc The collider attached to the entity.
- #end
- Property Collider:Collider()
-
- Return GetComponent<Collider>()
- End
- #rem monkeydoc The animator attached to the entity.
- #end
- Property Animator:Animator()
-
- Return GetComponent<Animator>()
- End
- #rem monkeydoc World space rotation in degrees.
- #end
- Property Rotation:Vec3f()
-
- Return Basis.GetRotation() * RadiansToDegrees
-
- Setter( rotation:Vec3f )
-
- Basis=Mat3f.Rotation( rotation * DegreesToRadians )
- End
-
- #rem monkeydoc Local space rotation in degrees.
- #end
- Property LocalRotation:Vec3f()
-
- Return LocalBasis.GetRotation() * RadiansToDegrees
-
- Setter( rotation:Vec3f )
-
- LocalBasis=Mat3f.Rotation( rotation * DegreesToRadians )
- End
-
- #Rem monkeydoc World space rotation around the X axis in degrees.
- #End
- Property Rx:Float()
-
- Return Rotation.x
-
- Setter( rx:Float )
-
- Local r:=Rotation
- Rotation=New Vec3f( rx,r.y,r.z )
- End
- #Rem monkeydoc World space rotation around the Y axis in degrees.
- #End
- Property Ry:Float()
-
- Return Rotation.y
-
- Setter( ry:Float )
-
- Local r:=Rotation
- Rotation=New Vec3f( r.x,ry,r.z )
- End
- #Rem monkeydoc World space rotation around the Z axis in degrees.
- #End
- Property Rz:Float()
-
- Return Rotation.z
-
- Setter( rz:Float )
-
- Local r:=Rotation
- Rotation=New Vec3f( r.x,r.y,rz )
- End
-
- #Rem monkeydoc Local space rotation around the X axis in degrees.
- #End
- Property LocalRx:Float()
-
- Return LocalRotation.x
-
- Setter( rx:Float )
-
- Local r:=LocalRotation
- LocalRotation=New Vec3f( rx,r.y,r.z )
- End
- #Rem monkeydoc Local space rotation around the Y axis in degrees.
- #End
- Property LocalRy:Float()
-
- Return LocalRotation.y
-
- Setter( ry:Float )
-
- Local r:=LocalRotation
- LocalRotation=New Vec3f( r.x,ry,r.z )
- End
- #Rem monkeydoc Local space rotation around the Z axis in degrees.
- #End
- Property LocalRz:Float()
-
- Return LocalRotation.z
-
- Setter( rz:Float )
-
- Local r:=LocalRotation
- LocalRotation=New Vec3f( r.x,r.y,rz )
- End
- #rem monkeydoc World space X coordinate.
- #end
- Property X:Float()
-
- Return Position.x
-
- Setter( x:Float )
-
- Local v:=Position
- Position=New Vec3f( x,v.y,v.z )
- End
-
- #rem monkeydoc World space Y coordinate.
- #end
- Property Y:Float()
-
- Return Position.y
-
- Setter( y:Float )
-
- Local v:=Position
- Position=New Vec3f( v.x,y,v.z )
- End
- #rem monkeydoc World space Z coordinate.
- #end
- Property Z:Float()
-
- Return Position.z
-
- Setter( z:Float )
-
- Local v:=Position
- Position=New Vec3f( v.x,v.y,z )
- End
-
- #rem monkeydoc Local space X coordinate.
- #end
- Property LocalX:Float()
-
- Return LocalPosition.x
-
- Setter( x:Float )
- Local v:=LocalPosition
- LocalPosition=New Vec3f( x,v.y,v.z )
- End
-
- #rem monkeydoc Local space Y coordinate.
- #end
- Property LocalY:Float()
-
- Return LocalPosition.y
-
- Setter( y:Float )
-
- Local v:=LocalPosition
- LocalPosition=New Vec3f( v.x,y,v.z )
- End
- #rem monkeydoc Local space Z coordinate.
- #end
- Property LocalZ:Float()
-
- Return LocalPosition.z
-
- Setter( z:Float )
-
- Local v:=LocalPosition
- LocalPosition=New Vec3f( v.x,v.y,z )
- End
-
- #rem monkeydoc World space scale on the X axis.
- #end
- Property Sx:Float()
-
- Return Scale.x
-
- Setter( sx:Float )
-
- Local s:=Scale
- Scale=New Vec3f( sx,s.y,s.z )
- End
-
- #rem monkeydoc World space scale on the Y axis.
- #end
- Property Sy:Float()
-
- Return Scale.y
-
- Setter( sy:Float )
-
- Local s:=Scale
- Scale=New Vec3f( s.x,sy,s.z )
- End
-
- #rem monkeydoc World space scale on the Z axis.
- #end
- Property Sz:Float()
-
- Return Scale.z
-
- Setter( sz:Float )
-
- Local s:=Scale
- Scale=New Vec3f( s.x,s.y,sz )
- End
-
- #rem monkeydoc Local space scale on the X axis.
- #end
- Property LocalSx:Float()
-
- Return LocalScale.x
-
- Setter( sx:Float )
-
- Local s:=LocalScale
-
- LocalScale=New Vec3f( sx,s.y,s.z )
- End
-
- #rem monkeydoc Local space scale on the Y axis.
- #end
- Property LocalSy:Float()
-
- Return LocalScale.y
-
- Setter( sy:Float )
-
- Local s:=LocalScale
- LocalScale=New Vec3f( s.x,sy,s.z )
- End
-
- #rem monkeydoc Local space scale on the Z axis.
- #end
- Property LocalSz:Float()
-
- Return LocalScale.z
-
- Setter( sz:Float )
-
- Local s:=LocalScale
- LocalScale=New Vec3f( s.x,s.y,sz )
- End
-
- #rem monkeydoc Sets entity position in local or world space.
- #end
- Method SetPosition( position:Vec3f,localSpace:Bool=False )
-
- If localSpace LocalPosition=position Else Position=position
- End
-
- Method SetPosition( x:Float,y:Float,z:Float,localSpace:Bool=False )
-
- SetPosition( New Vec3f( x,y,z ),localSpace )
- End
-
- #rem monkeydoc Gets entity position in local or world space.
- #end
- Method GetPosition:Vec3f( localSpace:Bool=False )
-
- Return localSpace ? LocalPosition Else Position
- End
-
- #rem monkeydoc Sets entity basis matrix in local or world space.
- #end
- Method SetBasis( basis:Mat3f,localSpace:Bool=False )
-
- If localSpace LocalBasis=basis Else Basis=basis
- End
-
- #rem monkeydoc Gets entity basis matrix in local or world space.
- #end
- method GetBasis:Mat3f( localSpace:Bool=False )
-
- Return localSpace ? LocalBasis Else Basis
-
- End
- #rem monkeydoc Sets entity rotation in euler angles in local or world space.
- #end
- Method SetRotation( rotation:Vec3f,localSpace:Bool=False )
-
- Local basis:=Mat3f.Rotation( rotation * DegreesToRadians )
-
- If localSpace LocalBasis=basis Else Basis=basis
- End
-
- Method SetRotation( rx:Float,ry:Float,rz:Float,localSpace:Bool=False )
-
- SetRotation( New Vec3f( rx,ry,rz ),localSpace )
- End
-
- #rem monkeydoc Gets entity rotation in euler angles in local or world space.
- #end
- Method GetRotation:Vec3f( localSpace:Bool=False )
-
- Local basis:=localSpace ? LocalBasis Else Basis
-
- Return basis.GetRotation() * RadiansToDegrees
- End
-
- #rem monkeydoc Sets entity scale in local or world space.
- #end
- Method SetScale( scale:Vec3f,localSpace:Bool=False )
-
- If localSpace LocalScale=scale Else Scale=scale
- End
-
- Method SetScale( sx:Float,sy:Float,sz:Float,localSpace:Bool=False )
-
- SetScale( New Vec3f( sx,sy,sz ),localSpace )
- End
- #rem monkeydoc Gets entity scale in local or world space.
- #end
- Method GetScale:Vec3f( localSpace:Bool=False )
-
- Return localSpace ? LocalScale Else Scale
- End
-
- #rem monkeydoc Moves the entity.
-
- Moves the entity relative to its current orientation.
-
- #end
- Method Move( tv:Vec3f,localSpace:Bool=False )
-
- If localSpace LocalPosition+=tv Else Position+=Basis * tv
- End
-
- Method Move( tx:Float,ty:Float,tz:Float )
-
- Move( New Vec3f( tx,ty,tz ) )
- End
-
- #rem monkeydoc Moves the entity on the X axis.
-
- Moves the entity relative to its current orientation.
-
- #end
- Method MoveX( tx:Float,localSpace:Bool=False )
-
- If localSpace LocalX+=tx Else Position+=Basis.i * tx
- End
-
- #rem monkeydoc Moves the entity on the Y axis.
-
- Moves the entity relative to its current orientation.
-
- #end
- Method MoveY( ty:Float,localSpace:Bool=False )
- If localSpace LocalY+=ty Else Position+=Basis.j * ty
- End
-
- #rem monkeydoc Moves the entity on the Z axis.
-
- Moves the entity relative to its current orientation.
-
- #end
- Method MoveZ( tz:Float,localSpace:Bool=False )
- If localSpace LocalZ+=tz Else Position+=Basis.k * tz
- End
-
- #rem monkeydoc Rotates the entity.
-
- Rotates the entity.
-
- If `localSpace` is false, the rotation is applied after the entity's world rotation.
-
- If `localSpace` is true, the rotation is applied before the entity's local rotation.
-
- #end
- Method Rotate( rv:Vec3f,localSpace:Bool=False )
-
- Local basis:=Mat3f.Rotation( rv * DegreesToRadians )
-
- If localSpace LocalBasis*=basis Else Basis=basis*Basis
- End
-
- Method Rotate( rx:Float,ry:Float,rz:Float,localSpace:Bool=False )
-
- Rotate( New Vec3f( rx,ry,rz ),localSpace )
- End
-
- #rem monkeydoc Rotates the entity around the X axis.
- #end
- Method RotateX( rx:Float,localSpace:Bool=False )
-
- Local basis:=Mat3f.Pitch( rx * DegreesToRadians )
-
- If localSpace LocalBasis=basis*LocalBasis Else Basis*=basis
- End
- #rem monkeydoc Rotates the entity around the Y axis.
- #end
- Method RotateY( ry:Float,localSpace:Bool=False )
- Local basis:=Mat3f.Yaw( ry * DegreesToRadians )
-
- If localSpace LocalBasis=basis*LocalBasis Else Basis*=basis
- End
- #rem monkeydoc Rotates the entity around the Z axis.
- #end
- Method RotateZ( rz:Float,localSpace:Bool=False )
- Local basis:=Mat3f.Roll( rz * DegreesToRadians )
-
- If localSpace LocalBasis=basis*LocalBasis Else Basis*=basis
- End
- #rem monkeydoc Points the entity at a target.
- #end
- Method PointAt( target:Vec3f,up:Vec3f=New Vec3f( 0,1,0 ) )
-
- Local k:=(target-Position).Normalize()
-
- Local i:=up.Cross( k ).Normalize()
-
- Local j:=k.Cross( i )
-
- Basis=New Mat3f( i,j,k )
- End
-
- Method PointAt( target:Entity,up:Vec3f=New Vec3f( 0,1,0 ) )
-
- PointAt( target.LocalPosition )
- End
-
-
- End
|