Jump to content
  • Advertisement

Archived

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

thekid

Vector to Screen Coords

This topic is 6934 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 have a loader that loads vector coordinates from a file. I can get all this into D3DVECTORs but I cannot figure out how to get these vectors into D3DVERTEX format so that I can draw them to the screen. ANYONE help would be appreciated

Share this post


Link to post
Share on other sites
Advertisement

struct D3DVECTOR
{
float x;
float y;
float z;
};

struct D3DVERTEX
{
float x;
float y;
float z;
float nx;
float ny;
float nz;
float tu;
float tv;
};


Just copy the coordinates from your D3DVECTOR to the x,y, and z components in D3DVERTEX. Leave the rest of the attributes zero. Now you should be able to render the model, though it will be black since Direct3D doesn''t have enough information to light the vertices. You need to set the normals to have correct lighting. Either you get the normals from the file or you compute it.

You can also skip copying the coordinates completely and render from you array of D3DVECTORs directly. You do this by supplying D3DFVF_XYZ instead of D3DFVF_VERTEX as dwVertexTypeDesc in DrawPrimitive() or DrawIndexedPrimitive().



- WitchLord

Share this post


Link to post
Share on other sites
Yea that normals thing. What is that and how do i calculate them. What are they. I read alot about them.

Also does anyone have the code to draw a simple cube in d3d NOT using the d3dframe utility lib. I need the real code

Thanx

Share this post


Link to post
Share on other sites
You can compute the normal for a triangle composed of three vectors (V1,V2,V3) like this:

D3DVECTOR N = Normalize(CrossProduct(V2-V1, V3-V1));

Then you can for each vertex average the normals of the triangles connected to the vertex to produce the vertex normal.

The normal is a vector that describes to the lighting functions in which direction the surface is facing at the corresponding position.

Sorry, I don''t have time right now to write the code for rendering a cube. Rendering the cube without using d3dframe.lib is done the same way as with d3dframe.lib. The only thing d3dframe.lib helps you with is the initialization, and some other tedious work.



- WitchLord

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Read up in the DX docs on Flexible Vertex Formats, it will help alot. As Witchlord stated, you don''t even need to pass in a D3DVERTEX structure. D3D really just looks that the memory is laid out correctly. It doesn''t care how you send in the floats, as long as the memory lay out matches the vertex format you give it.

I have my vertex like:

CVector
{
float x,y,z;
float DotProduct();
CVector CrossProduct();
...etc.
};

CVertex
{
CVector Position;
float tu,tv;
float lu,lv;
};

This allows you to make some nice object models and still pass them to D3D. As long as you don''t have any virtual methods in there

-Mitch

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!