public void UpdateTankStuff(KeyboardState keyboard, ClsBattlefield terreno) { //Controlo da torre if (keyboard.IsKeyDown(Keys.Left)) { turretAngle += MathHelper.ToRadians(yaw); } if (keyboard.IsKeyDown(Keys.Right)) { turretAngle -= MathHelper.ToRadians(yaw); } if (keyboard.IsKeyDown(Keys.Up)) { canonAngle -= MathHelper.ToRadians(yaw); } if (keyboard.IsKeyDown(Keys.Down)) { canonAngle += MathHelper.ToRadians(yaw); } //Controlo do movimento if (keyboard.IsKeyDown(Keys.A)) { directionTank = Vector3.Transform(directionTank, Matrix.CreateRotationY(yaw)); } if (keyboard.IsKeyDown(Keys.D)) { directionTank = Vector3.Transform(directionTank, Matrix.CreateRotationY(-yaw)); } if (keyboard.IsKeyDown(Keys.W)) { positionTank = positionTank - directionTank * speedTank; positionTank.Y = terreno.Interpolacao(positionTank.X, positionTank.Z); //normalTank = terreno.GetNormals((int)positionTank.X, (int)positionTank.Z); } if (keyboard.IsKeyDown(Keys.S)) { positionTank = positionTank + directionTank * speedTank; positionTank.Y = terreno.Interpolacao(positionTank.X, positionTank.Z); //normalTank = terreno.GetNormals((int)positionTank.X, (int)positionTank.Z); } }
public void UpdateCameraPositionSurfaceFollow(ClsBattlefield terreno, KeyboardState keyboardState) { MouseState mousestate = Mouse.GetState(); pitch = MathHelper.ToRadians(mousestate.Y * 0.1f); Matrix pitchRotation = Matrix.CreateFromYawPitchRoll(yaw, pitch, 0.0f); if (keyboardState.IsKeyDown(Keys.NumPad4)) { speed = Vector3.Transform(speed, Matrix.CreateRotationY(yaw)); } if (keyboardState.IsKeyDown(Keys.NumPad6)) { speed = Vector3.Transform(speed, Matrix.CreateRotationY(-yaw)); } //Matrix yawRotation = Matrix.CreateRotationY(yaw); //Vector3 dir = speed; //dir.Normalize(); //yawRotation.Forward = dir; //yawRotation.Up = Vector3.UnitY; //yawRotation.Right = Vector3.Cross(dir, Vector3.UnitY); //view = yawRotation * Matrix.CreateTranslation(posicao); //direcao = Vector3.Transform(directionBase, yawRotation); if (keyboardState.IsKeyDown(Keys.NumPad8)) { posicao = posicao + speed; alturaCam = terreno.Interpolacao(posicao.X, posicao.Z); posicao.Y = alturaCam + offSetChao; } if (keyboardState.IsKeyDown(Keys.NumPad2)) { posicao = posicao - speed; alturaCam = terreno.Interpolacao(posicao.X, posicao.Z); posicao.Y = alturaCam + offSetChao; } view = Matrix.CreateLookAt(posicao, posicao + speed, Vector3.Up); }
public TankClass(GraphicsDevice device, ContentManager content, ClsBattlefield terreno) { modelTank = content.Load <Model>("tank"); world = terreno.matrixTerreno; effect = new BasicEffect(device); view = Matrix.CreateLookAt(new Vector3(1.0f, 2.0f, 2.0f), Vector3.Zero, Vector3.Up); float aspectRatio = (float)device.Viewport.Width / device.Viewport.Height; projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 2.0f, 1000.0f); turretBone = modelTank.Bones["turret_geo"]; canonBone = modelTank.Bones["canon_geo"]; rEngineBone = modelTank.Bones["r_engine_geo"]; lEngineBone = modelTank.Bones["l_engine_geo"]; rBackWheelBone = modelTank.Bones["r_back_wheel_geo"]; lBackWheelBone = modelTank.Bones["l_back_wheel_geo"]; rSteerBone = modelTank.Bones["r_steer_geo"]; lSteerBone = modelTank.Bones["l_steer_geo"]; rFrontWheelBone = modelTank.Bones["r_front_wheel_geo"]; lFrontWheelBone = modelTank.Bones["l_front_wheel_geo"]; hatchBone = modelTank.Bones["hatch_geo"]; turretTransform = turretBone.Transform; canonTransform = canonBone.Transform; rEngineTransform = rEngineBone.Transform; lEngineTransform = lEngineBone.Transform; rBackWheelTranform = rBackWheelBone.Transform; lBackWheelTransform = rBackWheelBone.Transform; rSteerTransform = rSteerBone.Transform; lSteerTransform = lSteerBone.Transform; rFrontWheelTransform = rFrontWheelBone.Transform; lFrontWheelTransform = lFrontWheelBone.Transform; hatchTransform = hatchBone.Transform; boneTransforms = new Matrix[modelTank.Bones.Count]; directionTank = Vector3.UnitX; //Inicialização do tanque PositionTank = new Vector3(64.0f, terreno.Interpolacao(PositionTank.X, PositionTank.Z), 64.0f); NormalTank = terreno.GetNormals((int)PositionTank.X, (int)PositionTank.Z); DirectionTank = Vector3.UnitX; SpeedTank = 0.5f; }
public void Draw(Matrix camview, ClsBattlefield terreno) { Matrix translation = Matrix.CreateTranslation(positionTank.X, terreno.Interpolacao(positionTank.X, positionTank.Z), positionTank.Z); Matrix rotation = Matrix.CreateRotationY(yaw); normalTank = terreno.GetNormals((int)positionTank.X, (int)positionTank.Z); //Matrix rotation = Matrix.Identity; rotation.Up = normalTank; rotation.Forward = directionTank; rotation.Right = Vector3.Cross(normalTank, directionTank); world = rotation * translation; modelTank.Root.Transform = Matrix.CreateScale(0.005f) * world; turretBone.Transform = Matrix.CreateRotationY(turretAngle) * turretTransform; canonBone.Transform = Matrix.CreateRotationX(canonAngle) * canonTransform; //lEngineBone.Transform = Matrix.CreateTranslation(positionTank) * lEngineTransform; //rEngineBone.Transform = Matrix.CreateTranslation(positionTank) * rEngineTransform; //hatchBone.Transform = Matrix.CreateTranslation() * hatchTransform; modelTank.CopyAbsoluteBoneTransformsTo(boneTransforms); foreach (ModelMesh mesh in modelTank.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = boneTransforms[mesh.ParentBone.Index]; effect.View = camview; effect.Projection = projection; effect.EnableDefaultLighting(); } // Draw each mesh of the model mesh.Draw(); } }