/// <summary> /// Models from users /// </summary> private void CreateAdditionalModels() { // create a temple Model3D m3d = new Model3D(this, "temple", "TempleV3"); m3d.IsCollidable = true; // must be set before addObject(...) and Model3D doesn't set it m3d.AddObject(new Vector3(340 * SPACING, terrain.SurfaceHeight(340, 340), 340 * SPACING), new Vector3(0, 1, 0), 0.79f); Components.Add(m3d); Model3D tajMahal = new Model3D(this, "Taj Mahal", "TajMahal"); tajMahal.IsCollidable = true; tajMahal.AddObject( new Vector3(LocationConstant.TAJ_MAHAL_X * SPACING, terrain.SurfaceHeight(LocationConstant.TAJ_MAHAL_X, LocationConstant.TAJ_MAHAL_Z) + 2500, LocationConstant.TAJ_MAHAL_Z * SPACING), new Vector3(0, 1, 0), 0.0f); Components.Add(tajMahal); Model3D rockBuilding = new Model3D(this, "Rock Building", "RockBuilding"); rockBuilding.IsCollidable = true; rockBuilding.AddObject( new Vector3(LocationConstant.ROCK_BUILDING_X * SPACING, terrain.SurfaceHeight(LocationConstant.ROCK_BUILDING_X, LocationConstant.ROCK_BUILDING_Z), LocationConstant.ROCK_BUILDING_Z * SPACING), new Vector3(0, 1, 0), 0.0f); Components.Add(rockBuilding); Model3D pineappleBuilding = new Model3D(this, "Pineapple Building", "PineappleBuilding"); pineappleBuilding.IsCollidable = true; pineappleBuilding.AddObject( new Vector3(LocationConstant.PINEAAPLE_X * SPACING, terrain.SurfaceHeight(LocationConstant.PINEAAPLE_X, LocationConstant.PINEAAPLE_Z), LocationConstant.PINEAAPLE_Z * SPACING), new Vector3(0, 1, 0), 0.0f); Components.Add(pineappleBuilding); }
// constructors /// <summary> /// Object that places and orients itself. /// </summary> /// <param name="theStage"> the stage containing object </param> /// <param name="aModel">how the object looks</param> /// <param name="label"> name of object </param> /// <param name="position"> position in stage </param> /// <param name="orientAxis"> axis to orient on </param> /// <param name="radians"> orientation rotation </param> public Object3D(Stage theStage, Model3D aModel, string label, Vector3 position, Vector3 orientAxis, float radians) { scales = Vector3.One; stage = theStage; model = aModel; name = label; step = 1; stepSize = 10; pitch = yaw = roll = 0.0f; orientation = Matrix.Identity; orientation *= Matrix.CreateFromAxisAngle(orientAxis, radians); orientation *= Matrix.CreateTranslation(position); ScaleObjectBoundingSphere(); }
/// <summary> /// Object that places, orients, and scales itself. /// </summary> /// <param name="theStage"> the stage containing object </param> /// <param name="aModel">how the object looks</param> /// <param name="label"> name of object </param> /// <param name="position"> position in stage </param> /// <param name="orientAxis"> axis to orient on </param> /// <param name="radians"> orientation rotation </param> /// <param name="objectScales">re-scale Model3D </param> public Object3D(Stage theStage, Model3D aModel, string label, Vector3 position, Vector3 orientAxis, float radians, Vector3 objectScales) { stage = theStage; name = label; scales = objectScales; model = aModel; step = 1; stepSize = 10; pitch = yaw = roll = 0.0f; // set object orientation /* * --------------------- * | Rx | Ry | Rz | Rw | right * --------------------- * | Ux | Uy | Uz | Uw | up * --------------------- * | Bx | By | Bz | Bw | backward = -forward * --------------------- * | Tx | Ty | Yz | Tw | translation * --------------------- */ orientation = Matrix.Identity; orientation *= Matrix.CreateScale(scales); orientation *= Matrix.CreateFromAxisAngle(orientAxis, radians); orientation *= Matrix.CreateTranslation(position); // scale it's bounding sphere ScaleObjectBoundingSphere(); }