/// <summary> /// Tightrope without texture /// </summary> /// <param name="width"></param> /// <param name="length"></param> public Tightrope(float width, float length) : base(-width / 2, 0.01f, 0.0f, width / 2, 1.0f, -length) { CollisionModel = new BoundingBox(-width / 2, 0.0f, 0.0f, width / 2, 0.0f, -length); }
/// <summary> /// Tightrope with texture /// </summary> /// <param name="textureNumber"></param> /// <param name="textureWidth"></param> /// <param name="textureHeight"></param> /// <param name="width"></param> /// <param name="length"></param> public Tightrope(int textureNumber, float textureWidth, float textureHeight, float width, float length) : base(-width / 2, 0.0f, 0.001f, width / 2, 0.001f, -length) { this.TextureNumber = textureNumber; this.TextureWidth = textureWidth; this.TextureHeight = textureHeight; CollisionModel = new BoundingBox(-width / 2, 0.0f, 0.0f, width / 2, 0.0f, -length); }
/// <summary> /// Constructor for non-textured cube. /// </summary> /// <param name="xMin"></param> /// <param name="yMin"></param> /// <param name="zMin"></param> /// <param name="xMax"></param> /// <param name="yMax"></param> /// <param name="zMax"></param> public Cube(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax) : base(xMin, yMin, zMin, xMax, yMax, zMax) { //XMin = xMin; //YMin = yMin; //ZMin = zMin; //XMax = xMax; //YMax = yMax; //ZMax = zMax; m_leftFace = new Quad( new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMin, ZMin), new Vector3f(XMin, YMax, ZMin), new Vector3f(XMin, YMax, ZMax) ); m_rightFace = new Quad( new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMax, YMax, ZMin) ); m_bottomFace = new Quad( new Vector3f(XMin, YMin, ZMax), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMin, YMin, ZMin) ); m_topFace = new Quad( new Vector3f(XMin, YMax, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMin, YMax, ZMax) ); m_frontFace = new Quad( new Vector3f(XMin, YMin, ZMin), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMin, YMax, ZMin) ); m_backFace = new Quad( new Vector3f(XMax, YMin, ZMax), new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMax, ZMax), new Vector3f(XMax, YMax, ZMax) ); //m_leftFace.CollisionModel = new BoundingBox(xMin, YMin, ZMin, xMax, yMax, zMax); //CollisionModel = new List<BoundingBox>(); CollisionModel = new BoundingBox(XMin,YMin,ZMax,XMax,YMax,ZMin); }
static private bool IsInside(float pointX, float pointY, float pointZ, BoundingBox rect1) { if (pointX >= rect1.XMin && pointX <= rect1.XMax) { if (pointY >= rect1.YMin && pointY <= rect1.YMax) { if (pointZ >= rect1.ZMax && pointZ <= rect1.ZMin) { return true; } } } return false; }
/// <summary> /// Returns bool indicating if two bounding boxes have collided /// </summary> /// <param name="rect1"></param> /// <param name="rect2"></param> /// <param name="currentX"></param> /// <param name="currentY"></param> /// <param name="currentZ"></param> /// <returns></returns> static public bool HaveCollided(BoundingBox rect1, BoundingBox rect2, float currentX, float currentY, float currentZ) { bool collisionHasOccured = false; //for each cube2 vertex, check if vertex is inside cube 1 //Front Bottom Left collisionHasOccured = IsInside(rect2.XMin + currentX, rect2.YMin + currentY, rect2.ZMin + currentZ, rect1); //Use IF to prevent further unnecessary searching //Back Bottom Left if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMin + currentX, rect2.YMin + currentY, rect2.ZMax + currentZ, rect1); } //Back Top Left if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMin + currentX, rect2.YMax + currentY, rect2.ZMax + currentZ, rect1); } //Front Top Left if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMin + currentX, rect2.YMax + currentY, rect2.ZMin + currentZ, rect1); } //Front Bottom Right if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMax + currentX, rect2.YMin + currentY, rect2.ZMin + currentZ, rect1); } //Back Bottom Right if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMax + currentX, rect2.YMin + currentY, rect2.ZMax + currentZ, rect1); } //Back Top Right if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMax + currentX, rect2.YMax + currentY, rect2.ZMax + currentZ, rect1); } //Front Top Right if (collisionHasOccured == false) { collisionHasOccured = IsInside(rect2.XMax + currentX, rect2.YMax + currentY, rect2.ZMin + currentZ, rect1); } return collisionHasOccured; }
/// <summary> /// Constructor for non-textured quad. /// </summary> /// <param name="bottomLeftVertex"></param> /// <param name="bottomRightVertex"></param> /// <param name="topRightVertex"></param> /// <param name="topLeftVertex"></param> public Quad(Vector3f bottomLeftVertex, Vector3f bottomRightVertex, Vector3f topRightVertex, Vector3f topLeftVertex) : base((GetMinValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topLeftVertex.X)), (GetMinValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y)), (GetMinValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z)), (GetMaxValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topRightVertex.X)), (GetMaxValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y)), (GetMaxValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z))) { m_vertices[0] = bottomLeftVertex; m_vertices[1] = bottomRightVertex; m_vertices[2] = topRightVertex; m_vertices[3] = topLeftVertex; CollisionModel = new BoundingBox(GetMinValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topLeftVertex.X), GetMinValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y), GetMinValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z), GetMaxValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topRightVertex.X), GetMaxValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y), GetMaxValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z) ); }
/// <summary> /// Constructor for textured quad. /// </summary> /// <param name="textureNumber"></param> /// <param name="textureWidth"></param> /// <param name="textureHeight"></param> /// <param name="bottomLeftVertex"></param> /// <param name="bottomRightVertex"></param> /// <param name="topRightVertex"></param> /// <param name="topLeftVertex"></param> public Quad(int textureNumber, float textureWidth, float textureHeight, Vector3f bottomLeftVertex, Vector3f bottomRightVertex, Vector3f topRightVertex, Vector3f topLeftVertex) : base((GetMinValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topLeftVertex.X)), (GetMinValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y)), (GetMinValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z)), (GetMaxValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topRightVertex.X)), (GetMaxValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y)), (GetMaxValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z))) { m_vertices[0] = bottomLeftVertex; m_vertices[1] = bottomRightVertex; m_vertices[2] = topRightVertex; m_vertices[3] = topLeftVertex; this.TextureNumber = textureNumber; this.TextureWidth = textureWidth; this.TextureHeight = textureHeight; CollisionModel = new BoundingBox(GetMinValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topLeftVertex.X), GetMinValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y), GetMinValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z), GetMaxValue(bottomLeftVertex.X, bottomRightVertex.X, topRightVertex.X, topRightVertex.X), GetMaxValue(bottomLeftVertex.Y, bottomRightVertex.Y, topRightVertex.Y, topLeftVertex.Y), GetMaxValue(bottomLeftVertex.Z, bottomRightVertex.Z, topRightVertex.Z, topLeftVertex.Z) ); }
/// <summary> /// Updates the boundbox for the current object /// </summary> protected virtual void UpdateBoundingBox(float XMin, float YMin, float ZMin, float XMax, float YMax, float ZMax) { CollisionModel = new BoundingBox(XMin, YMin, ZMin, XMax, YMax, ZMax); }
/// <summary> /// Constructor for textured cube. /// </summary> /// <param name="textureNumber"></param> /// <param name="textureWidth"></param> /// <param name="textureHeight"></param> /// <param name="xMin"></param> /// <param name="yMin"></param> /// <param name="zMin"></param> /// <param name="xMax"></param> /// <param name="yMax"></param> /// <param name="zMax"></param> public Cube(int textureNumber, float textureWidth, float textureHeight, float xMin, float yMin, float zMin, float xMax, float yMax, float zMax) : base(textureNumber,textureWidth,textureHeight,xMin, yMin, zMin, xMax, yMax, zMax) { //XMin = xMin; //YMin = yMin; //ZMin = zMin; //XMax = xMax; //YMax = yMax; //ZMax = zMax; this.TextureNumber = textureNumber; this.TextureWidth = textureWidth; this.TextureHeight = textureHeight; if (this.TextureNumber != -1) { m_leftFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMin, ZMin), new Vector3f(XMin, YMax, ZMin), new Vector3f(XMin, YMax, ZMax) ); m_rightFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMax, YMax, ZMin) ); m_bottomFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMin, YMin, ZMax), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMin, YMin, ZMin) ); m_topFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMin, YMax, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMin, YMax, ZMax) ); m_frontFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMin, YMin, ZMin), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMin, YMax, ZMin) ); m_backFace = new Quad(this.TextureNumber, this.TextureWidth, this.TextureHeight, new Vector3f(XMax, YMin, ZMax), new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMax, ZMax), new Vector3f(XMax, YMax, ZMax) ); } else { m_leftFace = new Quad(new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMin, ZMin), new Vector3f(XMin, YMax, ZMin), new Vector3f(XMin, YMax, ZMax) ); m_rightFace = new Quad(new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMax, YMax, ZMin) ); m_bottomFace = new Quad(new Vector3f(XMin, YMin, ZMax), new Vector3f(XMax, YMin, ZMax), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMin, YMin, ZMin) ); m_topFace = new Quad(new Vector3f(XMin, YMax, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMax, YMax, ZMax), new Vector3f(XMin, YMax, ZMax) ); m_frontFace = new Quad(new Vector3f(XMin, YMin, ZMin), new Vector3f(XMax, YMin, ZMin), new Vector3f(XMax, YMax, ZMin), new Vector3f(XMin, YMax, ZMin) ); m_backFace = new Quad(new Vector3f(XMax, YMin, ZMax), new Vector3f(XMin, YMin, ZMax), new Vector3f(XMin, YMax, ZMax), new Vector3f(XMax, YMax, ZMax) ); } //m_leftFace.CollisionModel = new BoundingBox(xMin, YMin, ZMin, xMax, yMax, zMax); //CollisionModel = new List<BoundingBox>(); CollisionModel = new BoundingBox(XMin, YMin, ZMax, XMax, YMax, ZMin); }