public MovingObject(CollisionAPI api) { this.api = api; parts = new List <MovingPart>(); renderedNodes = null; movingObjects.Add(this); }
public MovingObject(CollisionAPI api) { this.api = api; parts = new List<MovingPart>(); renderedNodes = null; movingObjects.Add(this); }
public static RenderState ToggleRenderCollisionVolumes(CollisionAPI api, SceneManager sceneManager, bool movingObjects) { if (scene == null) { scene = sceneManager; } RenderState previousState = renderState; if (movingObjects) { renderState = (renderState == RenderState.None ? RenderState.All : (renderState == RenderState.All ? RenderState.Obstacles : RenderState.None)); } else { renderState = (renderState == RenderState.None ? RenderState.Obstacles : RenderState.None); } bool renderObstacles = RenderObstacles(renderState); if (renderObstacles != RenderObstacles(previousState)) { api.SphereTree.ChangeRendering(renderObstacles); } bool renderMOs = RenderMovingObjects(renderState); if (renderMOs != RenderMovingObjects(previousState)) { MovingObject.ChangeRendering(renderMOs); } return(previousState); }
public CollisionTileManager(CollisionAPI API, float tileSize, FindObstaclesInBoxCallback ObstacleFinder) { collisionAPI = API; this.tileSize = tileSize; this.ObstacleFinder = ObstacleFinder; collisionHorizon = 0.0f; tiles = null; }
public MovingPart(CollisionAPI api, CollisionShape shape) { this.shape = shape; this.api = api; constantShape = shape; id = api.SphereTree.GetId(); renderedNodes = null; RenderedNode.MaybeCreateRenderedNodes(false, shape, id, ref renderedNodes); sphere = null; }
private void FourCollisionsButton_Click(object sender, EventArgs e) { CollisionAPI API = new CollisionAPI(); // Create some obstacles, at 4 corners of a square List<CollisionShape> shapes = new List<CollisionShape>(); CollisionSphere sphere = new CollisionSphere(new Vector3(0f, 0f, 2f), 1f); shapes.Add(sphere); API.AddCollisionShape(sphere, 1); CollisionCapsule capsule = new CollisionCapsule(new Vector3(10f,0f,0f), new Vector3(10f,0f,4f), 1f); shapes.Add(capsule); API.AddCollisionShape(capsule, 2); // Now, an AABB CollisionAABB aabb = new CollisionAABB(new Vector3(9.5f,9.5f,0f), new Vector3(10.5f,10.5f,4f)); shapes.Add(aabb); API.AddCollisionShape(aabb, 3); CollisionOBB obb = new CollisionOBB(new Vector3(0f,10f,2), new Vector3[3] { new Vector3(1f,0f,0f), new Vector3(0f,1f,0f), new Vector3(0f,0f,1f)}, new Vector3(1f, 1f, 1f)); shapes.Add(obb); API.AddCollisionShape(obb, 4); FileStream f = new FileStream("C:\\Junk\\DumpSphereTree.txt", FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(f); API.DumpSphereTree(writer); API.SphereTreeRoot.VerifySphereTree(); // Now a moving object capsule in the center of the square CollisionCapsule moCap = new CollisionCapsule(new Vector3(5f,5f,0f), new Vector3(5f,5f,4f), 1f); // Remember where the moving object started Vector3 start = moCap.center; // Move the moving object toward each of the obstacles foreach (CollisionShape s in shapes) { moCap.AddDisplacement(start - moCap.center); MoveToObject(writer, API, s, moCap); } writer.Close(); }
public void GrabCounters(CollisionAPI api) { nodeCounter.RawValue = api.SphereTree.nodeCount; shapesAddedCounter.RawValue = api.SphereTree.shapesAdded; shapesRemovedCounter.RawValue = api.SphereTree.shapesRemoved; intersectingShapeCounter.RawValue = api.SphereTree.intersectingShapeCount; topLevelCallsCounter.RawValue = api.topLevelCalls; partCallsCounter.RawValue = api.partCalls; topLevelCollisionsCounter.RawValue = api.topLevelCollisions; collisionTestCounter.RawValue = api.collisionTestCount; }
public static void InitPrimeMover(WorldManager worldMgr, CollisionAPI collisionMgr) { worldManager = worldMgr; collisionManager = collisionMgr; playerStuck = false; }
public MovingPart(CollisionAPI api, CollisionShape shape) { this.shape = shape; this.api = api; constantShape = shape; id = api.SphereTree.GetId(); renderedNodes = null; RenderedNode.MaybeCreateRenderedNodes(false, shape, id, ref renderedNodes); sphere = null; }
public CollisionTileManager(CollisionAPI API, float tileSize, FindObstaclesInBoxCallback ObstacleFinder) { collisionAPI = API; this.tileSize = tileSize; this.ObstacleFinder = ObstacleFinder; collisionHorizon = 0.0f; tiles = null; }
// This entrypoint is invoked by the higher-level client to // set up the collision tile manager public void SetCollisionInterface(CollisionAPI API, float tileSize) { collisionTileManager = new CollisionTileManager(API, tileSize, FindObstaclesInBox); }
// This entrypoint is invoked by the higher-level client to // set up the collision tile manager public void SetCollisionInterface(CollisionAPI API, float tileSize) { TerrainManager.Instance.SetCollisionInterface(API, tileSize); }
private void MoveToObject(StreamWriter stream, CollisionAPI API, CollisionShape collisionShape, CollisionShape movingShape) { stream.Write("\n\n\nEntering MoveToObject\n"); // Create a MovingObject, and add movingShape to it MovingObject mo = new MovingObject(); API.AddPartToMovingObject(mo, movingShape); // Move movingObject 1 foot at a time toward the sphere Vector3 toShape = collisionShape.center - movingShape.center; stream.Write(string.Format("movingShape {0}\n", movingShape.ToString())); stream.Write(string.Format("collisionShape {0}\nDisplacement Vector {1}\n", collisionShape.ToString(), toShape.ToString())); // We'll certainly get there before steps expires int steps = (int)Math.Ceiling(toShape.Length); // 1 foot step in the right direction Vector3 stepVector = toShape.ToNormalized(); stream.Write(string.Format("Steps {0}, stepVector {1}\n", steps, stepVector.ToString())); bool hitIt = false; // Loop til we smack into something CollisionParms parms = new CollisionParms(); for (int i=0; i<steps; i++) { // Move 1 foot; if returns true, we hit something hitIt = (API.TestCollision (mo, stepVector, parms)); stream.Write(string.Format("i = {0}, hitIt = {1}, movingShape.center = {2}\n", i, hitIt, movingShape.center.ToString())); if (hitIt) { stream.Write(string.Format("collidingPart {0}\nblockingObstacle {1}\n, normPart {2}, normObstacle {3}\n", parms.part.ToString(), parms.obstacle.ToString(), parms.normPart.ToString(), parms.normObstacle.ToString())); return; } stream.Write("\n"); } Debug.Assert(hitIt, "Didn't hit the obstacle"); }
private void GenerateRandomObjects(StreamWriter stream, CollisionAPI API, Random rand, int count, int handleStart, float coordRange, float objectSizeRange) { // Set the seed to make the sequence deterministic for (int i=0; i<count; i++) { CollisionShape shape = RandomObject(rand, coordRange, objectSizeRange); //stream.Write(string.Format("\nAdding (i={0}) shape {1}", i, shape.ToString())); //stream.Flush(); API.AddCollisionShape(shape, (i + handleStart)); //API.DumpSphereTree(stream); //stream.Flush(); API.SphereTreeRoot.VerifySphereTree(); } }
public void GrabCounters(CollisionAPI api) { nodeCounter.RawValue = api.SphereTree.nodeCount; shapesAddedCounter.RawValue = api.SphereTree.shapesAdded; shapesRemovedCounter.RawValue = api.SphereTree.shapesRemoved; intersectingShapeCounter.RawValue = api.SphereTree.intersectingShapeCount; topLevelCallsCounter.RawValue = api.topLevelCalls; partCallsCounter.RawValue = api.partCalls; topLevelCollisionsCounter.RawValue = api.topLevelCollisions; collisionTestCounter.RawValue = api.collisionTestCount; }
protected bool Setup() { if (repositoryDirectoryList.Count > 0) RepositoryClass.Instance.InitializeRepository(repositoryDirectoryList); else RepositoryClass.Instance.InitializeRepositoryPath(); // get a reference to the engine singleton engine = new Root(null, null); // retrieve the max FPS, if it exists getMaxFPSFromRegistry(); // add event handlers for frame events engine.FrameStarted += new FrameEvent(OnFrameStarted); engine.FrameEnded += new FrameEvent(OnFrameEnded); // make the collisionAPI object collisionManager = new CollisionAPI(false); // allow for setting up resource gathering if (!SetupResources()) return false; //show the config dialog and collect options if (!ConfigureAxiom()) { // shutting right back down engine.Shutdown(); return false; } if (!CheckShaderCaps()) { MessageBox.Show("Your graphics card does not support pixel shader 2.0 and vertex shader 2.0, which are required to run this tool.", "Graphics Card Not Supported", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); engine.Shutdown(); return false; } ChooseSceneManager(); CreateCamera(); CreateViewports(); // set default mipmap level TextureManager.Instance.DefaultNumMipMaps = 5; materialSchemeNames = MaterialManager.Instance.SchemeNames; if (materialSchemeNames.Count > 1) materialSchemeToolStripMenuItem.Enabled = true; // call the overridden CreateScene method CreateScene(); InitializeAxiomControlCallbacks(); return true; }
public PathGenerator(bool logPathGeneration, string modelName, PathObjectType poType, float terrainLevel, Matrix4 modelTransform, List<CollisionShape> collisionVolumes) { this.dumpGrid = logPathGeneration; this.modelName = modelName; this.poType = poType; this.modelWidth = poType.width * oneMeter; this.cellWidth = poType.gridResolution * modelWidth; this.boxHeight = poType.height * oneMeter; this.maxClimbDistance = poType.maxClimbSlope * cellWidth; this.maxDisjointDistance = poType.maxDisjointDistance * oneMeter; this.minimumFeatureSize = poType.minimumFeatureSize; this.terrainLevel = terrainLevel; this.modelTransform = modelTransform; this.collisionVolumes = collisionVolumes; stopwatch = new Stopwatch(); stopwatch.Start(); // Create the collisionAPI object collisionAPI = new CollisionAPI(false); // Ugly workaround for a modularity problem do to // unadvised use of static variables: remember the // existing state of rendering collision volumes RenderedNode.RenderState oldRenderState = RenderedNode.renderState; RenderedNode.renderState = RenderedNode.RenderState.None; // Form the union of the collision volumes; we don't care // about Y coordinate, only the X and Z coordinates Vector3 min = Vector3.Zero; Vector3 max = Vector3.Zero; for (int i=0; i<collisionVolumes.Count; i++) { CollisionShape shape = collisionVolumes[i]; // Add the shape to the sphere tree collisionAPI.SphereTree.AddCollisionShape(shape); AxisAlignedBox vol = shape.BoundingBox(); // If this is the first iteration, set up the min and // max if (i == 0) { min = vol.Minimum; max = vol.Maximum; min.y = terrainLevel; max.y = terrainLevel; continue; } // Enlarge the box by the dimensions of the shape min.x = Math.Min(min.x, vol.Minimum.x); min.z = Math.Min(min.z, vol.Minimum.z); max.x = Math.Max(max.x, vol.Maximum.x); max.z = Math.Max(max.z, vol.Maximum.z); } // Restore RenderState RenderedNode.renderState = oldRenderState; // Round out the max and min by 4 times the grid // resolution, so we can just divide to find the // horizontal and vertical numbers are cells Vector3 margin = Vector3.UnitScale * 4 * cellWidth; min -= margin; max += margin; // Now adjust the max the min coords so that they are // exactly a multiple of the grid resolution min.x = MultipleOfResolution(min.x); min.z = MultipleOfResolution(min.z); max.x = MultipleOfResolution(max.x); max.z = MultipleOfResolution(max.z); // Set the lower left and upper right corners lowerLeftCorner = min; upperRightCorner = max; // Set the horizontal and vertical counts xCount = (int)((max.x - min.x) / cellWidth); zCount = (int)((max.z - min.z) / cellWidth); // Initial the gridBox gridBox = new AxisAlignedBox(min, max); // Allocate the grid grid = new List<GridCell>[xCount, zCount]; for (int i=0; i<xCount; i++) for (int j=0; j<zCount; j++) grid[i,j] = new List<GridCell>(); // Initialize the work list, adding the cell at 0,0 and // the terrain height as the first member workList = new List<CellLocation>(); workList.Add(new CellLocation(0, 0, terrainLevel, null)); // Create the moving box at the center of the 0, 0 cell, // and the MovingObject object that contains the moving box movingBox = new CollisionAABB( new Vector3(min.x, terrainLevel, min.z), new Vector3(min.x + cellWidth, terrainLevel + boxHeight, min.z + terrainLevel)); movingObject = new MovingObject(collisionAPI); movingObject.AddPart(movingBox); }
private void RandomSpheresButton_Click(object sender, EventArgs e) { const int iterations = 20; const int objects = 10; const float coordRange = 1000.0f; const float objectSizeRange = 20.0f; CollisionAPI API = new CollisionAPI(); Random rand = new Random((int)3141526); FileStream f = new FileStream("C:\\Junk\\RandomSphereTree.txt", FileMode.Create, FileAccess.Write); StreamWriter stream = new StreamWriter(f); // Create and delete many randomly-placed collision // objects, periodically verifying the sphere tree for (int i=0; i<iterations; i++) { stream.Write("//////////////////////////////////////////////////////////////////////\n\n"); stream.Write(string.Format("Creation Iteration {0}, adding {1} objects, object size range {2}, coordinate range {3}\n\n", i, objects, objectSizeRange, coordRange)); GenerateRandomObjects(stream, API, rand, objects, 0, coordRange, objectSizeRange); stream.Write(string.Format("\n\nAfter iteration {0}:\n\n", i)); API.DumpSphereTree(stream); stream.Flush(); API.SphereTreeRoot.VerifySphereTree(); } for (int i=0; i<objects; i++) { stream.Write("\n\n//////////////////////////////////////////////////////////////////////\n\n"); stream.Write(string.Format("Deleting shapes with handle {0}\n\n", i)); API.RemoveCollisionShapesWithHandle(i); API.DumpSphereTree(stream); stream.Flush(); API.SphereTreeRoot.VerifySphereTree(); } stream.Close(); }