Jump to content

  • Log In with Google      Sign In   
  • Create Account

Watermelon Chris

Member Since 07 Aug 2011
Offline Last Active Feb 20 2012 10:50 AM

Topics I've Started

Drawing a linelist... Error about vertex declaration/shader and normal0 missing.

19 February 2012 - 11:23 AM

Hey guys.

I'm stumped with this error 'The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing. It is occuring on this line: graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, gridVertices, 0, 6);


I've started a projet from scratch to try narrow down where I'm going wrong but no luck.

Basically what I'm trying to do is setup a 'grid'. (All points are calculated in the SetupGrid method). All the calculated vertices seem fine coordinate wise. Here's a copy of them either way:
  • + [0] {Position:{X:-10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [1] {Position:{X:-10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [2] {Position:{X:-5 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [3] {Position:{X:-5 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [4] {Position:{X:0 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [5] {Position:{X:0 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [6] {Position:{X:5 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [7] {Position:{X:5 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [8] {Position:{X:10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [9] {Position:{X:10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [10] {Position:{X:-10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [11] {Position:{X:10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [12] {Position:{X:-10 Y:0.5 Z:-5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [13] {Position:{X:10 Y:0.5 Z:-5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [14] {Position:{X:-10 Y:0.5 Z:0} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [15] {Position:{X:10 Y:0.5 Z:0} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [16] {Position:{X:-10 Y:0.5 Z:5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [17] {Position:{X:10 Y:0.5 Z:5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [18] {Position:{X:-10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
    + [19] {Position:{X:10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
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 DelXnaGrideLine
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
	    GraphicsDeviceManager graphics;
	    SpriteBatch spriteBatch;
	    BasicEffect effect;
	    VertexPositionColor[] gridVertices;
	    int gridLineCount;
	    private void SetupGrid(int width, int height, int lineCount, float yHeight, Color color)
	    {
		    gridLineCount = lineCount * 2;
		    gridVertices = new VertexPositionColor[lineCount * 4];
		    int xDiff = width / (lineCount - 1);
		    int zDiff = height / (lineCount - 1);
		    int xStart = -width / 2;
		    int xEnd = width / 2;
		    int zStart = -height / 2;
		    int zEnd = height / 2;
		    for (int x = 0; x < lineCount; x++)
		    {
			    gridVertices[x * 2] = new VertexPositionColor(
				    new Vector3(xStart + (x * xDiff), yHeight, zStart),
				    color);
			    gridVertices[x * 2 + 1] = new VertexPositionColor(
				    new Vector3(xStart + (x * xDiff), yHeight, zEnd),
				    color);
			   
		    }
		    int halfLine = lineCount * 2;
		    for (int z = 0; z < lineCount; z++)
		    {
			    gridVertices[halfLine + z * 2] = new VertexPositionColor(
				    new Vector3(xStart, yHeight, zStart + (z * xDiff)),
				    color);
			    gridVertices[halfLine + z * 2 + 1] = new VertexPositionColor(
				    new Vector3(xEnd, yHeight, zStart + (z * xDiff)),
				    color);
			    bool bob = true;
		    }
	    }
	    public Game1()
	    {
		    graphics = new GraphicsDeviceManager(this);
		    Content.RootDirectory = "Content";
	    }
	    protected override void Initialize()
	    {
		    base.Initialize();
	    }
	    protected override void LoadContent()
	    {
		    spriteBatch = new SpriteBatch(GraphicsDevice);
		    effect = new BasicEffect(GraphicsDevice);
		    effect.VertexColorEnabled = true;
		    effect.LightingEnabled = true;
		    SetupGrid(20, 20, 5, 0.5f, Color.Red);
	    }
	    protected override void UnloadContent()
	    {
	    }
	    protected override void Update(GameTime gameTime)
	    {
		    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
			    this.Exit();
		    base.Update(gameTime);
	    }
	    protected override void Draw(GameTime gameTime)
	    {
		    GraphicsDevice.Clear(Color.CornflowerBlue);
		    float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
		    Vector3  cameraPosition = new Vector3(1, 12, 3);
		    Vector3 cameraView = new Vector3(0.5f, 0.5f, 0.5f);
		    effect.View = Matrix.CreateLookAt(cameraPosition, cameraView, Vector3.Up);
		    effect.Projection = Matrix.CreatePerspectiveFieldOfView(
			    MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);
		    effect.World = Matrix.Identity;
		    effect.CurrentTechnique.Passes[0].Apply();
		    graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
			    PrimitiveType.LineList, gridVertices, 0, 6);
		    base.Draw(gameTime);
	    }
    }
}

Model artifacts in XNA from blender

18 February 2012 - 10:18 AM

Hey guys I'm getting strange artifacts in my model in xna.

The only thing I think could be causing it is the single walled 'bowl' the monkey is in. But it's effecting the face so I'm not sure.
It seems to be showing 'behind' vertices and hiding the ones infront. A culling issue?
Any ideas?

Heres my draw code:
Matrix[] transforms = new Matrix[monkey.Bones.Count];
		    float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
		    monkey.CopyAbsoluteBoneTransformsTo(transforms);
		    Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
		    Matrix view = Matrix.CreateLookAt(cameraPosition, cameraView, Vector3.Up);
		    foreach (ModelMesh mesh in monkey.Meshes)
		    {
			    foreach (BasicEffect effect in mesh.Effects)
			    {
				    effect.EnableDefaultLighting();
				    effect.View = view;
				    effect.Projection = projection;
				    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(monkeyPosition);
			    }
			    mesh.Draw();
		    }

Some questions about positioning/matricis/rotations

18 February 2012 - 06:37 AM

Hey guys...

Can someone please explain to me how the 'world matrix' relates to objects, I understand that a matrix is a equation/formula for translating/rotating/scaling operations. However, a model does not have a 'rotation' vector as far as I can see, so what is the matrix acting/translating on? Wouldeach object/model have it's own world matrix?

When you have a model you would like to rotate, should one keep a 'rotationX/Y/Z' variable in radion/degrees? How is the rotation 'state' stored?

Second question, I've encountred times when positioning my camera that if I have say the camera position vector3 set as (0, 5, 0), It won't display anytihng on screen. However if I add just a tiny increment to the x/z component the models will show on screen? Why does this happen?

Thank you!

XNA Access variables from base class in game component

06 November 2011 - 08:47 AM

Hey guys.
Can someone please inform me how I should be accessing variables from the base game class in a game component?
Or should I be passing it via the game component's constructor?

XNA Color in spritebatch

26 August 2011 - 02:05 PM

I've found some code that 'ghosts' an object/sprite. If anyone is interested: http://bobtacoindustries.com/developers/utils/ (It's near the bottom).

I've just got one line that I don't get
spriteBatch.Draw(previousSceneRenderTarget, Vector2.Zero, new Color(blendAmount, blendAmount, blendAmount, blendAmount));

It's the color part. I don't get what the Color parameter in Draw() does? A colour tint?

If we had the blendAmount at 128, it would create a gray colour with half transparency? Why is the white/gray/black ish component needed?

The 'trails' left behind the object are in colour just so you know.

PARTNERS