简体   繁体   中英

Trying to draw textured cube primitive in XNA with quads

Right now I'm using XNA 4.0 with Windows Phone Developer Tools to create a textured cube using a predefined quad class on MSDN.

The front/back/left/right faces of the cube will draw fine (for every cube that I make), however the top and bottom faces won't render. The rasterizer state's cull mode is set to none and the quad that represents the top face exists, and it seems as if it would draw, but for some reason it won't.

Is there a problem with my code, or is this not happening for some other reason?

Here's the code:

It's because your top and bottom faces have a height to them. They should have 0 height.

Here you are passing in a value as height:

Faces[4] = new Quad(topFaceOrigin, Vector3.Normalize(Vector3.Down), Up, Size, Size);

And then here in Quad constructor it's being used to give incorrect LowerLeft & LowerRight values:

LowerLeft = UpperLeft - (Up * height);
LowerRight = UpperRight - (Up * height);

I would recommend changing how you create all your quads; each face really should have different parameters. Right now all your faces are passing in practically the same stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM