Jump to content
  • Advertisement

manderson

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

100 Neutral

About manderson

  • Rank
    Newbie
  1. manderson

    beginner error?

    Ok. After of hours of trawling thru the code, I still cannot find what is up with it. Am I taking the correct tack with this? Or do I need to completely revisit how I am doing it? Or have I gone and done something daft? My model is just a basic cube, exported as fbx from blender.
  2. manderson

    beginner error?

    Is my problem because my model is stored and drawn outside the game class?
  3. manderson

    Ahoyy! - Assistance Requested

    It is better to get a grasp of the underlying language, not just by reading and following tutorials, but by experimentation. There are many aspects of a langauge that you will not cover in tutorials, books, or even a classroom. You need to push yourself. Try making an desktop app, in OOP that will provide a lot of insight into how things tie together, try text processing, reading from files, basic animation (moving squares around), creating libraries, keyboard input, raising events, build a calculator etc All of these will assist in transition into any form of programming, and the logic experience will help you progress into creating whatever you want. And always remember... The documentation is your friend. You will learn more from finding the answer through trial and error then by just asking for an answer... Unless you have exhausted every idea.
  4. manderson

    Ahoyy! - Assistance Requested

    Have a look at reimers xna tutorials. It's c# but gives a decent overview of game programming, and u get some instant results
  5. manderson

    beginner error?

    I have put together xna code to draw a room made up of cubes. The code is at http://pastebin.com/csJGw3z5 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 theCube { public abstract class Camera { //public BoundingFrustum Frustum { get; private set; } //public Matrix View { get; set; } //public Matrix Projection { get; set; } protected GraphicsDevice GraphicsDevice { get; set; } Matrix view; Matrix projection; public Matrix Projection { get { return projection; } protected set { projection = value; // generateFrustum(); } } public Matrix View { get { return view; } protected set { view = value; // generateFrustum(); } } //private void generateFrustum() //{ // Matrix viewProjection = View * Projection; // Frustum = new BoundingFrustum(viewProjection); //} //public bool BoundingVolumeIsInView(BoundingSphere sphere) //{ // return (Frustum.Contains(sphere) != ContainmentType.Disjoint); //} //public bool BoundingVolumeIsInView(BoundingBox box) //{ // return (Frustum.Contains(box) != ContainmentType.Disjoint); //} public Camera(GraphicsDevice graphicsDevice) { this.GraphicsDevice = graphicsDevice; generatePerspectiveProjectionMatrix(MathHelper.PiOver4); } private void generatePerspectiveProjectionMatrix(float FieldOfView) { PresentationParameters pp = GraphicsDevice.PresentationParameters; float aspectRatio = (float)pp.BackBufferWidth /(float)pp.BackBufferHeight; this.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 10000.0f); } public virtual void Update() { } } public class FreeCamera : Camera { public float Yaw { get; set; } public float Pitch { get; set; } public Vector3 Position { get; set; } public Vector3 Target { get; private set; } private Vector3 translation; public FreeCamera(Vector3 Position, float Yaw, float Pitch, GraphicsDevice graphicsDevice) : base(graphicsDevice) { this.Position = Position; this.Yaw = Yaw; this.Pitch = Pitch; translation = Vector3.Zero; } public void Rotate(float YawChange, float PitchChange) { this.Yaw += YawChange; this.Pitch += PitchChange; // Console.WriteLine("Yaw:" + Yaw); // Console.WriteLine("Pitch:" + Pitch); } public void Move(Vector3 Translation) { //Console.WriteLine(Translation); this.translation += Translation; Console.WriteLine(this.Position); } public override void Update() { // Calculate the rotation matrix Matrix rotation = Matrix.CreateFromYawPitchRoll(Yaw, Pitch, 0); // Offset the position and reset the translation translation = Vector3.Transform(translation, rotation); Position += translation; translation = Vector3.Zero; // Calculate the new target Vector3 forward = Vector3.Transform(Vector3.Forward, rotation); Target = Position + forward; // Calculate the up vector Vector3 up = Vector3.Transform(Vector3.Up, rotation); // Calculate the view matrix View = Matrix.CreateLookAt(Position, Target, up); } } } 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 theCube { class CubeBase:Microsoft.Xna.Framework.GameComponent { public Vector3 Position {get; set;} public Vector3 Rotation {get; set;} public Vector3 Scale {get; set;} public Model Model { get; private set; } private Matrix[] modelTransforms; private GraphicsDevice graphicsDevice; Matrix view; Matrix projection; private BoundingBox boundingBox; GraphicsDevice device; //Matrix localWorld; public CubeBase(Game game) : base(game) { device = game.GraphicsDevice; this.Model=game.Content.Load<Model>("cube") ; } public void Initiate() { try { Initiate(Position,Rotation,Scale,device); } catch { throw new Exception("Position,Rotation,Scale not set"); } } public void Initiate(Vector3 pos,Vector3 rot,Vector3 sca,GraphicsDevice graphicsDevice) { this.Position = pos; this.Rotation = rot; this.Scale=sca; this.graphicsDevice = graphicsDevice; modelTransforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo(modelTransforms); // buildBoundingBox(); } public void Draw(Matrix view, Matrix Projection) { Matrix baseWorld = Matrix.CreateScale (Scale) * Matrix.CreateFromYawPitchRoll(Rotation.Y,Rotation.X,Rotation.Z) * Matrix.CreateTranslation(Position); foreach(ModelMesh mesh in Model.Meshes) { Matrix localWorld=modelTransforms[mesh.ParentBone.Index] * baseWorld; foreach(ModelMeshPart part in mesh.MeshParts) { BasicEffect eff = (BasicEffect)part.Effect; eff.World= localWorld; eff.View = view; eff.Projection = projection; eff.EnableDefaultLighting(); } mesh.Draw(); } } }//close namespace 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 theCube { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { Camera camera; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Dictionary<Vector3,CubeBase> cubes = new Dictionary<Vector3,CubeBase>(); int roomSize=40; MouseState lastMouseState; Vector3 oldTrans; int spread; Vector3 rotation = new Vector3(0,0,0); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } void buildRoom() { spread = roomSize / 2; for(int x=-spread;x<=spread;x++) { for(int y=-spread;y<=spread;y++) { for(int z=-spread;z<=spread;z++) { if(x==-spread||x==spread||y==-spread||y==spread||z==-spread||z==spread) { Vector3 position = new Vector3(x,y,z); // Vector3 rotation = new Vector3(0,0,0); Vector3 scale = new Vector3(1,1,1); cubes.Add(position,new CubeBase(this)); cubes[position].Initiate(position, rotation, scale, GraphicsDevice); //Console.WriteLine (cubes[position].Position+ " " +cubes[position].Model.Bones.Count) ; } } } } } void updateCamera(GameTime gameTime) { // Get the new keyboard and mouse state MouseState mouseState = Mouse.GetState(); KeyboardState keyState = Keyboard.GetState(); // Determine how much the camera should turn float deltaX = (float)lastMouseState.X - (float)mouseState.X; float deltaY = (float)lastMouseState.Y - (float)mouseState.Y; // Rotate the camera ((FreeCamera)camera).Rotate(deltaX * .01f, deltaY * .01f); Vector3 translation = Vector3.Zero; // Determine in which direction to move the camera if (keyState.IsKeyDown(Keys.W)) translation += Vector3.Forward; if (keyState.IsKeyDown(Keys.S)) translation += Vector3.Backward; if (keyState.IsKeyDown(Keys.A)) translation += Vector3.Left; if (keyState.IsKeyDown(Keys.D)) translation += Vector3.Right; // Move 3 units per millisecond, independent of frame rate translation *= (float)gameTime.ElapsedGameTime.TotalMilliseconds; // Move the camera if (translation != oldTrans) { ((FreeCamera)camera).Move(translation); // Update the camera camera.Update(); // Update the mouse state } oldTrans = translation; lastMouseState = mouseState; } /// <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); buildRoom(); SetUpCamera(); GameTime g = new GameTime(); base.Draw(g); // 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() { // 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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here updateCamera(gameTime); base.Update(gameTime); } /// <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); int nModelsDrawn; foreach(KeyValuePair<Vector3,CubeBase>cube in cubes) { //if (camera.BoundingVolumeIsInView(cube.Value.BoundingBox)) //{ nModelsDrawn++; cube.Value.Draw(camera.View, camera.Projection); //} } //if (nModelsDrawn == 0) //{ // GraphicsDevice.Clear(Color.Red); //} base.Draw(gameTime); } public void SetUpCamera() { camera = new FreeCamera(new Vector3(6,6,6), MathHelper.ToRadians(153), // Turned around 153 degrees MathHelper.ToRadians(5), GraphicsDevice); } } } Could someone tell me what is missing? I just get an empty view. I have tried debugging it, and I cannot see what is wrong, so I must have missed something out entirely. Thanks
  6. I have put together xna code to draw a room made up of cubes. The code is at http://pastebin.com/csJGw3z5 Could someone tell me what is missing? I just get an empty view. Thanks
  • 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!