Problems displaying triangles properly

Started by
2 comments, last by ktuluorion 17 years, 6 months ago
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),
			 D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &batch, NULL ) ) )
		return 0;
    
	VOID* pVertices;
    if( FAILED( batch->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
    batch->Unlock();

d3ddevice->SetRenderState(D3DRS_LIGHTING,
                                     FALSE);

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



[Edited by - ktuluorion on October 8, 2006 3:36:35 PM]
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
Advertisement
Your comments suggest you're using transformed and lit (which are specified in screen-space/2D) but your code suggests regular 3D.

e.g:

{ 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?

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

How come each vertex only take four parameters? If they're supposed to be transformed, where's RHW?

Edit: Blasted "high speed" internet.
I took out RHW. It's an old comment. I think i might have figured out the probem.. i needed to call the transform function to set where in space it is.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]

This topic is closed to new replies.

Advertisement