The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Graphic & Game Programming > XNA Development


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , , , , ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 09-14-2007, 07:16 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Icon13 Drawing Mesh Please Help!!!

PHP Code:
        #region Variables

        
Model shipModel;
        
Vector3 cameraPosition = new Vector3(0.0f5000.0f0.0f);
        
Vector3 shipPosition Vector3.Zero;

        
#endregion

/// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        
public override void Draw(GameTime gameTime)
        {
            
// This game has a blue background. Why? Because!
            
ScreenManager.GraphicsDevice.Clear(ClearOptions.TargetColor.CornflowerBlue00);

            
Matrix[] transforms = new Matrix[shipModel.Bones.Count];
            
shipModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (
ModelMesh mesh in shipModel.Meshes)
            {
                foreach (
BasicEffect effect in mesh.Effects)
                {
                    
effect.EnableDefaultLighting();
                    
effect.World transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(shipPosition);
                    
effect.View Matrix.CreateLookAt(cameraPositionVector3.ZeroVector3.Up);
                    
Matrix projection Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), (800.0f 600.0f), 10.0f10000.0f);
                }
                
mesh.Draw();
            }

            
// If the game is transitioning on or off, fade it out to black.
            
if (TransitionPosition 0)
                
ScreenManager.FadeBackBufferToBlack(255 TransitionAlpha);
        } 
I need help on drawing mesh, I just want to make sure if this Draw() code will work...??? I used this code to just draw the model rotation, however, it doesn't appear on my game for some reason... I got some edits on it... I want it to be seen from the top instead, not really close as the sample.. Thanx if anybody could help...

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 09-14-2007, 07:34 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
In case if you're curious, here's the entire code:

PHP Code:
#region File Description
//-----------------------------------------------------------------------------
// GameplayScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace GameStateManagement
{
    
/// <summary>
    /// This screen implements the actual game logic. It is just a
    /// placeholder to get the idea across: you'll probably want to
    /// put some more interesting gameplay in here!
    /// </summary>
    
class GameplayScreen GameScreen
    
{
        
#region Fields

        
ContentManager content;
        
SpriteFont gameFont;

        
Vector2 playerPosition = new Vector2(100100);
        
Vector2 enemyPosition = new Vector2(100100);

        
Random random = new Random();

        
#region Variables

        
Model shipModel;
        
Vector3 cameraPosition = new Vector3(0.0f5000.0f0.0f);
        
Vector3 shipPosition Vector3.Zero;

        
#endregion

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        
public GameplayScreen()
        {
            
TransitionOnTime TimeSpan.FromSeconds(1.5);
            
TransitionOffTime TimeSpan.FromSeconds(0.5);
        }


        
/// <summary>
        /// Load graphics content for the game.
        /// </summary>
        
public override void LoadGraphicsContent(bool loadAllContent)
        {
            if (
loadAllContent)
            {
                if (
content == null)
                    
content = new ContentManager(ScreenManager.Game.Services);

                
gameFont content.Load<SpriteFont>("Content/gamefont");
                
shipModel content.Load<Model>("Models/p1_wedge");

                
// A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                
Thread.Sleep(1000);
            }
        }


        
/// <summary>
        /// Unload graphics content used by the game.
        /// </summary>
        
public override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (
unloadAllContent)
                
content.Unload();
        }


        
#endregion

        #region Update and Draw


        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        
public override void Update(GameTime gameTimebool otherScreenHasFocusbool coveredByOtherScreen)
        {
            
base.Update(gameTimeotherScreenHasFocuscoveredByOtherScreen);

            if (
IsActive)
            {
                
// Apply some random jitter to make the enemy move around.
                
const float randomization 10;

                
enemyPosition.+= (float)(random.NextDouble() - 0.5) * randomization;
                
enemyPosition.+= (float)(random.NextDouble() - 0.5) * randomization;

                
// Apply a stabilizing force to stop the enemy moving off the screen.
                
Vector2 targetPosition = new Vector2(200200);

                
enemyPosition Vector2.Lerp(enemyPositiontargetPosition0.05f);

                
// TODO: this game isn't very fun! You could probably improve
                // it by inserting something more interesting in this space :-)
            
}
        }


        
/// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        
public override void HandleInput(InputState input)
        {
            if (
input == null)
                
throw new ArgumentNullException("input");

            if (
input.PauseGame)
            {
                
// If they pressed pause, bring up the pause menu screen.
                
ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                
// Otherwise move the player position.
                
const float movementSpeed 2;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Left))
                    
playerPosition.-= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Right))
                    
playerPosition.+= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Up))
                    
playerPosition.-= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Down))
                    
playerPosition.+= movementSpeed;

                
Vector2 thumbstick input.CurrentGamePadState.ThumbSticks.Left;

                
playerPosition.+= thumbstick.movementSpeed;
                
playerPosition.-= thumbstick.movementSpeed;
            }
        }


        
/// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        
public override void Draw(GameTime gameTime)
        {
            
// This game has a blue background. Why? Because!
            
ScreenManager.GraphicsDevice.Clear(ClearOptions.TargetColor.CornflowerBlue00);

            
Matrix[] transforms = new Matrix[shipModel.Bones.Count];
            
shipModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (
ModelMesh mesh in shipModel.Meshes)
            {
                foreach (
BasicEffect effect in mesh.Effects)
                {
                    
effect.EnableDefaultLighting();
                    
effect.World transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(shipPosition);
                    
effect.View Matrix.CreateLookAt(cameraPositionVector3.ZeroVector3.Up);
                    
Matrix projection Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), (800.0f 600.0f), 10.0f10000.0f);
                }
                
mesh.Draw();
            }

            
// If the game is transitioning on or off, fade it out to black.
            
if (TransitionPosition 0)
                
ScreenManager.FadeBackBufferToBlack(255 TransitionAlpha);
        }


        
#endregion
    
}

I really need help on this for some reason it doesn't show anything!!! sigh... I think there's something wrong with the aspect ratio...?

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 09-15-2007, 01:59 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Found the solution! Please mark this thread as SOLVED if you'd like

the Up Vector must be Vector3.Forward
Although I'm now still trying to understand on how does the Up Vector do in my program, but eventually I'll figure it out... Does anybody would like to tell me what is Up Vector with your understanding...?

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 09-15-2007, 09:43 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Never mind, still not working properly lol....

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 01:09 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50