public void update(GameObject target) { cameraTarget = target.position; cameraPosition = target.position + Vector3.Transform(new Vector3(0, 0, mDistance + distanceOffset ), Matrix.CreateRotationX(mHeight / 60f) * Matrix.CreateRotationY(target.rotation)); ; cameraView = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up); }
bool CheckForCollisions(GameObject c1, GameObject c2) { //foreach (ModelMesh mesh in c1.model.Model.Meshes) //{ //Matrix transform1 = c1.animationController..SkinnedBoneTransforms[mesh.ParentBone.Index]; //Vector3 translation1 = transform1.Translation; //foreach (ModelMesh otherMesh in c2.model.Model.Meshes) //{ //Matrix transform2 = c2.animationController.SkinnedBoneTransforms[otherMesh.ParentBone.Index]; //Vector3 translation2 = transform2.Translation; BoundingSphere b1 = new BoundingSphere(c1.position, c1.radius); BoundingSphere b2 = new BoundingSphere(c2.position, c2.radius); if (b1.Intersects(b2)) { return true; } //} //} return false; }
void DrawModel(GameObject item) { foreach (ModelMesh modelMesh in item.model.Model.Meshes) { foreach (SkinnedModelBasicEffect effect in modelMesh.Effects) { // Setup camera effect.View = camera.cameraView; effect.Projection = camera.cameraProjection; effect.World = Matrix.CreateRotationY(item.rotation) * Matrix.CreateScale(item.scale) * Matrix.CreateTranslation(item.position); // Set the animated bones to the model effect.Bones = item.animationController.SkinnedBoneTransforms; // OPTIONAL - Configure material effect.Material.DiffuseColor = new Vector3(0.8f); effect.Material.SpecularColor = new Vector3(0.3f); effect.Material.SpecularPower = 8; // OPTIONAL - Configure lights effect.AmbientLightColor = new Vector3(0.1f); effect.LightEnabled = true; effect.EnabledLights = EnabledLights.One; effect.PointLights[0].Color = Vector3.One; effect.PointLights[0].Position = new Vector3(100); } // Draw a model mesh modelMesh.Draw(); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up the reference grid and sample camera grid = new SampleGrid(); grid.GridColor = Color.LimeGreen; grid.GridScale = 10.0f; grid.GridSize = 32; grid.LoadGraphicsContent(graphics.GraphicsDevice); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Fonts/Courier New"); mDottedLine = Content.Load<Texture2D>("DottedLine"); foreach (Dictionary<string,string> item in assets) { GameObject t = new GameObject(); t.model = Content.Load<SkinnedModel>(item["assets_model"]); t.id = int.Parse(item["assets_id"]); t.position.X = float.Parse(item["assets_position_x"]); t.position.Y = float.Parse(item["assets_position_y"]); t.position.Z = float.Parse(item["assets_position_z"]); t.assignPosition.X = float.Parse(item["assets_position_x"]); t.assignPosition.Y = float.Parse(item["assets_position_y"]); t.assignPosition.Z = float.Parse(item["assets_position_z"]); t.scale = float.Parse(item["assets_scale"]); t.rotation = float.Parse(item["assets_rotation"]); t.assignRotation = float.Parse(item["assets_rotation"]); t.radius = float.Parse(item["assets_radius"]); t.health = float.Parse(item["assets_health"]); t.hitspeed = float.Parse(item["assets_hitspeed"]); t.init(); model.Add(t); } /* foreach (string item in models) { GameObject t = new GameObject(); t.model = Content.Load<SkinnedModel>(item); t.init(); model.Add(t); }*/ Vector3 randPos = getFreePos(assets); //System.Diagnostics.Trace.WriteLine(randPos); tmodel.model = Content.Load<SkinnedModel>("Models/biped"); tmodel.position = new Vector3(0f, 0f, -150f); tmodel.scale = 2f; tmodel.position = tmodel.assignPosition = tmodel.prevPosition = randPos; if (arguments.Length > 0) { tmodel.model = model[int.Parse(arguments[0])].model; tmodel.position = model[int.Parse(arguments[0])].position; tmodel.prevPosition = model[int.Parse(arguments[0])].position; tmodel.assignPosition = model[int.Parse(arguments[0])].position; tmodel.scale = model[int.Parse(arguments[0])].scale; tmodel.rotation = model[int.Parse(arguments[0])].rotation; tmodel.assignRotation = model[int.Parse(arguments[0])].rotation; tmodel.id = model[int.Parse(arguments[0])].id; model.RemoveAt(int.Parse(arguments[0])); } else { lastId = connect.insertquery("INSERT INTO `runecrafter_assets` (`assets_model` ,`assets_position_x` ,`assets_position_y` ,`assets_position_z` ,`assets_scale` ,`assets_radius` ,`assets_health` ,`assets_hitspeed`) " + "VALUES (" + "'Models/biped', '" + randPos.X + "', '" + randPos.Y + "', '" + randPos.Z + "', '2', '10', '5', '2'" + ");"); tmodel.id = Convert.ToInt32( lastId); } tmodel.init(); //model[0].position = new Vector3(50f, 0f, 50f); //grid requires a projection matrix to draw correctly grid.ProjectionMatrix = camera.cameraProjection; //Set the grid to draw on the x/z plane around the origin grid.WorldMatrix = Matrix.Identity; }