void PickBody() { DropBody(); PickedEntity = RayCastEntity(out Vector3 PickPoint, out Vector3 Normal); if (PickedEntity != null) { DbgDraw.DrawLine(FireOrigin, PickPoint, Time: 5000); DbgDraw.DrawCircle(PickPoint + Normal * 0.1f, Normal, FishGfx.Color.Red, 5, 8, Time: 5000); PickDist = Vector3.Distance(FireOrigin, PickPoint); GlobalPickPoint = PickPoint; Matrix4x4.Invert(PickedEntity.RigidBody.CenterOfMassTransform, out Matrix4x4 InvCenterOfMass); LocalPickPoint = PickPoint = Vector3.Transform(PickPoint, InvCenterOfMass); PickedEntity.Unfreeze(); PickedEntity.DisableSleep(); PointConst = new Point2PointConstraint(PickedEntity.RigidBody, PickPoint); PointConst.Setting.ImpulseClamp = 10000; PointConst.Setting.Tau = 0.01f; PointConst.Setting.Damping = 0.99f; Map.World.AddConstraint(PointConst); OldAngularDamping = PickedEntity.RigidBody.AngularDamping; OldLinearDamping = PickedEntity.RigidBody.LinearDamping; PickedEntity.RigidBody.SetDamping(OldLinearDamping, 0.99f); IsPickingBody = true; } }
public override void Reload(bool Pressed) { if (Pressed) { EntPhysics Ent = RayCastEntity(out Vector3 PickPoint); if (Ent != null) { Ent.Unfreeze(); } /*Vector3[] Pts = Engine.Camera3D.GetFrustumPoints(); * * // Connecting lines * Vector3 A = DrawRay(Pts[0], Pts[4]); * Vector3 B = DrawRay(Pts[1], Pts[5]); * Vector3 C = DrawRay(Pts[2], Pts[6]); * Vector3 D = DrawRay(Pts[3], Pts[7]); * * DbgDraw.DrawLine(A, B, FishGfx.Color.Red, Time: 30000); * DbgDraw.DrawLine(B, C, FishGfx.Color.Red, Time: 30000); * DbgDraw.DrawLine(C, D, FishGfx.Color.Red, Time: 30000); * DbgDraw.DrawLine(D, A, FishGfx.Color.Red, Time: 30000);*/ } }
public override void SecondaryFire(bool Pressed) { if (Pressed && IsPickingBody) { EntPhysics FreezeEntity = PickedEntity; DropBody(); FreezeEntity.Freeze(); } }
void DropBody() { if (!IsPickingBody) { return; } Map.World.RemoveConstraint(PointConst); PointConst.Dispose(); PointConst = null; PickedEntity.Unfreeze(); PickedEntity.RigidBody.SetDamping(OldLinearDamping, OldAngularDamping); PickedEntity = null; IsPickingBody = false; }
public override void Reload(bool Pressed) { if (Pressed) { EntPhysics Ent = RayCastEntity(out Vector3 PickPoint); if (Ent != null) { Ent.Unfreeze(); } //DbgDraw.DrawFrustum(Engine.Camera3D, Time: 10000); //DbgDraw.DrawFrustum(Engine.Map.GetEntities<Player>().First().ViewModelCamera, Time: 10000); Vector3[] Pts = Engine.Camera3D.GetFrustumPoints(); /*// Near * DbgDraw.DrawLine(Pts[0], Pts[1], Time: 10000); * DbgDraw.DrawLine(Pts[1], Pts[2], Time: 10000); * DbgDraw.DrawLine(Pts[2], Pts[3], Time: 10000); * DbgDraw.DrawLine(Pts[3], Pts[0], Time: 10000); * * // Far * DbgDraw.DrawLine(Pts[4], Pts[5], Time: 10000); * DbgDraw.DrawLine(Pts[5], Pts[6], Time: 10000); * DbgDraw.DrawLine(Pts[6], Pts[7], Time: 10000); * DbgDraw.DrawLine(Pts[7], Pts[4], Time: 10000);*/ // Connecting lines Vector3 A = DrawRay(Pts[0], Pts[4]); Vector3 B = DrawRay(Pts[1], Pts[5]); Vector3 C = DrawRay(Pts[2], Pts[6]); Vector3 D = DrawRay(Pts[3], Pts[7]); DbgDraw.DrawLine(A, B, FishGfx.Color.Red, Time: 30000); DbgDraw.DrawLine(B, C, FishGfx.Color.Red, Time: 30000); DbgDraw.DrawLine(C, D, FishGfx.Color.Red, Time: 30000); DbgDraw.DrawLine(D, A, FishGfx.Color.Red, Time: 30000); } }
public void InitPhysics() { CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.SolverInfo.SolverMode |= SolverModes.Use2FrictionDirections | SolverModes.RandomizeOrder; World.SolverInfo.NumIterations = 20; World.DispatchInfo.AllowedCcdPenetration = 0.0001f; World.DispatchInfo.UseContinuous = true; World.Gravity = new Vector3(0, -600, 0); ClosestConvexResult = new ClosestConvexResultCallback(); EntPhysics MapPhysics = new EntPhysics(libTechCollisionShape.FromVerticesConcave(GetModels().First().GetMeshes().SelectMany(M => M.GetVertices().Select(V => V.Position))), 0); SpawnEntity(MapPhysics); }
public override void Load() { CrosshairTex = Engine.Load <Texture>("/content/textures/gui/crosshair_default.png"); UtilityGun UtilGun = new UtilityGun(); Console.WriteLine("Loading map"); Engine.Map = BSPMap.LoadMap("/content/maps/lt_test.bsp"); Engine.Map.InitPhysics(); Console.WriteLine("Done!"); PlayerSpawn[] SpawnPositions = Engine.Map.GetEntities <PlayerSpawn>().ToArray(); PlayerEnt = new Player(); PlayerEnt.SetPosition((PlySpawnPos = SpawnPositions.Random().SpawnPosition) + new Vector3(0, 100, 0)); PlayerEnt.Camera.LookAt(Vector3.Zero); PlayerEnt.SetPosition(new Vector3(-285.1535f, -964.8776f, 229.2883f)); Engine.Map.SpawnEntity(UtilGun); Engine.Map.SpawnEntity(PlayerEnt); PlayerEnt.WeaponPickUp(UtilGun); /*foreach (var L in Engine.Map.GetLights()) * Engine.Map.RemoveEntity(L);*/ LightEmitter = Engine.Map.GetEntities <EntPhysics>().Skip(5).First(); Light = new DynamicLight(Vector3.Zero, Color.Red); Engine.Map.SpawnEntity(Light); EntStatic TestEntity = new EntStatic(new libTechModel(Obj.Load("content/models/cube.obj"), Engine.GetMaterial(FogMaterial.Name))); TestEntity.Model.Scale = new Vector3(120); // 20 //DragonEnt.Model.Position = new Vector3(0, -1120, 0); TestEntity.Model.Position = new Vector3(0, -1000, 0); Engine.Map.SpawnEntity(TestEntity); /* * EntStatic TestEntity2 = new EntStatic(new libTechModel(TestEntity.Model)); * TestEntity2.Model.Position = new Vector3(240, -1000, 0); * Engine.Map.SpawnEntity(TestEntity2); * //*/ PlayerEnt.Camera.LookAt(TestEntity.Position); Engine.Camera3D.MouseMovement = true; Engine.Window.CaptureCursor = true; Engine.Window.OnMouseMoveDelta += (Wnd, X, Y) => { PlayerEnt.MouseMove(new Vector2(-X, -Y)); }; Engine.Window.OnKey += (Wnd, Key, Scancode, Pressed, Repeat, Mods) => { PlayerEnt.OnKey(Key, Pressed, Mods); if (Key == Key.Escape && Pressed) { Engine.Exit(); } if (Key == Key.F5 && Pressed) { RenderDoc.CaptureFrame(); } if (Key == Key.F6 && Pressed) { if (!Debugger.IsAttached) { Debugger.Launch(); } } }; }