Sign in to follow this  

Problems displaying triangles properly

Recommended Posts

Basically, I am drawing 3 triangles on the screen. As I understand it, the vertices are transformed already, so they should be in a "stuck" place in the 3d world. When I move the camera, however, the triangles actually move position. I can't figure out why this is happening. Thanks for any help! edit: ok, I see that the vertices being transformed means that they are in 2d screen space. How do I get them to be in 3d? I'm a little confused ;) Here's the code i'm using:
	CUSTOMVERTEX vertices[] =
        { 5.0f,  20.0f, 0.5f,0xffff0000, }, // x, y, z, rhw, color
        { 10.0f,  20.0f, -5.0f, 0xffff0000, },
        { 5.0f,  20.0f, -5.0f, 0xffff0000, },
		{  5.0f, 5.0f, 0.5f,   0xff00ff00, }, // x, y, z, rhw, color
        { 10.0f, 50.0f, 0.5f,  0xff00ff00, },
        {  10.0f, 10.0f, 0.5f, 0xff00ff00, },
		{ 25.0f, 25.0f, 0.5f,  0xff00ffff, },
		{ 5.0f,  25.0f, 0.5f,  0xff00ffff, },
		{ 5.0f,  5.0f, 0.5f,   0xff00ffff, }, // x, y, z, rhw, color

	if( FAILED( d3ddevice->CreateVertexBuffer( sizeof(vertices),
		return 0;
	VOID* pVertices;
    if( FAILED( batch->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );


d3ddevice->SetStreamSource( 0, batch, 0,sizeof(CUSTOMVERTEX) );
d3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 3);

[Edited by - ktuluorion on October 8, 2006 3:36:35 PM]

Share this post

Link to post
Share on other sites
Your comments suggest you're using transformed and lit (which are specified in screen-space/2D) but your code suggests regular 3D.


{ 5.0f, 20.0f, 0.5f,0xffff0000, }, // x, y, z, rhw, color

Your comment lists 5 fields, but your code is only providing 4 [smile]

What is D3DFVF_CUSTOMVERTEX defined as? Does it use D3DFVF_XYZRHW or D3DFVF_XYZ?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this