//Constructor------------------------------------------------------------------------ /// <summary> /// Construct a pack with an Object3D leader /// </summary> /// <param name="theStage"> the scene </param> /// <param name="label"> name of pack </param> /// <param name="meshFile"> model of a pack instance</param> /// <param name="xPos, zPos"> approximate position of the pack </param> /// <param name="aLeader"> alpha dog can be used for flock center and alignment </param> public Pack(Stage theStage, string label, string meshFile, int nDogs, int xPos, int zPos, Object3D theLeader, bool isCollidable = true) : base(theStage, label, meshFile) { this.isCollidable = isCollidable; this.random = new Random(); this.leader = theLeader; //Local Variables UInt32 spacing = (UInt32)stage.Spacing; Int32 x, z; float scale; //Initial vertex offset of dogs around (xPos, zPos) Int32[,] position = { { 0, 0 }, { 7, -4 }, { -5, -2 }, { -7, 4 }, { 5, 2 } }; for (int i = 0; i < position.GetLength(0); i++) { //Position the dogs x = xPos + position[i, 0]; z = zPos + position[i, 1]; //Scale the dogs scale = (float)(0.5 + random.NextDouble()); //Add the pack member to the instance list addObject(new Vector3(x * spacing, stage.surfaceHeight(x, z), z * spacing), new Vector3(0, 1, 0), 0.0f, new Vector3(scale, scale, scale)); } }
public void setSurfaceHeight(Object3D anObject3D) { //Re-written to utilize the "Lerp" function in order to better place an obj3D on a surface (JWF) // A-----B // | /| // | / | // C-----D float xA, yA, zA; float xB, yB, zB; float xC, yC, zC; float xD, yD, zD; float x, z; float xy, zy; float distA, distD; Vector3 A, B, C, D; //First, get the position of the object and position of its upper-left hand vertex x = anObject3D.Translation.X; xA = ((Int32)(x / terrain.Spacing)) * terrain.Spacing; z = anObject3D.Translation.Z; zA = ((Int32)(z / terrain.Spacing)) * terrain.Spacing; //With this information, we can now calculate the remaining 3 corners of the square xB = xA + terrain.Spacing; zB = zA; xC = xA; zC = zA + terrain.Spacing; xD = xB; zD = zC; yA = terrain.surfaceHeight((int)(xA / terrain.Spacing), (int)(zA / terrain.Spacing)); yB = terrain.surfaceHeight((int)(xB / terrain.Spacing), (int)(zB / terrain.Spacing)); yC = terrain.surfaceHeight((int)(xC / terrain.Spacing), (int)(zC / terrain.Spacing)); yD = terrain.surfaceHeight((int)(xD / terrain.Spacing), (int)(zD / terrain.Spacing)); A = new Vector3(xA, yA, zA); B = new Vector3(xB, yB, zB); C = new Vector3(xC, yC, zC); D = new Vector3(xD, yD, zD); //Now, we'll need to determine if we are in the top or bottom triangle distA = Vector2.Distance(new Vector2(A.X, A.Z), new Vector2(x, z)); distD = Vector2.Distance(new Vector2(D.X, D.Z), new Vector2(x, z)); if ( distA < distD ) //Top triangle { //From C -> D xy = Vector3.Lerp(A, B, ((float)(x - xA)) / Spacing).Y - A.Y; zy = Vector3.Lerp(A, C, ((float)(z - zA)) / Spacing).Y - A.Y; anObject3D.Translation = new Vector3(anObject3D.Translation.X, A.Y + xy + zy, anObject3D.Translation.Z); } else //Bottom triangle { //From C -> D xy = Vector3.Lerp(D, C, ((float)(xD- x)) / Spacing).Y - D.Y; zy = Vector3.Lerp(D, B, ((float)(zD - z)) / Spacing).Y - D.Y; anObject3D.Translation = new Vector3(anObject3D.Translation.X, D.Y + xy + zy, anObject3D.Translation.Z); } #if(false) float terrainHeight = terrain.surfaceHeight((int)(anObject3D.Translation.X / spacing), (int)(anObject3D.Translation.Z / spacing)); anObject3D.Translation = new Vector3(anObject3D.Translation.X, terrainHeight + 500, anObject3D.Translation.Z); #endif }
// Methods public bool isCollidable(Object3D obj3d) { if (collidable.Contains(obj3d)) return true; else return false; }
/// <summary> /// Create a new Object3D, place it on the stage, add to Model3D's instance collection, /// and if collidable add to collision collection. /// </summary> /// <param name="position"> location of new Object3D</param> /// <param name="orientAxis"> axis of rotation</param> /// <param name="radians"> rotation on orientAxis</param> /// <param name="scales"> size the Object3D</param> /// <returns> the new Object3D</returns> public Object3D addObject(Vector3 position, Vector3 orientAxis, float radians, Vector3 scales) { Object3D obj3d = new Object3D(stage, this, String.Format("{0}.{1}", name, instance.Count), position, orientAxis, radians, scales); //This update is needed for objects such as walls, trees, etc.. objects who have Model3D as parent obj3d.updateBoundingSphere(); //Add an instance of this object to the list instance.Add(obj3d); //If the object is collidable, also add it to the stages collidable list if (IsCollidable) stage.Collidable.Add(obj3d); return obj3d; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Create a new Object3D, place it on the stage, add to Model3D's instance collection, /// and if collidable add to collision collection. /// </summary> /// <param name="position"> location of new Object3D</param> /// <param name="orientAxis"> axis of rotation</param> /// <param name="radians"> rotation on orientAxis</param> /// <returns> the new Object3D</returns> public Object3D addObject(Vector3 position, Vector3 orientAxis, float radians) { Object3D obj3d = new Object3D(stage, this, String.Format("{0}.{1}", name, instance.Count), position, orientAxis, radians, Vector3.One); obj3d.updateBoundingSphere(); // need to do only once for Model3D instance.Add(obj3d); if (IsCollidable) stage.Collidable.Add(obj3d); return obj3d; }
public Camera(Stage aScene, Object3D anAgentObject, CameraEnum cameraType) { scene = aScene; agent = anAgentObject; cameraCase = cameraType; }