public SetDirection ( Vector3 vec, TransformSpace relativeTo, Vector3 localDirection ) : void | ||
vec | Vector3 | The direction vector. |
relativeTo | TransformSpace | The space in which this direction vector is expressed. |
localDirection | Vector3 | The vector which normally describes the natural direction /// of the node, usually -Z. /// |
return | void |
public void SetDirection( Vector3 vec, TransformSpace relativeTo, Vector3 localDirection )
{
// Do nothing if given a zero vector
if ( vec == Vector3.Zero )
{
return;
}
// Adjust vector so that it is relative to local Z
Vector3 zAdjustVec;
if ( localDirection == Vector3.NegativeUnitZ )
{
zAdjustVec = -vec;
}
else
{
Quaternion localToUnitZ = localDirection.GetRotationTo( Vector3.UnitZ );
zAdjustVec = localToUnitZ * vec;
}
zAdjustVec.Normalize();
Quaternion targetOrientation;
if ( isYawFixed )
{
Vector3 xVec = yawFixedAxis.Cross( zAdjustVec );
xVec.Normalize();
Vector3 yVec = zAdjustVec.Cross( xVec );
yVec.Normalize();
targetOrientation = Quaternion.FromAxes( xVec, yVec, zAdjustVec );
}
else
{
Vector3 xAxis, yAxis, zAxis;
// Get axes from current quaternion
// get the vector components of the derived orientation vector
this.DerivedOrientation.ToAxes( out xAxis, out yAxis, out zAxis );
Quaternion rotationQuat;
if ( ( zAxis + zAdjustVec ).LengthSquared < 0.00000001f )
{
// Oops, a 180 degree turn (infinite possible rotation axes)
// Default to yaw i.e. use current UP
rotationQuat = Quaternion.FromAngleAxis( Utility.PI, yAxis );
}
else
{
// Derive shortest arc to new direction
rotationQuat = zAxis.GetRotationTo( zAdjustVec );
}
targetOrientation = rotationQuat * orientation;
}
if ( relativeTo == TransformSpace.Local || parent != null )
{
orientation = targetOrientation;
}
else
{
if ( relativeTo == TransformSpace.Parent )
{
orientation = targetOrientation * parent.Orientation.Inverse();
}
else if ( relativeTo == TransformSpace.World )
{
orientation = targetOrientation * parent.DerivedOrientation.Inverse();
}
}
}
SceneNode::SetDirection ( Real x, Real y, Real z ) : void | |
SceneNode::SetDirection ( Real x, Real y, Real z, TransformSpace relativeTo ) : void | |
SceneNode::SetDirection ( Real x, Real y, Real z, TransformSpace relativeTo, Vector3 localDirectionVector ) : void | |
SceneNode::SetDirection ( Vector3 vec ) : void | |
SceneNode::SetDirection ( Vector3 vec, TransformSpace relativeTo ) : void |
public MultiLights(SceneManager pSceneManager, SceneNode pCamNode, MovingObject pPlayerShip, Int32 pNumberOfLights) { oldCamLightColor = CamLightColor = new ColorEx(0.13f, 0.1f, 0.05f); PlayerLightColor = ColorEx.White; camLights = new List<Light>(pNumberOfLights); innerLights = (Int32)Math.Round(pNumberOfLights / 3.0f, MidpointRounding.AwayFromZero); outerLights = pNumberOfLights - innerLights; // create the playership's light. playerLight = pSceneManager.CreateLight("playerSpotLight"); playerLight.Type = LightType.Spotlight; playerLight.Diffuse = PlayerLightColor; playerLight.Specular = ColorEx.White; playerLight.SetSpotlightRange(0.0f, 120.0f); playerLight.Direction = Vector3.NegativeUnitZ; playerLightNode = pPlayerShip.Node.CreateChildSceneNode(); playerLightNode.AttachObject(playerLight); playerLightNode.Position = new Vector3(0, 0, 0); playerLightNode.SetDirection(new Vector3(1, 0, 0), TransformSpace.Local); // create the camera spotlights around the camera's direction. camInnerLightNode = pCamNode.CreateChildSceneNode(); camInnerLightNode.Position = new Vector3(0, 0, 0); camOuterLightNode = pCamNode.CreateChildSceneNode(); camOuterLightNode.Position = new Vector3(0, 0, 0); for (var i = 0; i < innerLights; i++) { var light = pSceneManager.CreateLight("camInnerLight " + (i + 1)); light.Type = LightType.Spotlight; light.Diffuse = CamLightColor; light.Specular = ColorEx.White; light.SetSpotlightRange(0.0f, 25.0f); light.Direction = Quaternion.FromAngleAxis(360.0 * i / innerLights * Constants.DegreesToRadians, Vector3.UnitZ) * Quaternion.FromAngleAxis(10.0 * Constants.DegreesToRadians, Vector3.UnitX) * Vector3.NegativeUnitZ; camLights.Add(light); camInnerLightNode.AttachObject(light); } for (var i = 0; i < outerLights; i++) { var light = pSceneManager.CreateLight("camOuterLight " + (i + 1)); light.Type = LightType.Spotlight; light.Diffuse = CamLightColor; light.Specular = ColorEx.White; light.SetSpotlightRange(0.0f, 25.0f); light.Direction = Quaternion.FromAngleAxis(360.0 * i / outerLights * Constants.DegreesToRadians, Vector3.UnitZ) * Quaternion.FromAngleAxis(20.0 * Constants.DegreesToRadians, Vector3.UnitX) * Vector3.NegativeUnitZ; camLights.Add(light); camOuterLightNode.AttachObject(light); } }