View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# clockwise (CW) & counter-clockwise (CCW) definition of vertices.

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.

5 replies to this topic

### #1oreste  Members

Posted 10 August 2014 - 02:16 PM

Windows 7 DirectX9 VS express 2013 I'm in a state of deep confusion!!! The default in DirectX( is clockwise definition of vertices. In my tut. the lesson building the code to draw a triangle starting w/ transformed vertices renders a triangle. The vertices are defined in a CW mode, if i change the definition to a CCW mode the triangle is not rendered: as expected. In the next lesson the vertices are untransformed and here is the root of my confusion. Because here the vertices are defined CCW. After quite a few tries my only conclusion is that i plugged the coordinates the wrong way. On a piece of paper i used a 2D cartesian coordinate system where X and Y are perpendicular to each other, intersecting at (0, 0). Right of (0, 0) X is >0 (<0 to the left) and Y is >0 above (0, 0) (<0 below). CW has not been changed to CCW in the code, in fact the tut. author states that CCW will not be used in the tut. Help!!! I've been obssessing over this!! Thanx. Oreste

### #2Endurion  Members

Posted 10 August 2014 - 10:50 PM

AFAIK since you use untransformed vertices one of the stage matrices might change the order direction. The culling is done once all vertices have been transformed through world, view and projection matrix.

In other words, is the vertex order CW after transformation?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

### #3oreste  Members

Posted 11 August 2014 - 09:18 AM

I don't see in the code a change of direction...........But being relatively new at this i think a good idea is to paste here the code that might be relevant:............................................................. //this is the funct used to render a single frame void render_frame(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->BeginScene(); //select which vertex format we are using d3ddev->SetFVF(CUSTOMFVF); //set up the pipeline D3DXMATRIX matRotateY; //a matrix to store the rotation info static float index = 0.0f; index += 0.01f; //an ever increasing float value, this determines the speed of the rotation //build a matrix to rotate the model based on the increasing float value D3DXMatrixRotationY(&matRotateY, index); //tell Direct3D about our matrix d3ddev->SetTransform(D3DTS_WORLD, &matRotateY); D3DXMATRIX matView; //the view transform matrix D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3{ 0.0f, 0.0f, 10.0f }, //the camera position &D3DXVECTOR3{ 0.0f, 0.0f, 0.0f }, //look-at position &D3DXVECTOR3{ 0.0f, 1.0f, 0.0f }); //the up direction d3ddev->SetTransform(D3DTS_VIEW, &matView); //set the view transform to matView D3DXMATRIX matProjection; //the projection transform matrix D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), //the horizontal field of view (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, //aspect ratio 1.0f, //the near view plane 100.0f); //the far view plane d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); //set the projection //select the vertex buffer to display d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); //copy the vertex buffer to the back buffer d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); }...................................................................................... //this is the func that puts the 3D models into video RAM void init_graphics(void) { //create the vertices using the CUSTOMVERTEX struct CUSTOMVERTEX vertices[] = { { 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), }, { 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), }, { -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), }, }; //CUSTOMVERTEX vertices[] = //{ //{} //} //create a vertex buffer interface called v_buffer d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; //a void pointer //lock v_buffer and load the vertices into it v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); v_buffer->Unlock(); }

### #4oreste  Members

Posted 11 August 2014 - 09:26 AM

Sorry i am having a prob with the editor! The reply is a mess. By the way where must i go to present posts that are legible and not one big mass of text? Thankx Oreste

### #5Khatharr  Members

Posted 11 August 2014 - 10:47 AM

Click 'more reply options' to open the full post editor.

There's a button for entering code.

Alternatively, you can just wrap it in BBCode style [ code ] [ /code ] tags.

The idea behind backface culling is that primitives whose vertices are CW/CCW (depending on the setting) from the point of view of the camera won't be drawn. You want the 'outward' facing primitives of an object's mesh to be in the correct order so that they'll be rendered when the face is pointing toward the viewer. If you have a simple triangle and you're rotating it steadily around one axis, then it should only be visible half the time.

  CUSTOMVERTEX vertices[] = {
{  3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255) },
{  0.0f,  3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0) },
{ -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0) }
};

That's CCW. If you don't transform it, and if the camera is looking at it from the front, then you won't see it. However, the code you posted looks like it does transform it: it rotates the triangle around the y axis by 0.01f every frame, so you should be seeing it roughly half the time, since you're looking at 0,0,0, where it's centered. Specifically, you should start seeing it after rendering 158 or so frames.

Are you calling render_frame() repeatedly?

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

### #6oreste  Members

Posted 11 August 2014 - 11:21 AM

Yes render_frame is called repeatedly. In an attempt to see clearer i stopped the rotation of the triangle. And w/ the code as it is the triangle is rendered, when i swap the coordinates (to CW) the triangle is not rendered!! My nrxt project is to look more in depth at the geometry pipeline it is very possible thta my solution lies there.

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.