protected override void OnRender( Camera camera )
{
base.OnRender( camera );
//no update in cubemap generation mode
if( Map.Instance.CubemapGenerationMode )
return;
bool playerIntellectFPSCamera = false;
{
PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
if( playerIntellect != null )
playerIntellectFPSCamera = playerIntellect.FPSCamera;
}
bool fpsCamera = playerIntellectFPSCamera && RendererWorld.Instance.DefaultCamera == camera;
if( activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade )
{
//FPS mesh material
activeWeapon.FPSMeshMaterialNameEnabled =
fpsCamera && !camera.IsForShadowMapGeneration();
//update weapon vertical orientation
if( activeWeaponAttachedObject.MapObject is Gun )
{
//for guns
if( fpsCamera )
{
Vec3 p = camera.Position + camera.Rotation * Type.WeaponFPSAttachPosition;
Quat r = camera.Rotation;
Vec3 s = new Vec3( 1, 1, 1 );
activeWeaponAttachedObject.MapObject.SetTransform( p, r, s );
activeWeaponAttachedObject.MapObject.SetOldTransform( p, r, s );
//Vec3 diff = playerIntellect.LookDirection.GetVector();
//float dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() );
//float halfDirV = dirV * .5f;
//Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0,
// MathFunctions.Cos( halfDirV ) );
//activeWeaponAttachedObject.RotationOffset = rot;
//activeWeaponAttachedObject.PositionOffset =
// Type.FPSCameraOffset + Type.WeaponFPSAttachPosition * rot;
}
else
{
float dirV;
if( EntitySystemWorld.Instance.IsClientOnly() )
{
//client specific
dirV = client_weaponVerticalAngle;
}
else
{
Vec3 diff = TurnToPosition - Position;
dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() );
}
float halfDirV = dirV * .5f;
Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0,
MathFunctions.Cos( halfDirV ) );
activeWeaponAttachedObject.RotationOffset = rot;
activeWeaponAttachedObject.PositionOffset = Type.WeaponAttachPosition;
}
}
else
{
//for melee weapons
activeWeaponAttachedObject.RotationOffset = Quat.Identity;
activeWeaponAttachedObject.PositionOffset = Vec3.Zero;
}
//no cast shadows from active weapon in the FPS mode
foreach( MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects )
{
MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh;
if( weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null )
{
if( weaponAttachedMesh.RemainingTime == 0 )
weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera;
}
}
}
//only weapon visible in the FPS mode
foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
attachedObject.Visible = !fpsCamera || attachedObject == activeWeaponAttachedObject;
//no cast shadows in the FPS mode
if( camera.IsForShadowMapGeneration() && playerIntellectFPSCamera )
{
foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
attachedObject.Visible = false;
}
}