Jump to content

  • Log In with Google      Sign In   
  • Create Account


Inside a cube


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Coventry   Members   -  Reputation: 102

Like
0Likes
Like

Posted 06 November 2012 - 05:21 PM

Hi.
I have a question that bothers me for couple of hours and I failed with my experiments.
I am working with code from the following code sample http://xbox.create.m...e/primitives_3d
I would like to look inside of the cube with backface culling turned on.
I was manipulating the normals, but I failed.
Could you tell me what changes do I have to put to CubePrimitive.cs in order to change the face of every wall of the cube such that I can see it from inside? Here's the code, a little bit cleaned from unnecessary comments:
public CubePrimitive(GraphicsDevice graphicsDevice, float size)
{
// A cube has six faces, each one pointing in a different direction.
Vector3[] normals =
{
  new Vector3(0, 0, 1),
  new Vector3(0, 0, -1),
  new Vector3(1, 0, 0),
  new Vector3(-1, 0, 0),
  new Vector3(0, 1, 0),
  new Vector3(0, -1, 0),
};
// Create each face in turn.
foreach (Vector3 normal in normals)
{
  // Get two vectors perpendicular to the face normal and to each other.
  Vector3 side1 = new Vector3(normal.Y, normal.Z, normal.X);
  Vector3 side2 = Vector3.Cross(normal, side1);
  // Six indices (two triangles) per face.
  AddIndex(CurrentVertex + 0);
  AddIndex(CurrentVertex + 1);
  AddIndex(CurrentVertex + 2);
  AddIndex(CurrentVertex + 0);
  AddIndex(CurrentVertex + 2);
  AddIndex(CurrentVertex + 3);
  // Four vertices per face.
  AddVertex((normal - side1 - side2) * size / 2, normal);
  AddVertex((normal - side1 + side2) * size / 2, normal);
  AddVertex((normal + side1 + side2) * size / 2, normal);
  AddVertex((normal + side1 - side2) * size / 2, normal);
}
InitializePrimitive(graphicsDevice);
}


Sponsor:

#2 NightCreature83   Crossbones+   -  Reputation: 2669

Like
0Likes
Like

Posted 07 November 2012 - 07:12 AM

You will have to add the verts on the inside of the cube in a different order form the ones outside. The order should be Counter-Clock-Wise.
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS