Jump to content
  • Advertisement

PrajayShetty_120286

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

100 Neutral

About PrajayShetty_120286

  • Rank
    Newbie
  1. PrajayShetty_120286

    Orientation

    how to move the model in direction of rotation thanks. thanks a lot
  2. PrajayShetty_120286

    Model Breaking

    i got the answer i just removed spritebatch.begin and spritebatch methods and add them in the last and it worked
  3. PrajayShetty_120286

    Model Breaking

    Hii, Mine Model is breaking when i am moving it why is it so ... please help using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Avtars { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Matrix world=Matrix.Identity; Model sphere; Model ground; SpriteFont sf; String str = ""; Matrix []bones; Matrix []original; int index = 0; Song song; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); sphere = this.Content.Load<Model>("tank"); sf = this.Content.Load<SpriteFont>("SpriteFont1"); bones = new Matrix[sphere.Bones.Count]; original = new Matrix[sphere.Bones.Count]; sphere.CopyAbsoluteBoneTransformsTo(original); song=this.Content.Load<Song>("videoplayback"); ground = this.Content.Load<Model>("Ground"); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { MediaPlayer.Stop(); // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Right)) { sphere.CopyAbsoluteBoneTransformsTo(bones); index = sphere.Bones["l_back_wheel_geo"].Index; mediaplayer(); sphere.Bones[index].Transform = Matrix.CreateRotationX(0.1f) * sphere.Bones[index].Transform; index = sphere.Bones["r_back_wheel_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationX(0.1f) * sphere.Bones[index].Transform; index = sphere.Bones["l_front_wheel_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationX(0.1f) * sphere.Bones[index].Transform; index = sphere.Bones["r_front_wheel_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationX(0.1f) * sphere.Bones[index].Transform; index = sphere.Bones["l_front_wheel_geo"].Index; str = "pressed Backward"; } else if (Keyboard.GetState().IsKeyDown(Keys.Left)) { sphere.CopyAbsoluteBoneTransformsTo(bones); index = sphere.Bones["l_back_wheel_geo"].Index; sphere.Bones[index].Transform =Matrix.Identity* Matrix.CreateRotationX(-0.1f) * sphere.Bones[index].Transform*Matrix.CreateTranslation(0,0,1); index = sphere.Bones["r_back_wheel_geo"].Index; sphere.Bones[index].Transform =Matrix.Identity* Matrix.CreateRotationX(-0.1f) * sphere.Bones[index].Transform*Matrix.CreateTranslation(0,0,1); index = sphere.Bones["l_front_wheel_geo"].Index; sphere.Bones[index].Transform = Matrix.Identity*Matrix.CreateRotationX(-0.1f) * sphere.Bones[index].Transform*Matrix.CreateTranslation(0,0,1); index = sphere.Bones["r_front_wheel_geo"].Index; sphere.Bones[index].Transform =Matrix.Identity* Matrix.CreateRotationX(-0.1f) * sphere.Bones[index].Transform; index = sphere.Bones["l_front_wheel_geo"].Index; world =world* Matrix.CreateTranslation(0, 0, 1); index = sphere.Bones["l_steer_geo"].Index; sphere.Bones[index].Transform = sphere.Bones[index].Transform*Matrix.CreateTranslation(0,0,1); index = sphere.Bones["turret_geo"].Index; sphere.Bones[index].Transform =sphere.Bones[index].Transform*Matrix.CreateTranslation(0,0,1); str = "pressed Forward"; mediaplayer(); } else if (Keyboard.GetState().IsKeyDown(Keys.Q)) { world = world* Matrix.CreateRotationX(0.1f); str = "Rotation ON Positive X Axis"; } else if (Keyboard.GetState().IsKeyDown(Keys.W)) { world = world* Matrix.CreateRotationX(-0.1f); str = "Rotation on Negative X Axis"; }else if(Keyboard.GetState().IsKeyDown(Keys.Enter)){ world = Matrix.Identity; mediaplayer(); } else if(Keyboard.GetState().IsKeyDown(Keys.Up)){ world = world* Matrix.CreateRotationZ(0.1f); str = "Rotating on Y Axis"; } else if (Keyboard.GetState().IsKeyDown(Keys.Down)) { world = world * Matrix.CreateRotationZ(-0.1f); str = "Rotating on Negative Yaxis"; } else if (Keyboard.GetState().IsKeyDown(Keys.E)) { index = sphere.Bones["l_steer_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(0.1f) * sphere.Bones[index].Transform; str = "Steering Right"; } else if (Keyboard.GetState().IsKeyDown(Keys.R)) { index = sphere.Bones["l_steer_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(-0.1f) * sphere.Bones[index].Transform; str = "Steering Left"; } else if (Keyboard.GetState().IsKeyDown(Keys.Y)) { index = sphere.Bones["turret_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(0.1f) * sphere.Bones[index].Transform; str = "Turrent Right"; } else if (Keyboard.GetState().IsKeyDown(Keys.T)) { index = sphere.Bones["turret_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(-0.1f) * sphere.Bones[index].Transform; str = "Turrent Left"; } else if (Keyboard.GetState().IsKeyDown(Keys.I) ){ index = sphere.Bones["canon_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(0.1f) * sphere.Bones[index].Transform; str = "Cannon Left Pressed"; } else if (Keyboard.GetState().IsKeyDown(Keys.O)) { index = sphere.Bones["canon_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(-0.1f) * sphere.Bones[index].Transform; str = "Cannon Right Pressed"; } else if (Keyboard.GetState().IsKeyDown(Keys.P)) { index = sphere.Bones["hatch_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(0.1f) * sphere.Bones[index].Transform; str = "Cannon Left Pressed"; } else if (Keyboard.GetState().IsKeyDown(Keys.Insert)) { index = sphere.Bones["hatch_geo"].Index; sphere.Bones[index].Transform = Matrix.CreateRotationY(-0.1f) * sphere.Bones[index].Transform; str = "Cannon Right Pressed"; } else { if (MediaPlayer.State == MediaState.Playing) { MediaPlayer.Pause(); } str = "tank game"; } // TODO: Add your update logic here base.Update(gameTime); } private void mediaplayer() { if (MediaPlayer.State == MediaState.Stopped) { MediaPlayer.Play(song); MediaPlayer.IsRepeating = true; } else if (MediaPlayer.State == MediaState.Paused) { MediaPlayer.Stop(); MediaPlayer.Resume(); } } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); Matrix mi = Matrix.CreateLookAt(new Vector3(1000, 500, 0), new Vector3(0, 150, 0), Vector3.Up); // TODO: Add your initialization code here List<ModelBone> si = sphere.Bones.ToList(); spriteBatch.Begin(); spriteBatch.DrawString(sf,str,new Vector2(0,0),Color.CornflowerBlue); Matrix identity = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.DisplayMode.AspectRatio, 20.0f, 1000.0f); sphere.CopyBoneTransformsTo(bones); this.Window.Title = str; sphere.Root.Transform=world; foreach (ModelMesh mesh in sphere.Meshes) { foreach (Effect es in mesh.Effects) { BasicEffect bs = es as BasicEffect; bs.EnableDefaultLighting(); bs.World = world; } } ground.Draw(world, mi, identity); sphere.Draw(world, mi, identity); spriteBatch.End(); } } }
  4. using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Avtar { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Model sphere; Matrix world=Matrix.Identity; SpriteFont sf; int curx; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> /// protected override void Update(GameTime gameTime) { KeyboardState gc = Keyboard.GetState(); if (gc.IsKeyDown(Keys.A)) { world = calculateA(); } base.Update(gameTime); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); sphere = this.Content.Load<Model>("tiger"); // TODO: use this.Content to load your game content here sf = this.Content.Load<SpriteFont>("SpriteFont1"); } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.Deferred,null); spriteBatch.DrawString(sf, world.ToString(), new Vector2(0, 0), Color.White); spriteBatch.End(); Matrix mi = Matrix.CreateLookAt(new Vector3(-10, 0, 0), Vector3.Zero, Vector3.Up); // TODO: Add your initialization code here Matrix identity = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), GraphicsDevice.DisplayMode.AspectRatio, 0.1f, 100.0f); foreach (ModelMesh mis in sphere.Meshes) { foreach (BasicEffect bs in mis.Effects) { bs.EnableDefaultLighting(); bs.World = world; bs.View = mi; bs.Projection = identity; foreach (EffectPass pass in bs.CurrentTechnique.Passes) { pass.Apply(); } } mis.Draw(); } // TODO: Add your drawing code here base.Draw(gameTime); } public Matrix calculateA() { Vector3 x = new Vector3(1,0,0); x.Normalize(); //Up Vector Vector3 y = new Vector3(0,1,0); y.Normalize(); Vector3 z = Vector3.Cross(x, y); z.Normalize(); Matrix YRot = new Matrix(); YRot.Right = x; YRot.Up = y; YRot.Backward = z; return Matrix.Identity * YRot; } } } i am unable to see mine tiger on the screen whats the problem in it , am i creating the orientation matrix properly.. , am i using this perfectly z=cros(x,y) is this logic correct please help me please tell me how do i create mine world matrix if i have to move from one postion to another in same direction ,is this method correct , sorry ,this is mine first post
  5. PrajayShetty_120286

    World Matrix,

    Hii everyone, i am new to this forum Can any one please explain me how do i create a world matrix so that i can draw mine model on to the screen using vectors method in xna . I mean i need to move from one point to another point but with direction maintained i. i know we should use I.S.R.O.T sequence .Do explain me using vectors method or give me a tuitorial link will do . I need it for 3d model space . A depth or short explanation will do just i need to understant the math logic behind it .
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!