Preston Moore

I'm trying to use the asteroid model from the SpaceWar template, but when I try and render the model, it comes out being mostly transparent. I've copied all the content over from SpaceWar, but it still doesn't work. I used almost the exact same code on one of the spaceships, and it worked fine. Can someone tell me what I'm doing wrong

Here's all of unfinished code for the asteroid... 

#region Using Statements

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Audio;

using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Storage;

#endregion

namespace SpaceGame

{

class Asteroid

{

private Model M_Asteroid;

private Vector3 position;

private float rotateX, rotateY, rotation;

private float scale;

public Asteroid()

{

rotateX = 0.0f;

rotateY = 0.0f;

rotation = 0.05f;

scale = 0.3f;

}

public void UpdateAsteroid()

{

rotateX += rotation;

rotateY += rotation;

}

public void LoadModel(ContentManager content)

{

M_Asteroid = content.Load<Model>("Content/Models/asteroid2");

}

public void DrawModel(Vector3 cameraPosition, float aspectRatio)

{

Matrix[] transforms = new Matrix[M_Asteroid.Bones.Count];

M_Asteroid.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in M_Asteroid.Meshes)

{

foreach (BasicEffect effect in mesh.Effects)

{

effect.EnableDefaultLighting();

effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationX(rotateX)  * Matrix.CreateRotationY(rotateY);

effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, new Vector3(0.0f, 1.0f, 0.0f));

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

}

mesh.Draw();

}

}

}

}



Re: XNA Game Studio Express Trouble using Asteroid Models

Kyle_W

Well I haven't looked at the SpaceWar source code, but if in SpaceWar the asteroid is using a real Effect instead of a BasicEffect, then you should too.



Re: XNA Game Studio Express Trouble using Asteroid Models

Preston Moore

I tried looking at the SpaceWars code, but I couldn't find it anywhere...



Re: XNA Game Studio Express Trouble using Asteroid Models

Shawn Hargreaves - MSFT

Try setting the AlphaBlendEnable renderstate to false before you draw the ship.





Re: XNA Game Studio Express Trouble using Asteroid Models

waruwaru

If the above doesn't work for you, make sure the z-buffer is on. When depth buffer is not on, different parts of the object draw on top of each other, and it looks "transparent" too:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1240805&SiteID=1

graphicsDevice.RenderState.DepthBufferEnable = true;

graphicsDevice.RenderState.DepthBufferWriteEnable = true;






Re: XNA Game Studio Express Trouble using Asteroid Models

Preston Moore

That fixed it. There are still a few holes, but once I scale down the object and turn on the background, they're hardly noticable.

Thanks!





Re: XNA Game Studio Express Trouble using Asteroid Models

The ZMan

SpaceWar uses a custom effect for all of the models to add in the point light from the sun and the spualr highlights. The models use the alpha channel for the specular map so BasicEffect will get confused by this.