///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> /// <param name="inertiaTensor">Inertia tensor of the entity.</param> public MorphableEntity(EntityShape shape, float mass, Matrix3f inertiaTensor) : base(shape, mass, inertiaTensor) { }
///<summary> /// Constructs a new kinematic entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> public Entity(EntityShape shape) : this() { Initialize(shape.GetCollidableInstance()); }
///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> public MorphableEntity(EntityShape shape) : base(shape) { }
///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> public MorphableEntity(EntityShape shape, float mass) : base(shape, mass) { }
public static void DrawCardinalitiesLine(Graphics g, CardinalityShape cardi, int EntityEdgeCardiPlace, int pos, int numCardi, Color backgroundColor) { EntityShape entity = cardi.Entity; RelationshipShape rel = cardi.Relationship; //debug //g.DrawLine(new Pen(Color.Red, 1), entity.CenterPoint, rel.CenterPoint); Point centerRelationship = rel.CenterPoint; Point centerEntity = entity.CenterPoint; Point TopLeft = entity.Location; Point BottomRight = new Point(entity.Location.X + entity.Width, entity.Location.Y + entity.Height); int stepX = pos * entity.Width / (numCardi + 1); int stepY = pos * entity.Height / (numCardi + 1); Bitmap myCardi = GetCardinalitiesShape(cardi, EntityEdgeCardiPlace, backgroundColor); Point EntityStartPos = getStartPos(EntityEdgeCardiPlace, (ShapeBase)entity, TopLeft, BottomRight, stepX, stepY, myCardi); Point EntityCardiPos = getCardiPos(EntityEdgeCardiPlace, (ShapeBase)entity, TopLeft, BottomRight, stepX, stepY, myCardi); if (rel.type != RelationshipType.AssociativeEntity) { g.DrawImage(myCardi, EntityCardiPos); g.DrawLine(ThongSo.ConectiveLinePen, EntityStartPos, centerRelationship); } else //nếu relationship là Associative Entity { Point TopLeftRel = rel.Location; Point BottomRightRel = new Point(rel.Location.X + rel.Width, rel.Location.Y + rel.Height); int AssEdgeCardiPlace = 0, index = 0; rel.getCardiPosition(cardi, ref AssEdgeCardiPlace, ref index); int stepXRel = (index + 1) * rel.Width / (rel.cardiplaces[AssEdgeCardiPlace - 1].Count + 1); int stepYRel = (index + 1) * rel.Height / (rel.cardiplaces[AssEdgeCardiPlace - 1].Count + 1); //cardi 1, 1 CardinalityShape cardi1 = new CardinalityShape(); cardi1.setValue(1, 1); //lấy cardi của đầu bên kia Relationship CardinalityShape cardi2 = new CardinalityShape(); foreach (CardinalityShape card in cardi.Relationship.cardinalities) { if (card != cardi) { cardi2 = card; } } Bitmap CardiAtEn = GetCardinalitiesShape(cardi1, EntityEdgeCardiPlace, backgroundColor); Bitmap CardiAtRel = GetCardinalitiesShape(cardi2, AssEdgeCardiPlace, backgroundColor); Point AssStartPos = getStartPos(AssEdgeCardiPlace, (ShapeBase)rel, TopLeftRel, BottomRightRel, stepXRel, stepYRel, CardiAtRel); Point AssCardiPos = getCardiPos(AssEdgeCardiPlace, (ShapeBase)rel, TopLeftRel, BottomRightRel, stepXRel, stepYRel, CardiAtRel); g.DrawImage(CardiAtEn, EntityCardiPos); g.DrawImage(CardiAtRel, AssCardiPos); g.DrawLine(ThongSo.ConectiveLinePen, EntityStartPos, AssStartPos); } }
protected EntityCollidable(EntityShape shape) { base.Shape = shape; }
public bool ConvexCast(ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweepnorm, double slen, MaterialSolidity solidness, out RayHit hit) { RigidTransform rot = new RigidTransform(Vector3.Zero, startingTransform.Orientation); castShape.GetBoundingBox(ref rot, out BoundingBox bb); double adv = 0.1f; double max = slen + adv; bool gotOne = false; RayHit BestRH = default(RayHit); Vector3 sweep = sweepnorm * slen; for (double f = 0; f < max; f += adv) { Vector3 c = startingTransform.Position + sweepnorm * f; int mx = (int)Math.Ceiling(c.X + bb.Max.X); for (int x = (int)Math.Floor(c.X + bb.Min.X); x <= mx; x++) { if (x < 0 || x >= ChunkSize.X) { continue; } int my = (int)Math.Ceiling(c.Y + bb.Max.Y); for (int y = (int)Math.Floor(c.Y + bb.Min.Y); y <= my; y++) { if (y < 0 || y >= ChunkSize.Y) { continue; } int mz = (int)Math.Ceiling(c.Z + bb.Max.Z); for (int z = (int)Math.Floor(c.Z + bb.Min.Z); z <= mz; z++) { if (z < 0 || z >= ChunkSize.Z) { continue; } BlockInternal bi = Blocks[BlockIndex(x, y, z)]; if (solidness.HasFlag(((Material)bi.BlockMaterial).GetSolidity())) { EntityShape es = BlockShapeRegistry.BSD[bi.BlockData].GetShape(bi.Damage, out Location offs, false); if (es == null) { continue; } Vector3 adj = new Vector3(x + (double)offs.X, y + (double)offs.Y, z + (double)offs.Z); EntityCollidable coll = es.GetCollidableInstance(); //coll.LocalPosition = adj; RigidTransform rt = new RigidTransform(Vector3.Zero, Quaternion.Identity); coll.LocalPosition = Vector3.Zero; coll.WorldTransform = rt; coll.UpdateBoundingBoxForTransform(ref rt); RigidTransform adjusted = new RigidTransform(startingTransform.Position - adj, startingTransform.Orientation); bool b = coll.ConvexCast(castShape, ref adjusted, ref sweep, out RayHit rhit); if (b && (!gotOne || rhit.T * slen < BestRH.T) && rhit.T >= 0) { gotOne = true; BestRH = rhit; BestRH.Location += adj; BestRH.T *= slen; // TODO: ??? BestRH.Normal = -BestRH.Normal; // TODO: WHY?! } } } } } if (gotOne) { hit = BestRH; return(true); } } hit = new RayHit() { Location = startingTransform.Position + sweep, Normal = new Vector3(0, 0, 0), T = slen }; return(false); }
///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> /// <param name="inertiaTensor">Inertia tensor of the entity.</param> public MorphableEntity(EntityShape shape, Fix64 mass, Matrix3x3 inertiaTensor) : base(shape, mass, inertiaTensor) { }
public BodyComponent(float width, float height, EntityType entityType, EntityShape entityShape, float density = 1f) : this(new Vector2(width, height), entityType, entityShape, density) { }
public BodyComponent(IEnumerable <Vector2> vertices, EntityType entityType, EntityShape entityShape, float density = 1f) : this(Vector2.Zero, entityType, entityShape, density) { Vertices = vertices; }
public AddCardinality(RelationshipShape relationship) { InitializeComponent(); Relationship = new RelationshipShape(relationship.sName, new Point(panelDoubleBuffered1.Width / 2, panelDoubleBuffered1.Height / 2), relationship.type); SelectedEntity1 = new EntityShape(relationship.cardinalities[0].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 - ThongSo.ShapeW * 3 / 2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[0].Entity.type); SelectedEntity2 = new EntityShape(relationship.cardinalities[1].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 + ThongSo.ShapeW * 3 / 2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[1].Entity.type); cardi1 = Relationship.CreateCardinality(SelectedEntity1, relationship.cardinalities[0].MinCardinality, relationship.cardinalities[0].MaxCardinality); cardi2 = Relationship.CreateCardinality(SelectedEntity2, relationship.cardinalities[1].MinCardinality, relationship.cardinalities[1].MaxCardinality); panelDoubleBuffered1.Controls.Add(Relationship); panelDoubleBuffered1.Controls.Add(SelectedEntity1); panelDoubleBuffered1.Controls.Add(SelectedEntity2); panelDoubleBuffered1.Refresh(); int min1, max1, min2, max2; min1 = Relationship.cardinalities[0].MinCardinality; max1 = Relationship.cardinalities[0].MaxCardinality; min2 = Relationship.cardinalities[1].MinCardinality; max2 = Relationship.cardinalities[1].MaxCardinality; if (min1 == 0 && max1 == 1) { imageComboBoxEdit1.SelectedIndex = 0; } if (min1 == 1 && max1 == 1) { imageComboBoxEdit1.SelectedIndex = 1; } if (min1 == 0 && max1 == -1) { imageComboBoxEdit1.SelectedIndex = 2; } if (min1 == 1 && max1 == -1) { imageComboBoxEdit1.SelectedIndex = 3; } if (min2 == 0 && max2 == 1) { imageComboBoxEdit2.SelectedIndex = 0; } if (min2 == 1 && max2 == 1) { imageComboBoxEdit2.SelectedIndex = 1; } if (min2 == 0 && max2 == -1) { imageComboBoxEdit2.SelectedIndex = 2; } if (min2 == 1 && max2 == -1) { imageComboBoxEdit2.SelectedIndex = 3; } showText(); }
///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> /// <param name="inertiaTensor">Inertia tensor of the entity.</param> /// <param name="volume">Volume of the entity.</param> public MorphableEntity(EntityShape shape, float mass, Matrix3x3 inertiaTensor, float volume) : base(shape, mass, inertiaTensor, volume) { }
public override void Start() { if (HasComponent <Collider>()) { Collider c = _geCollider; _collisionShape = c.Shape; Transform t = gameElement.WorldTransform; _motionState = new MotionState { Position = t.Translation, Orientation = Quaternion.FromEulerAngles(t.Rotation.Z, t.Rotation.Y, t.Rotation.X) }; _innerRigidBody = new Entity(_collisionShape, _mass) { MotionState = _motionState }; _innerRigidBody.PositionUpdateMode = PositionUpdateMode.Discrete; _innerRigidBody.PositionUpdated += _positionUpdated; _innerRigidBody.Tag = gameElement.Tag; _innerRigidBody.CollisionInformation.Tag = gameElement.Tag; gameElement.LocalTransform.OnPositionChange += ((_old, _new) => { if (!_shouldUpdate) { Transform _t = gameElement.WorldTransform; _innerRigidBody.Position += (_t.Translation - _lastTranslate); _lastTranslate = _t.Translation; } // Keep the rigidbody active while moving //if (!_innerRigidBody.IsActive) //{ // _innerRigidBody.ClearForces(); // _innerRigidBody.ProceedToTransform((Matrix)gameElement.WorldTransform.GetTransformation()); //} }); gameElement.LocalTransform.OnRotationChange += ((_old, _new) => { if (!_shouldUpdate) { Transform _t = gameElement.WorldTransform; Quaternion _q = Quaternion.FromEulerAngles(t.Rotation.X, t.Rotation.Y, t.Rotation.Z); _innerRigidBody.Orientation = _q; _innerRigidBody.AngularVelocity += (_t.Rotation - _lastRotate); _lastRotate = _t.Rotation; } }); gameElement.ParentScene.RegisterRigidBody(gameElement); _lastTranslate = t.Translation; _lastRotate = t.Rotation; } }
///<summary> /// Constructs a new dynamic entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> public Entity(EntityShape shape, float mass) : this() { Initialize(shape.GetCollidableInstance(), mass); }
public bool Build(ShapeCollection staticGeometries, ref int numGeometryVertices, ref int numGeometryTriangles) { if (!HasEngineInstance()) { return(false); } EngineNavMesh.ClearNavMesh(); EngineNavMesh.ClearGeometry(); EngineNavMesh.ClearCarvers(); EngineNavMesh.ClearSeedPoints(); EngineNavMesh.ClearLocalSettings(); EngineNavMesh.ClearDecorationCapsules(); SetEngineInstanceBaseProperties(); HavokNavMeshGlobalSettings globalSettings = GetGlobalSettings(); if (globalSettings == null) { return(false); } BoundingBox parentZoneBbox = new BoundingBox(); if (globalSettings.RestrictToInputGeometryFromSameZone && ParentZone != null) { parentZoneBbox = ParentZone.CalculateBoundingBox(); } // check if there's a parent zone foreach (ShapeBase shape in staticGeometries) { // treat as cutter if flag is set and if in different zone bool potentiallyTreatAsCutter = globalSettings.RestrictToInputGeometryFromSameZone && (shape.ParentZone != ParentZone); if (shape is EntityShape) { EntityShape entity = shape as EntityShape; eNavMeshUsage usage = entity.GetNavMeshUsage(); // exclude entities that have a vHavokRigidBody component with "Motion Type" != "Fixed" ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("vHavokRigidBody"); if (compType != null && entity.Components != null) { ShapeComponent comp = entity.Components.GetComponentByType(compType); if (comp != null) { string propValue = comp.GetPropertyValue("Motion Type") as string; if (string.Compare(propValue, "Fixed") != 0) { usage = eNavMeshUsage.ExcludeFromNavMesh; } } } // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddEntityGeometry(entity.EngineEntity.GetNativeObject(), (int)usage, parentZoneBbox); } } else if (shape is StaticMeshShape) { StaticMeshShape staticMesh = shape as StaticMeshShape; eNavMeshUsage usage = staticMesh.GetNavMeshUsage(); // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddStaticMeshGeometry(staticMesh.EngineMesh.GetNativeObject(), (int)usage, parentZoneBbox); } } else if (shape is TerrainShape) { TerrainShape terrain = shape as TerrainShape; eNavMeshUsage usage = terrain.GetNavMeshUsage(); // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddTerrainGeometry(terrain.EngineTerrain.GetNativeObject(), (int)usage, parentZoneBbox); } } #if !HK_ANARCHY else if (shape is DecorationGroupShape) { DecorationGroupShape decorationGroup = shape as DecorationGroupShape; // Please note that currently the native HavokAiEnginePlugin only supports decoration capsules as cutters. if (decorationGroup.GetNavMeshLimitedUsage() == DecorationGroupShape.eNavMeshLimitedUsage.CutterOnly) { EngineNavMesh.AddDecorationGroupCapsules(decorationGroup.EngineGroup.GetGroupsObject()); } } #endif #if USE_SPEEDTREE else if (shape is Speedtree6GroupShape) { Speedtree6GroupShape trees = shape as Speedtree6GroupShape; if (trees.EnableCollisions) { EngineNavMesh.AddSpeedTree6Capsules(trees.EngineGroup.GetGroupsObject()); } } #endif } numGeometryVertices = EngineNavMesh.GetNumGeometryVertices(); numGeometryTriangles = EngineNavMesh.GetNumGeometryTriangles(); // Add carvers ShapeCollection carvers = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshCarverShape)); foreach (ShapeBase shape in carvers) { HavokNavMeshCarverShape carver = shape as HavokNavMeshCarverShape; BoundingBox localBbox = null; carver.GetLocalBoundingBox(ref localBbox); localBbox.vMin.X *= carver.ScaleX; localBbox.vMin.Y *= carver.ScaleY; localBbox.vMin.Z *= carver.ScaleZ; localBbox.vMax.X *= carver.ScaleX; localBbox.vMax.Y *= carver.ScaleY; localBbox.vMax.Z *= carver.ScaleZ; EngineNavMesh.AddBoxCarver(localBbox.vMin, localBbox.vMax, carver.Position, carver.RotationMatrix, carver.IsInverted()); } // Add seed points ShapeCollection seedPoints = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshSeedPointShape)); foreach (ShapeBase shape in seedPoints) { HavokNavMeshSeedPointShape seedPoint = shape as HavokNavMeshSeedPointShape; EngineNavMesh.AddSeedPoint(seedPoint.Position); } // Add local settings ShapeCollection localSettings = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshLocalSettingsShape)); foreach (ShapeBase shape in localSettings) { HavokNavMeshLocalSettingsShape ls = shape as HavokNavMeshLocalSettingsShape; BoundingBox bbox = null; ls.GetLocalBoundingBox(ref bbox); bbox.vMin.X *= ls.ScaleX; bbox.vMin.Y *= ls.ScaleY; bbox.vMin.Z *= ls.ScaleZ; bbox.vMax.X *= ls.ScaleX; bbox.vMax.Y *= ls.ScaleY; bbox.vMax.Z *= ls.ScaleZ; // Nav Mesh Generation Settings EngineNavMesh.m_maxWalkableSlope = ls.MaxWalkableSlope / 180.0f * 3.14159f; // Nav Mesh Edge Matching Settings EngineNavMesh.m_maxStepHeight = ls.MaxStepHeight; EngineNavMesh.m_maxSeparation = ls.MaxSeparation; EngineNavMesh.m_maxOverhang = ls.MaxOverhang; EngineNavMesh.m_cosPlanarAlignmentAngle = (float)Math.Cos(ls.PlanarAlignmentAngle / 180.0f * 3.14159f); EngineNavMesh.m_cosVerticalAlignmentAngle = (float)Math.Cos(ls.VerticalAlignmentAngle / 180.0f * 3.14159f); EngineNavMesh.m_minEdgeOverlap = ls.MinEdgeOverlap; // Nav Mesh Simplification Settings EngineNavMesh.m_maxBorderSimplifyArea = ls.MaxBorderSimplifyArea; EngineNavMesh.m_maxConcaveBorderSimplifyArea = ls.MaxConcaveBorderSimplifyArea; EngineNavMesh.m_useHeightPartitioning = ls.UseHeightPartitioning; EngineNavMesh.m_maxPartitionHeightError = ls.MaxPartitionHeightError; // Nav Mesh Simplification Settings (Advanced) EngineNavMesh.m_minCorridorWidth = ls.MinCorridorWidth; EngineNavMesh.m_maxCorridorWidth = ls.MaxCorridorWidth; EngineNavMesh.m_holeReplacementArea = ls.HoleReplacementArea; EngineNavMesh.m_maxLoopShrinkFraction = ls.MaxLoopShrinkFraction; EngineNavMesh.m_maxBorderHeightError = ls.MaxBorderHeightError; EngineNavMesh.m_maxBorderDistanceError = ls.MaxBorderDistanceError; EngineNavMesh.m_maxPartitionSize = ls.MaxPartitionSize; EngineNavMesh.m_useConservativeHeightPartitioning = ls.UseConservativeHeightPartitioning; EngineNavMesh.m_hertelMehlhornHeightError = ls.HertelMehlhornHeightError; EngineNavMesh.m_cosPlanarityThreshold = (float)Math.Cos(ls.PlanarityThreshold / 180 * 3.14159f); EngineNavMesh.m_nonconvexityThreshold = ls.NonconvexityThreshold; EngineNavMesh.m_boundaryEdgeFilterThreshold = ls.BoundaryEdgeFilterThreshold; EngineNavMesh.m_maxSharedVertexHorizontalError = ls.MaxSharedVertexHorizontalError; EngineNavMesh.m_maxSharedVertexVerticalError = ls.MaxSharedVertexVerticalError; EngineNavMesh.m_maxBoundaryVertexHorizontalError = ls.MaxBoundaryVertexHorizontalError; EngineNavMesh.m_maxBoundaryVertexVerticalError = ls.MaxBoundaryVertexVerticalError; EngineNavMesh.m_mergeLongestEdgesFirst = ls.MergeLongestEdgesFirst; EngineNavMesh.AddLocalSettings(bbox.vMin, bbox.vMax, ls.Position, ls.RotationMatrix); } // todo: figure out how to pass class instances between here and EngineNavMesh. // basically the settings members of EngineNavMesh are reused for transferring the local settings to // EngineNavMesh. this should be harmless due to the following call which will revert any changes. SetEngineInstanceBaseProperties(); string fullSnapshotPath = Path.Combine(CSharpFramework.EditorManager.Scene.Project.ProjectDir, m_snapshotFilename); bool ret = EngineNavMesh.BuildNavMeshFromGeometry(m_saveInputSnapshot, fullSnapshotPath); EngineNavMesh.ClearGeometry(); EngineNavMesh.ClearCarvers(); EngineNavMesh.ClearSeedPoints(); EngineNavMesh.ClearLocalSettings(); EngineNavMesh.ClearDecorationCapsules(); return(ret); }
///<summary> /// Constructs a new dynamic entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> /// <param name="inertiaTensor">Inertia tensor of the entity.</param> public Entity(EntityShape shape, float mass, Matrix3X3 inertiaTensor) : this() { Initialize(shape.GetCollidableInstance(), mass, inertiaTensor); }
///<summary> /// Constructs a new morphable entity. ///</summary> ///<param name="shape">Shape to use with the entity.</param> ///<param name="mass">Mass of the entity.</param> public MorphableEntity(EntityShape shape, Fix64 mass) : base(shape, mass) { }