15,897,334 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Pramslam (Top 2 by date)
Pramslam
9-Jun-11 16:02pm
View
Thanks for the timely response!
pGrid is called within the main function before the main loop within winmain.cpp
<pre lang="midl">pGrid = new Grid(11, 11, &v0, &v1, &v2, &v3);
pGrid->CreateDirectXMesh(pd3dDevice);
D3DXCreateSphere(pd3dDevice, 2, 20, 20, &pBallMesh, NULL);
// Main message loop:</pre>
This is the grid constructor I am using.
<pre>
struct GRIDVERTEX
{
D3DXVECTOR3 p; // The untransformed, 3D position for the vertex
D3DXVECTOR3 n; // normalized normal
DWORD color; // color for this vertex
float u, v;
};
#define D3DFVF_GRIDVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)
class Grid {
private:
int maxWidthVertices; // width in vertices
int maxHeightVertices; // height in vertices
int widthVertices; // width in vertices
int heightVertices; // height in vertices
int widthFaces; // widht in faces
int heightFaces; // height in faces
unsigned long maxNumVertices;
unsigned long numVertices;
int numFaces;
D3DXVECTOR3 v0, v1, v2, v3; // in D3D face order
D3DXVECTOR3 dv; // delta v from 0 to 2
GRIDVERTEX *vertices;
WORD *indexData;
LPD3DXMESH mesh;
public:
Grid(
int maxWidthVerticesP,
int maxHeightVerticesP,
D3DXVECTOR3 *v0P,
D3DXVECTOR3 *v1P,
D3DXVECTOR3 *v2P,
D3DXVECTOR3 *v3P
);
</pre>
<pre lang="cs">Grid::Grid(
int maxWidthVerticesP,
int maxHeightVerticesP,
D3DXVECTOR3 *v0P,
D3DXVECTOR3 *v1P,
D3DXVECTOR3 *v2P,
D3DXVECTOR3 *v3P
) {
int i, j, k;
maxWidthVertices = maxWidthVerticesP;
maxHeightVertices = maxHeightVerticesP;
widthVertices = maxWidthVertices;
heightVertices = maxHeightVertices;
numVertices = widthVertices * heightVertices;
widthFaces = widthVertices - 1;
heightFaces = heightVertices - 1;
numFaces = widthFaces * heightFaces * 2; // 2 triangles in each grid cell
v0 = *v0P;
v1 = *v1P;
v2 = *v2P;
v3 = *v3P;
dv = v2 - v0;
dv.x /= float(widthVertices - 1);
dv.y /= 1;
dv.z /= float(heightVertices - 1);
// set up the vertex and normal and texture data
vertices = new GRIDVERTEX[numVertices];
for (j=0, k=0; j<heightVertices; j++) {
for (i=0; i<widthVertices; i++, k++) {
GetGridPoint(&(vertices[k].p), float(v0.x + i * dv.x), float(v0.z + j * dv.z));
GetGridNormal(&(vertices[k].n), &(vertices[k].p));
vertices[k].color = D3DCOLOR_ARGB(255,0,255,255);
vertices[k].u = vertices[k].p.x;
vertices[k].v = vertices[k].p.z;
}
}</pre>
Pramslam
9-Jun-11 15:54pm
View
Deleted
Thanks for the timely response!
pGrid is called within the main function before the main loop within winmain.cpp
<pre lang="midl">pGrid = new Grid(11, 11, &v0, &v1, &v2, &v3);
pGrid->CreateDirectXMesh(pd3dDevice);
D3DXCreateSphere(pd3dDevice, 2, 20, 20, &pBallMesh, NULL);
// Main message loop:
</pre>
This is the grid constructor I am using.
<pre>
struct GRIDVERTEX
{
D3DXVECTOR3 p; // The untransformed, 3D position for the vertex
D3DXVECTOR3 n; // normalized normal
DWORD color; // color for this vertex
float u, v;
};
#define D3DFVF_GRIDVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)
class Grid {
private:
int maxWidthVertices; // width in vertices
int maxHeightVertices; // height in vertices
int widthVertices; // width in vertices
int heightVertices; // height in vertices
int widthFaces; // widht in faces
int heightFaces; // height in faces
unsigned long maxNumVertices;
unsigned long numVertices;
int numFaces;
D3DXVECTOR3 v0, v1, v2, v3; // in D3D face order
D3DXVECTOR3 dv; // delta v from 0 to 2
GRIDVERTEX *vertices;
WORD *indexData;
LPD3DXMESH mesh;
public:
Grid(
int maxWidthVerticesP,
int maxHeightVerticesP,
D3DXVECTOR3 *v0P,
D3DXVECTOR3 *v1P,
D3DXVECTOR3 *v2P,
D3DXVECTOR3 *v3P
);
~Grid() {
delete vertices;
delete indexData;
};
void Update(
);
void GetGridPoint(
D3DXVECTOR3 *pt,
float x,
float z
);
void GetGridPoint(
D3DXVECTOR3 *pt,
int i, // row (from bottom to top)
int j // column (from left to right)
);
void GetGridNormal(
D3DXVECTOR3 *n,
D3DXVECTOR3 *pt
);
void GetGridNormal(
D3DXVECTOR3 *n,
int i, // row (from bottom to top)
int j // column (from left to right)
);
void CreateDirectXMesh(
LPDIRECT3DDEVICE9 pd3dDevice
);
void DrawDirectXMesh(
LPDIRECT3DDEVICE9 pd3dDevice
);
};
#endif</pre>