public void UpdateLightPosition() { if (m_light != null) { MyCharacter character = m_skinnedEntity as MyCharacter; m_lightLocalPosition = character.Definition.LightOffset; MatrixD headMatrix = character.GetHeadMatrix(false, true, false); MatrixD headMatrixAnim = character.GetHeadMatrix(false, true, true, true); if (m_oldReflectorAngle != MyCharacter.REFLECTOR_DIRECTION) { m_oldReflectorAngle = MyCharacter.REFLECTOR_DIRECTION; m_reflectorAngleMatrix = MatrixD.CreateFromAxisAngle(headMatrix.Forward, MathHelper.ToRadians(MyCharacter.REFLECTOR_DIRECTION)); } m_light.ReflectorDirection = Vector3.Transform(headMatrix.Forward, m_reflectorAngleMatrix); m_light.ReflectorUp = headMatrix.Up; m_light.ReflectorTexture = "Textures\\Lights\\dual_reflector_2.dds"; m_light.ReflectorColor = MyCharacter.REFLECTOR_COLOR; m_light.UpdateReflectorRangeAndAngle(MyCharacter.REFLECTOR_CONE_ANGLE, MyCharacter.REFLECTOR_RANGE); m_light.Position = Vector3D.Transform(m_lightLocalPosition, headMatrixAnim); m_light.UpdateLight(); Matrix[] boneMatrices = character.BoneAbsoluteTransforms; if (m_leftGlare != null) { MatrixD leftGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_leftLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_leftGlare.Position = leftGlareMatrix.Translation; m_leftGlare.Range = 1; m_leftGlare.ReflectorDirection = -leftGlareMatrix.Up;//, m_reflectorAngleMatrix); m_leftGlare.ReflectorUp = leftGlareMatrix.Forward; m_leftGlare.GlareIntensity = m_light.Intensity; m_leftGlare.GlareSize = m_lightGlareSize; m_leftGlare.GlareQuerySize = 0.1f; m_leftGlare.GlareMaxDistance = MyCharacter.LIGHT_GLARE_MAX_DISTANCE; m_leftGlare.UpdateLight(); } if (m_rightGlare != null) { MatrixD rightGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_rightLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_rightGlare.Position = rightGlareMatrix.Translation; m_rightGlare.Range = 1; m_rightGlare.ReflectorDirection = -rightGlareMatrix.Up; m_rightGlare.ReflectorUp = rightGlareMatrix.Forward; m_rightGlare.GlareIntensity = m_light.Intensity; m_rightGlare.GlareSize = m_lightGlareSize; m_rightGlare.GlareQuerySize = 0.1f; m_rightGlare.GlareMaxDistance = MyCharacter.LIGHT_GLARE_MAX_DISTANCE; m_rightGlare.UpdateLight(); } } }
public void UpdatePositionAndOrientation() { MyCharacter character = Entity as MyCharacter; if (character == null || character.Physics == null || !character.Physics.IsInWorld) { return; } if (!IsInWorld && character.Physics.IsInWorld) { Enabled = true; Activate(); } if (IsInWorld) { MatrixD headWorldMatrix = character.GetHeadMatrix(false, forceHeadBone: true); Matrix rigidBodyMatrix = GetRigidBodyMatrix(headWorldMatrix); if (RigidBody != null) { RigidBody.SetWorldMatrix(rigidBodyMatrix); } if (RigidBody2 != null) { RigidBody2.SetWorldMatrix(rigidBodyMatrix); } } }
private bool PlayersLookingFaceToFace(MyCharacter firstCharacter, MyCharacter secondCharacter) { // Angle between head direction vectors between 120 and 240 angles. var firstHeadVector = firstCharacter.GetHeadMatrix(false).Forward; var secondHeadVector = secondCharacter.GetHeadMatrix(false).Forward; double dot; Vector3D.Dot(ref firstHeadVector, ref secondHeadVector, out dot); return(dot < -0.5); }
public void UpdateSensorPosition() { if (Owner != null) { Debug.Assert(Owner != null && Owner is MyCharacter, "An engineer tool is not held by a character"); MyCharacter character = Owner as MyCharacter; MatrixD sensorWorldMatrix = character.GetHeadMatrix(false, true); m_raycastComponent.OnWorldPosChanged(ref sensorWorldMatrix); } }
public void UpdateLightPosition() { if (m_light != null) { MyCharacter character = m_skinnedEntity as MyCharacter; m_lightLocalPosition = character.Definition.LightOffset; MatrixD headMatrix = character.GetHeadMatrix(false, true, false); MatrixD headMatrixAnim = character.GetHeadMatrix(false, true, true, true); if (m_oldReflectorAngle != MyCharacter.REFLECTOR_DIRECTION) { m_oldReflectorAngle = MyCharacter.REFLECTOR_DIRECTION; m_reflectorAngleMatrix = MatrixD.CreateFromAxisAngle(headMatrix.Forward, MathHelper.ToRadians(MyCharacter.REFLECTOR_DIRECTION)); } m_light.ReflectorDirection = Vector3.Transform(headMatrix.Forward, m_reflectorAngleMatrix); m_light.ReflectorUp = headMatrix.Up; m_light.Position = Vector3D.Transform(m_lightLocalPosition, headMatrixAnim); m_light.UpdateLight(); Matrix[] boneMatrices = character.BoneAbsoluteTransforms; if (m_leftLightIndex != -1) { MatrixD leftGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_leftLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_leftGlarePosition = leftGlareMatrix.Translation; } if (m_rightLightIndex != -1) { MatrixD rightGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_rightLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_rightGlarePosition = rightGlareMatrix.Translation; } } }
private void AffectAddBySurvival(ref MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder) { Debug.Assert(Sync.IsServer); MyFixedPoint space = ComputeAmountThatFits(objectBuilder.GetObjectId()); if (space < amount) { if (Owner != null && Owner.InventoryOwnerType == MyInventoryOwnerTypeEnum.Character) { MyCharacter c = (Owner as MyCharacter); Matrix m = c.GetHeadMatrix(true); MyEntity entity = MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount - space, objectBuilder), m.Translation, m.Forward, m.Up, c.Physics); entity.Physics.ApplyImpulse(m.Forward.Cross(m.Up), c.PositionComp.GetPosition()); } amount = space; } }
private void UpdateMatrices() { if (!(this.m_entity is MyCharacter)) { this.m_worldMatrix = this.m_entity.PositionComp.WorldMatrix; this.m_invWorldMatrix = this.m_entity.PositionComp.WorldMatrixInvScaled; this.m_aimingPositionAndOrientation = this.m_worldMatrix; this.m_invAimingPositionAndOrientation = this.m_invWorldMatrix; } else { MyCharacter entity = this.m_entity as MyCharacter; this.m_worldMatrix = entity.WorldMatrix; this.m_invWorldMatrix = Matrix.Invert((Matrix)this.m_worldMatrix); this.m_aimingPositionAndOrientation = entity.GetHeadMatrix(true, true, false, true, false); this.m_invAimingPositionAndOrientation = MatrixD.Invert(this.m_aimingPositionAndOrientation); } }
public void DebugDraw() { if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW) { this.m_aiming.DebugDraw(this.m_aimingPositionAndOrientation); if (MyDebugDrawSettings.DEBUG_DRAW_BOT_STEERING) { foreach (MySteeringBase local1 in this.m_steerings) { } } if (MyDebugDrawSettings.DEBUG_DRAW_BOT_NAVIGATION) { Vector3 translation = (Vector3)this.PositionAndOrientation.Translation; Vector3.Cross(this.m_forwardVector, this.UpVector); if (this.Stuck) { MyRenderProxy.DebugDrawSphere(translation, 1f, Color.Red.ToVector3(), 1f, false, false, true, false); } MyRenderProxy.DebugDrawArrow3D(translation, translation + this.ForwardVector, Color.Blue, new Color?(Color.Blue), false, 0.1, "Nav. FW", 0.5f, false); MyRenderProxy.DebugDrawArrow3D(translation + this.ForwardVector, (translation + this.ForwardVector) + this.m_correction, Color.LightBlue, new Color?(Color.LightBlue), false, 0.1, "Correction", 0.5f, false); if (this.m_destinationSphere != null) { this.m_destinationSphere.DebugDraw(); } MyCharacter botEntity = this.BotEntity as MyCharacter; if (botEntity != null) { MatrixD matrix = MatrixD.Invert(botEntity.GetViewMatrix()); MatrixD xd3 = botEntity.GetHeadMatrix(true, true, false, false, false); MyRenderProxy.DebugDrawLine3D(matrix.Translation, Vector3D.Transform(Vector3D.Forward * 50.0, matrix), Color.Yellow, Color.White, false, false); MyRenderProxy.DebugDrawLine3D(xd3.Translation, Vector3D.Transform(Vector3D.Forward * 50.0, xd3), Color.Red, Color.Red, false, false); if (botEntity.CurrentWeapon != null) { Vector3 vector2 = botEntity.CurrentWeapon.DirectionToTarget(botEntity.AimedPoint); MyRenderProxy.DebugDrawSphere(botEntity.AimedPoint, 1f, Color.Yellow, 1f, false, false, true, false); Vector3D pointFrom = (botEntity.CurrentWeapon as MyEntity).WorldMatrix.Translation; MyRenderProxy.DebugDrawLine3D(pointFrom, (botEntity.CurrentWeapon as MyEntity).WorldMatrix.Translation + (vector2 * 20f), Color.Purple, Color.Purple, false, false); } } } } }
public void UpdateSensorPosition() { if (Owner != null) { Debug.Assert(Owner != null && Owner is MyCharacter, "An engineer tool is not held by a character"); MyCharacter character = Owner as MyCharacter; MatrixD sensorWorldMatrix = MatrixD.Identity; if (character.ControllerInfo.IsLocallyControlled()) { sensorWorldMatrix = character.GetHeadMatrix(false, true); character.SyncHeadToolTransform(ref sensorWorldMatrix); } else { sensorWorldMatrix = character.GetSyncedToolTransform(); } m_raycastComponent.OnWorldPosChanged(ref sensorWorldMatrix); } }
private static bool SetContainerType() { MyCharacter character = MySession.LocalCharacter; if (character == null) { return(false); } Matrix headMatrix = character.GetHeadMatrix(true); List <MyPhysics.HitInfo> hits = new List <MyPhysics.HitInfo>(); Sandbox.Engine.Physics.MyPhysics.CastRay(headMatrix.Translation, headMatrix.Translation + headMatrix.Forward * 100.0f, hits); if (hits.Count() == 0) { return(false); } var hit = hits.FirstOrDefault(); if (hit.HkHitInfo.Body == null) { return(false); } IMyEntity entity = hit.HkHitInfo.GetHitEntity(); if (!(entity is MyCargoContainer)) { return(false); } var dialog = new MyGuiScreenDialogContainerType(entity as MyCargoContainer); MyGuiSandbox.AddScreen(dialog); return(true); }
public void UpdateLightPosition() { if (this.m_light != null) { MyCharacter skinnedEntity = base.m_skinnedEntity as MyCharacter; this.m_lightLocalPosition = skinnedEntity.Definition.LightOffset; MatrixD matrix = skinnedEntity.GetHeadMatrix(false, true, false, true, false); this.m_light.ReflectorDirection = (Vector3)matrix.Forward; this.m_light.ReflectorUp = (Vector3)matrix.Right; this.m_light.Position = Vector3D.Transform(this.m_lightLocalPosition, matrix); this.m_light.UpdateLight(); Matrix[] boneAbsoluteTransforms = skinnedEntity.BoneAbsoluteTransforms; if (this.m_leftLightIndex != -1) { MatrixD xd2 = MatrixD.Normalize(boneAbsoluteTransforms[this.m_leftLightIndex]) * base.m_skinnedEntity.PositionComp.WorldMatrix; this.m_leftGlarePosition = xd2.Translation; } if (this.m_rightLightIndex != -1) { MatrixD xd3 = MatrixD.Normalize(boneAbsoluteTransforms[this.m_rightLightIndex]) * base.m_skinnedEntity.PositionComp.WorldMatrix; this.m_rightGlarePosition = xd3.Translation; } } }
public override void Draw() { base.Draw(); UpdateCharacterSkeleton(); VRageRender.MyRenderProxy.SetCharacterTransforms(RenderObjectIDs[0], m_character.BoneRelativeTransforms); Matrix headMatrix = m_character.GetHeadMatrix(false); Vector3 position = m_light.Position; Vector3 forwardVector = m_light.ReflectorDirection; Vector3 leftVector = headMatrix.Left; Vector3 upVector = headMatrix.Up; float reflectorLength = MyCharacter.REFLECTOR_BILLBOARD_LENGTH * 0.4f * 0.16f; float reflectorThickness = MyCharacter.REFLECTOR_BILLBOARD_THICKNESS * 0.08f; //float reflectorRadiusForAdditive = 0.25f;//0.65f; Vector3 color = new Vector3(m_light.ReflectorColor); Vector3 glarePosition = position + forwardVector * 0.28f; var dot = Vector3.Dot(Vector3.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector); float angle = 1 - Math.Abs(dot); float alphaGlareAlphaBlended = (float)Math.Pow(1 - angle, 2); float alphaGlareAdditive = (float)Math.Pow(1 - angle, 2); float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f; float reflectorRadiusForAlphaBlended = MathHelper.Lerp(0.1f, 0.5f, alphaGlareAlphaBlended); //3.5f; // Multiply alpha by reflector level (and not the color), because if we multiply the color and let alpha unchanged, reflector cune will be drawn as very dark cone, but still visible var reflectorLevel = m_character.CurrentLightPower; m_light.ReflectorIntensity = reflectorLevel; alphaCone *= reflectorLevel * 0.2f; alphaGlareAlphaBlended *= reflectorLevel * 0.1f; alphaGlareAdditive *= reflectorLevel * 0.8f; float distance = Vector3.Distance(m_character.PositionComp.GetPosition(), MySector.MainCamera.Position); if (!m_character.IsInFirstPersonView && distance < MyCharacter.LIGHT_GLARE_MAX_DISTANCE && reflectorLevel > 0) { float alpha = MathHelper.Clamp((MyCharacter.LIGHT_GLARE_MAX_DISTANCE - 10.0f) / distance, 0, 1); if (reflectorLength > 0 && reflectorThickness > 0) { if (m_leftGlare != null) { MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha, m_leftGlare.Position, m_leftGlare.ReflectorDirection, reflectorLength, reflectorThickness); } if (m_rightGlare != null) { MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha, m_rightGlare.Position, m_rightGlare.ReflectorDirection, reflectorLength, reflectorThickness); } } if (m_leftGlare != null) { MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha, m_leftGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0); } if (m_rightGlare != null) { MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha, m_rightGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0); } } DrawJetpackThrusts(m_character.UpdateCalled()); if (m_character.Hierarchy.Parent != null) { if (m_leftGlare != null && m_leftGlare.LightOn == true) { m_leftGlare.LightOn = false; m_leftGlare.GlareOn = false; m_leftGlare.UpdateLight(); } if (m_rightGlare != null && m_rightGlare.LightOn == true) { m_rightGlare.LightOn = false; m_rightGlare.GlareOn = false; m_rightGlare.UpdateLight(); } } else { if (m_leftGlare != null && m_leftGlare.LightOn == false) { m_leftGlare.LightOn = true; m_leftGlare.GlareOn = true; m_leftGlare.UpdateLight(); } if (m_rightGlare != null && m_rightGlare.LightOn == true) { m_rightGlare.LightOn = true; m_rightGlare.GlareOn = true; m_rightGlare.UpdateLight(); } } if (MySession.ControlledEntity == m_character) { if (m_character.IsDead && m_character.CurrentRespawnCounter > 0) { DrawBlood(1); } if (!m_character.IsDead && m_currentHitIndicatorCounter > 0) { m_currentHitIndicatorCounter -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; if (m_currentHitIndicatorCounter < 0) { m_currentHitIndicatorCounter = 0; } float alpha = m_currentHitIndicatorCounter / HIT_INDICATOR_LENGTH; DrawBlood(alpha); } if (m_character.StatComp != null) { var healthRatio = m_character.StatComp.HealthRatio; if (healthRatio <= MyCharacterStatComponent.LOW_HEALTH_RATIO && !m_character.IsDead) { float alpha = MathHelper.Clamp(MyCharacterStatComponent.LOW_HEALTH_RATIO - healthRatio, 0, 1) / MyCharacterStatComponent.LOW_HEALTH_RATIO + 0.3f; DrawBlood(alpha); } } } //DebugDraw(); }
public static ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> FindLookAtGridGroup(MyCharacter controlledEntity) { const float range = 5000; Matrix worldMatrix; Vector3D startPosition; Vector3D endPosition; worldMatrix = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT. startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f; endPosition = worldMatrix.Translation + worldMatrix.Forward * (range); var list = new Dictionary <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group, double>(); var ray = new RayD(startPosition, worldMatrix.Forward); foreach (var group in MyCubeGridGroups.Static.Physical.Groups) { foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid cubeGrid = groupNodes.NodeData; if (cubeGrid != null) { if (cubeGrid.MarkedForClose || cubeGrid.MarkedAsTrash || !cubeGrid.InScene) { continue; } // check if the ray comes anywhere near the Grid before continuing. if (ray.Intersects(cubeGrid.PositionComp.WorldAABB).HasValue) { Vector3I?hit = cubeGrid.RayCastBlocks(startPosition, endPosition); if (hit.HasValue) { double distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length(); if (list.TryGetValue(group, out double oldDistance)) { if (distance < oldDistance) { list.Remove(group); list.Add(group, distance); } } else { list.Add(group, distance); } } } } } } ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> bag = new ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group>(); if (list.Count == 0) { return(bag); } // find the closest Entity. var item = list.OrderBy(f => f.Value).First(); bag.Add(item.Key); return(bag); }