void SetPathPoint(bool spawning) { if (Raycast(250.0f, out var hitPos, out _)) { var navMesh = scene.GetComponent <DynamicNavigationMesh>(); var pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f)); var compatiblePos = new BEPUutilities.Vector2((Fix64)pathPos.X, (Fix64)pathPos.Z); if (spawning) { // Spawn a jack at the target position simulation.Execute(new SpawnCommand { Position = compatiblePos }); } else { // Set crowd agents target position simulation.Execute(new NavigateCommand { Destination = compatiblePos, Selection = Contexts.sharedInstance.game.GetEntities(GameMatcher.LocalId).Where(entity => entity.actorId.value == simulation.LocalActorId).Select(entity => entity.id.value).ToArray() }); } } }
/// <summary> /// Ticks the entity. /// </summary> public void Tick() { BEPUutilities.Vector2 motion = BEPUutilities.Vector2.Zero; if (KeyForward) { motion.Y += 1; } if (KeyBack) { motion.Y -= 1; } if (KeyRight) { motion.X += 1; } if (KeyLeft) { motion.X -= 1; } if (motion.LengthSquared() > 0) { motion.Normalize(); } PhysChar.ViewDirection = Engine3D.MainCamera.Direction.ToBVector(); PhysChar.HorizontalMotionConstraint.MovementDirection = motion; if (KeyJump) { PhysChar.Jump(); } Engine3D.MainCamera.Position = EyePos; }
public void AddPosition(BEPUutilities.Vector2 newValue) { var index = GameComponentsLookup.Position; var component = (Lockstep.Core.State.Game.PositionComponent)CreateComponent(index, typeof(Lockstep.Core.State.Game.PositionComponent)); component.value = newValue; AddComponent(index, component); }
public void ReplaceVelocity(BEPUutilities.Vector2 newValue) { var index = GameComponentsLookup.Velocity; var component = (Lockstep.Core.State.Game.VelocityComponent)CreateComponent(index, typeof(Lockstep.Core.State.Game.VelocityComponent)); component.value = newValue; ReplaceComponent(index, component); }
public void ReplaceCoordinate(BEPUutilities.Vector2 newValue) { var index = InputComponentsLookup.Coordinate; var component = (Lockstep.Core.Components.Input.CoordinateComponent)CreateComponent(index, typeof(Lockstep.Core.Components.Input.CoordinateComponent)); component.value = newValue; ReplaceComponent(index, component); }
public void ReplacePosition(BEPUutilities.Vector2 newValue) { var index = GameComponentsLookup.Position; var component = (PositionComponent)CreateComponent(index, typeof(PositionComponent)); component.value = newValue; ReplaceComponent(index, component); }
//Vector2 public static Vector2 Convert(BEPUutilities.Vector2 bepuVector) { Vector2 toReturn; toReturn.X = bepuVector.X; toReturn.Y = bepuVector.Y; return(toReturn); }
public void ReplaceDestination(BEPUutilities.Vector2 newValue) { var index = GameComponentsLookup.Destination; var component = (Lockstep.Core.Components.Game.DestinationComponent)CreateComponent(index, typeof(Lockstep.Core.Components.Game.DestinationComponent)); component.value = newValue; ReplaceComponent(index, component); }
public void ReplaceNavigationInputData(int[] newEntityIds, BEPUutilities.Vector2 newDestination) { var index = InputComponentsLookup.NavigationInputData; var component = (NavigationInputDataComponent)CreateComponent(index, typeof(NavigationInputDataComponent)); component.EntityIds = newEntityIds; component.Destination = newDestination; ReplaceComponent(index, component); }
public void ReplaceSpawnInputData(int newOwnerId, int newEntityConfigId, BEPUutilities.Vector2 newPosition) { var index = InputComponentsLookup.SpawnInputData; var component = (SpawnInputDataComponent)CreateComponent(index, typeof(SpawnInputDataComponent)); component.OwnerId = newOwnerId; component.EntityConfigId = newEntityConfigId; component.Position = newPosition; ReplaceComponent(index, component); }
public void ReplaceRvoAgentSettings(BEPUutilities.Vector2 newPreferredVelocity, FixMath.NET.Fix64 newTimeHorizonObst, System.Collections.Generic.IList <System.Collections.Generic.KeyValuePair <FixMath.NET.Fix64, uint> > newAgentNeighbors) { var index = GameComponentsLookup.RvoAgentSettings; var component = (Lockstep.Core.State.Game.RvoAgentSettingsComponent)CreateComponent(index, typeof(Lockstep.Core.State.Game.RvoAgentSettingsComponent)); component.preferredVelocity = newPreferredVelocity; component.timeHorizonObst = newTimeHorizonObst; component.agentNeighbors = newAgentNeighbors; ReplaceComponent(index, component); }
// SharpDX -> BepuPhysics public static Vector2 ToSharp(this BEPUutilities.Vector2 a) { return(new Vector2(a.X, a.Y)); }
public static Vector2 Convert(BEPUutilities.Vector2 a) { return(new Vector2(a.X, a.Y)); }
public static void Convert(ref BEPUutilities.Vector2 bepuVector, out Vector2 xnaVector) { xnaVector.X = bepuVector.X; xnaVector.Y = bepuVector.Y; }
public static void Convert(ref Vector2 xnaVector, out BEPUutilities.Vector2 bepuVector) { bepuVector.X = xnaVector.X; bepuVector.Y = xnaVector.Y; }
public static BEPUutilities.Vector2 TransformVec2(BEPUutilities.Vector2 vector, BEPUutilities.Matrix2x2 transform) { return(new BEPUutilities.Vector2(vector.X * transform.M11 + vector.Y * transform.M21, vector.X * transform.M12 + vector.Y * transform.M22)); }
public Model FromScene(Model3D scene, string name, AnimationEngine engine) { if (scene.Meshes.Count == 0) { throw new Exception("Scene has no meshes! (" + name + ")"); } Model model = new Model(name); model.Engine = this; model.Original = scene; model.Root = convert(scene.MatrixA); foreach (Model3DMesh mesh in scene.Meshes) { if (mesh.Name.ToLowerFast().Contains("collision") || mesh.Name.ToLowerFast().Contains("norender")) { continue; } ModelMesh modmesh = new ModelMesh(mesh.Name); modmesh.vbo.Prepare(); bool hastc = mesh.TexCoords.Count == mesh.Vertices.Count; bool hasn = mesh.Normals.Count == mesh.Vertices.Count; if (!hasn) { SysConsole.Output(OutputType.WARNING, "Mesh has no normals! (" + name + ")"); } if (!hastc) { SysConsole.Output(OutputType.WARNING, "Mesh has no texcoords! (" + name + ")"); } for (int i = 0; i < mesh.Vertices.Count; i++) { BEPUutilities.Vector3 vertex = mesh.Vertices[i]; modmesh.vbo.Vertices.Add(new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z)); if (!hastc) { modmesh.vbo.TexCoords.Add(new Vector3(0, 0, 0)); } else { BEPUutilities.Vector2 texCoord = mesh.TexCoords[i]; modmesh.vbo.TexCoords.Add(new Vector3((float)texCoord.X, 1 - (float)texCoord.Y, 0)); } if (!hasn) { modmesh.vbo.Normals.Add(new Vector3(0, 0, 1)); } else { modmesh.vbo.Normals.Add(new Vector3((float)mesh.Normals[i].X, (float)mesh.Normals[i].Y, (float)mesh.Normals[i].Z)); } modmesh.vbo.Colors.Add(new Vector4(1, 1, 1, 1)); // TODO: From the mesh? } for (int i = 0; i < mesh.Indices.Count; i++) { modmesh.vbo.Indices.Add((uint)mesh.Indices[i]); } int bc = mesh.Bones.Count; if (bc > 200) { SysConsole.Output(OutputType.WARNING, "Mesh has " + bc + " bones! (" + name + ")"); bc = 200; } modmesh.vbo.BoneIDs = new Vector4[modmesh.vbo.Vertices.Count].ToList(); modmesh.vbo.BoneWeights = new Vector4[modmesh.vbo.Vertices.Count].ToList(); modmesh.vbo.BoneIDs2 = new Vector4[modmesh.vbo.Vertices.Count].ToList(); modmesh.vbo.BoneWeights2 = new Vector4[modmesh.vbo.Vertices.Count].ToList(); int[] pos = new int[modmesh.vbo.Vertices.Count]; for (int i = 0; i < bc; i++) { for (int x = 0; x < mesh.Bones[i].Weights.Count; x++) { int IDa = mesh.Bones[i].IDs[x]; float Weighta = (float)mesh.Bones[i].Weights[x]; int spot = pos[IDa]++; if (spot > 7) { //SysConsole.Output(OutputType.WARNING, "Too many bones influencing " + vw.VertexID + "!"); ForceSet(modmesh.vbo.BoneWeights, IDa, 3, modmesh.vbo.BoneWeights[IDa][3] + Weighta); } else if (spot > 3) { ForceSet(modmesh.vbo.BoneIDs2, IDa, spot - 4, i); ForceSet(modmesh.vbo.BoneWeights2, IDa, spot - 4, Weighta); } else { ForceSet(modmesh.vbo.BoneIDs, IDa, spot, i); ForceSet(modmesh.vbo.BoneWeights, IDa, spot, Weighta); } } } model.Meshes.Add(modmesh); } model.RootNode = new ModelNode() { Parent = null, Name = scene.RootNode.Name.ToLowerFast() }; List <ModelNode> allNodes = new List <ModelNode>(); PopulateChildren(model.RootNode, scene.RootNode, model, engine, allNodes); for (int i = 0; i < model.Meshes.Count; i++) { for (int x = 0; x < scene.Meshes[i].Bones.Count; x++) { ModelNode nodet = null; string nl = scene.Meshes[i].Bones[x].Name.ToLowerFast(); for (int n = 0; n < allNodes.Count; n++) { if (allNodes[n].Name == nl) { nodet = allNodes[n]; break; } } ModelBone mb = new ModelBone() { Offset = convert(scene.Meshes[i].Bones[x].MatrixA) }; nodet.Bones.Add(mb); model.Meshes[i].Bones.Add(mb); } } return(model); }
public void OnPosition(GameEntity entity, Vector2 value) { Node.SetWorldPosition(new Vector3((float)value.X, 0, (float)value.Y)); }
// Steer away from obstacles in the way. This method returns a zero vector if no correction is required. // It should be high priority and the steering from other behaviors should blend into the remaining space. // So if this returns a length 1.0f vector, avoiding the obstacle is most urgent and there is no room for other // steering. private Vector2 AvoidObstacles(Actor owner) { BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); // Conditions where we do not want to use this steering force. if (GetAngleFromVertical(bcc.Controller.Body.LinearVelocity) < MathHelper.PiOver4 || // We're probably falling... !bcc.Controller.SupportFinder.HasSupport || !bcc.Controller.SupportFinder.HasTraction) { return(Vector2.Zero); } // Sphere cast ahead along facing. List <RayCastResult> obstacles = new List <RayCastResult>(); SphereShape probe = new SphereShape(bcc.Controller.BodyRadius * 1.1f); RigidTransform probeStartPosition = new RigidTransform(bcc.Controller.Body.Position); // Add a small constant to the probe length because we want a minimum amount of forward probing, even if we are not moving. float probeLength = Math.Max(BepuVec3.Dot(bcc.Controller.Body.LinearVelocity, bcc.Controller.ViewDirection), 0.0f) + 1.0f; BepuVec3 probeSweep = bcc.Controller.ViewDirection * probeLength; ObstacleFilter filter = new ObstacleFilter(bcc.Controller.Body.CollisionInformation); GameResources.ActorManager.SimSpace.ConvexCast(probe, ref probeStartPosition, ref probeSweep, filter.Test, obstacles); RayCastDistanceComparer rcdc = new RayCastDistanceComparer(); obstacles.Sort(rcdc); BEPUutilities.Vector3 cross = BEPUutilities.Vector3.Zero; int obstacleIndex = 0; do { if (obstacles.Count == obstacleIndex) { return(Vector2.Zero); } cross = BEPUutilities.Vector3.Cross(bcc.Controller.ViewDirection, -obstacles[obstacleIndex++].HitData.Normal); }while (cross.X > 0.7f); // if cross.X > 0.7f, the obstacle is some kind of gentle ramp; ignore it. // dot will typically be negative and magnitude indicates how directly ahead the obstacle is. float dot = BEPUutilities.Vector3.Dot(bcc.Controller.ViewDirection, -obstacles[0].HitData.Normal); if (dot >= 0.0f) // The obstacle won't hinder us if we touch it. { return(Vector2.Zero); } // When cross.Y is positive, the object is generally to the right, so veer left (and vice versa). float directionSign = cross.Y >= 0.0f ? -1.0f : 1.0f; BEPUutilities.Vector2 result = BEPUutilities.Vector2.UnitX * directionSign * -dot; // Also scale response by how close the obstacle is. float distance = (obstacles[0].HitData.Location - bcc.Controller.Body.Position).Length(); result *= MathHelper.Clamp((1.0f - distance / probeLength), 0.0f, 1.0f); // / Math.Abs(dot); // So far the result is in terms of 'velocity space'. Rotate it to align with the controller facing. float velocityTheta = (float)(Math.Atan2(-probeSweep.X, -probeSweep.Z)); BEPUutilities.Matrix2x2 velocityWorld = SpaceUtils.Create2x2RotationMatrix(velocityTheta); float facingTheta = (float)(Math.Atan2(-bcc.Controller.HorizontalViewDirection.X, -bcc.Controller.HorizontalViewDirection.Z)); BEPUutilities.Matrix2x2 facingWorldInv = SpaceUtils.Create2x2RotationMatrix(facingTheta); facingWorldInv.Transpose(); // We want the transpose/inverse of the facing transform because we want to transform the movement into 'facing space'. return(BepuConverter.Convert(SpaceUtils.TransformVec2(SpaceUtils.TransformVec2(result, velocityWorld), facingWorldInv))); }
public ref BEPUutilities.Vector2 CopyTo(ref BEPUutilities.Vector2 toVec) { toVec.X = x; toVec.Y = -z; return(ref toVec); }