Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vector to Screen Coords

Started by thekid Apr 29, 2000 at 9:27 PM 4 replies 600+ views
Original Post
thekid
thekid
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
thekid
thekid
PLEASE HELP ME??!!!

I cannot figure this out.
WitchLord
WitchLord

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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
thekid
thekid
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
WitchLord
WitchLord
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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.