Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GekkoCube

Transformed or Untransformed? - that is the question.

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to draw the path of my projectile (basically a simply trajectory) using a linelist. I am wondering if I should use transformed or untransformed vertices. Can anybody recommend which one, the benefits of each, and why I should stick with one over the other, and also if it''s just a matter of preference as to which type to use??? I will post my code below because I am having problems getting the line to draw properly. instead of what i want i get two different results depending on if i use transformed or untransformed vertices. If i transform it myself (commented code in the render function below), i get a single vertical line and some stray lines at what appears to be random in location. If I let dx transform them, i get a bunch of lines shooting from the origin, like a 3-dimensional astrix. in both cases i am using the vertex format provided below. This is my vertex format...
  
// A structure for our custom vertex type, _UNTRANSFORMED

#define D3DFVF_CUSTOMVERTEX_UNTRANSFORMED ( D3DFVF_XYZ | D3DFVF_DIFFUSE  )

typedef struct CUSTOMVERTEX_UNTRANSFORMED {
    float x, y, z;      // The untransformed position for a vertex

    DWORD color;        // The vertex color

} VERTEX_UT, *lpVERTEX_UT;
[/source/

this is my render function...
[source]
//---( Render : Update and draw the projectile )---//

void CProjectile::Render( float fSpeed )
{
	// If projectile is not alive (dead), don''t do a thing.

	if( false == m_bAlive ) return;

	// Set the world matrix

	/*D3DXMATRIX matWorld;
    D3DXMatrixIdentity( &matWorld );
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );*/

	// If projectile has been fired, yet is still used (to show old trajectory path).
	if( false == m_bUsed )
	{
		// Update position.
		m_Pos += m_Velocity;// * fSpeed;

		// Begin the calculation for the time elapsed.
		static DWORD time_elapsed = 0;
		static DWORD time = timeGetTime();
		time_elapsed = time - timeGetTime();

		// 2.0 second time period between each line.
		if( time_elapsed >= 1500 )
		{
///*
			// Add a line-point to the line list.
			m_pVertices[m_iListLength  ].color = 0xff00ff0a;
			m_pVertices[m_iListLength  ].x     = m_Pos.x;
			m_pVertices[m_iListLength  ].y     = m_Pos.y;
			m_pVertices[m_iListLength++].z     = m_Pos.z;

			m_pVertices[m_iListLength  ].color = 0xff00ff0a;
			m_pVertices[m_iListLength  ].x     = m_Pos.x;
			m_pVertices[m_iListLength  ].y     = m_Pos.y;
			m_pVertices[m_iListLength++].z     = m_Pos.z;
//*/

			time = timeGetTime();

			// * CRITICAL SECTION * : The following condition is important since it

			// determines when to stop adding to the line-list. Otherwise there will

			// be segmentation fault(s)!


			// If equal-to or greater than length limit...

			// reserve the last line segment and set the m_bUsed flag.

			if( m_iListLength >= m_iMaxLength )
			{
				m_iListLength = m_iMaxLength;
				m_bUsed = true;
			}
		}
	}

	// Check : If the line-point list length is not greater than 0, or is not even, dont draw.

	// So basically, only draw the line-point list when that above criteria is OK.

	if( m_iListLength % 2 != 0 || m_iListLength == 0 ) return;

	// Now draw the line list.

	//g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE  ); // culling


	g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST,
								   m_iListLength,
							       m_pVertices,
								   m_iSizeOfInfo );

	//g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW  ); // culling

}
  

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by GekkoCube
I want to draw the path of my projectile (basically a simply trajectory) using a linelist.

// Add a line-point to the line list.
m_pVertices[m_iListLength ].color = 0xff00ff0a;
m_pVertices[m_iListLength ].x = m_Pos.x;
m_pVertices[m_iListLength ].y = m_Pos.y;
m_pVertices[m_iListLength++].z = m_Pos.z;

m_pVertices[m_iListLength ].color = 0xff00ff0a;
m_pVertices[m_iListLength ].x = m_Pos.x;
m_pVertices[m_iListLength ].y = m_Pos.y;
m_pVertices[m_iListLength++].z = m_Pos.z;

g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST,
m_iListLength,
m_pVertices,
m_iSizeOfInfo );



There are two weird things here.

1. Both ends of the line are set to the same location.
2. You are passing the number of vertices when it should be the number of lines.

Share this post


Link to post
Share on other sites
thanks...i''m setting two vertices at a time (which are at the same location) because i wanted to be sure that i have an even number of vertices, since that is one of the requirements for proper rendering.

ill change my primitive count...to (m_iListLength - 1).

thanks.
i hope this all work.s

Share this post


Link to post
Share on other sites
quote:
Original post by GekkoCube
thanks...i''m setting two vertices at a time (which are at the same location) because i wanted to be sure that i have an even number of vertices, since that is one of the requirements for proper rendering.


That makes sense as long as you set the first vert somewhere else and you ignore the last vert. Otherwise, the beginning of the line is at the same place as the end.
quote:

ill change my primitive count...to (m_iListLength - 1).



No, no, no. The number of lines in a line list is half the number of verts (since each segment has two verts).

I didn''t realize that all the line segments are connected. In that case, you should use a line strip instead of a line list.

Share this post


Link to post
Share on other sites
are you sure that the number of lines is half the number of vertices?
if i have 3 vertices, then there are 2 lines.
if i have 5 vertices, then i have 4 lines.
or am i missing something?

Share this post


Link to post
Share on other sites
youre getting confused between line lists and strips.

Line lists are a list of individual lines. The start and end vertex is not necessarily that of the next or previous line.
(ie each segment is discrete)

On the other hand, a line strip is continuous. Each vertex after the start vertex defines a line segment between it and the previous vertex.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!