Jump to content
  • Advertisement
Sign in to follow this  

Flip Normals of a D3DXSphere

This topic is 3077 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 I made a D3DX SPhere and want to map my texture inside the sphere not outside cause this sphere shall be my environment (Background)
Actually i've no clue how to do that i appriciate evry help!
this is the Code

void initScene()
pMesh = CreateMappedSphere(d3ddev, 10, 20, 20);
pMesh2 = CreateMappedSphere(d3ddev, 80, 20, 20);
pMesh3 = CreateMappedSphere(d3ddev, 5, 20, 20);
pMesh4 = CreateMappedSphere(d3ddev, 5, 20, 20);

void drawSphere()

static float t = 0.0f;
static DWORD dwTimeStart = 0;
DWORD dwTimeCur = GetTickCount();
if( dwTimeStart == 0 )
dwTimeStart = dwTimeCur;
t = ( dwTimeCur - dwTimeStart ) / 1000.0f;



D3DXVECTOR3 vP(0.0f,1.0f,0.0f);

gTexture = NULL;

D3DXMATRIX kugel2;

D3DXCreateTextureFromFile(d3ddev,"Weltall.jpg",&gTexture); //How to flip the Normals of that spehre So the Texture is Inside ?


D3DXVECTOR3 vP2(0.0f,1.0f,0.0f);


gTexture = NULL;

D3DXMATRIX matrix;



LPD3DXMESH CreateMappedSphere(LPDIRECT3DDEVICE9 pDev,float fRad,UINT slices,UINT stacks)
// create the sphere
VERTEX *pVerts;
if (FAILED(D3DXCreateSphere(pDev,fRad,slices,stacks,&mesh,NULL)))
return NULL;

// create a copy of the mesh with texture coordinates,
// since the D3DX function doesn't include them
if (FAILED(mesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM,FVF_VERTEX,pDev,&texMesh)))
// failed, return un-textured mesh
return mesh;

// finished with the original mesh, release it

// lock the vertex buffer
if (SUCCEEDED(texMesh->LockVertexBuffer(0,(LPVOID *) &pVerts))) {

// get vertex count
int numVerts=texMesh->GetNumVertices();

// loop through the vertices
for (int i=0;i<numVerts;i++) {

// calculate texture coordinates

// go to next vertex

// unlock the vertex buffer

// return pointer to caller
return texMesh;

[Edited by - Rey87 on July 14, 2010 6:28:40 PM]

Share this post

Link to post
Share on other sites
To flip a normal you can simply negate it. This is basic vector math.


D3DXVECTOR3 normal(1.0f, 0.0f, 0.0f); // normal along the xaxis
normal = -normal; // = (-1.0f, 0.0f, 0.0f)

// another example:
D3DXVECTOR3 normal(4.0f, -2.0f, 3.24f);
normal = -normal; // = (-4.0f, 2.0f, -3.24f);

D3DXVec3Normalize(&normal, &normal); // dont forget to normalize the vector if need be (which is almost always)

Share this post

Link to post
Share on other sites
What exactly are you trying to do? The thread title talks about flipping normals, but the code you posted doesn't do anything with normals, and the opening sentence of your post implies you're trying to change the texture coordinates rather than the normals?

Assuming the texture coordinates are wrong, how are they wrong? If the texture is mirrored, then just set the U coordinate to 1.0f - U to mirror it back.

EDIT: Also, what is the layout of your VERTEX struct, and how is FVF_VERTEX declared? And are you sure you want to create the mesh in system memory? Why not managed (Which is what I expect you really want)?

Share this post

Link to post
Share on other sites
OK all that not working for cause i'm a noob.
Anyway i tried to add a polygon and set that behind my Objects but i got the problem I can not see the Polygon!

void initScene()
void DrawPoly(){
D3DXMATRIX matrix9;
D3DXMATRIX scale9;

D3DXMatrixTranslation(&matrix9, 0.0f, 0.0f, 10.0f);
d3ddev->SetTransform(D3DTS_WORLD, &matrix9);

Any Idea's?

Share this post

Link to post
Share on other sites
You've got several problems. First: read the docs for D3DXCreatePolygon.

Second: start simple, not complex.

You've created a polygon that has 300 sides, each side 300 units long. The perimeter of your polygon is 90000 units long. The diameter is on the order of 29000 units. That's a big polygon! You then scale it by 100!, making it 2900000 units in diameter. With an average perspective fov, your eyepoint would have to be somewhere around 1500000 units away to see the whole thing. I doubt seriously if your projection far plane is that far away. [wink] Also, make sure your eyepoint and direction are appropriate for viewing the mesh. One thing you'll find (if I remember correctly) is that CreatePolygon meshes face the +Z axis. Unless your eyepoint has a z value > 0, and a direction looking along the -Z axis, you won't see much.

You're created a polygon with vertices which have a position and a normal (see the docs). It has no texture coordinates so setting a texture is useless.

Start simple: try a polygon with, say, 3 sides (a triangle), each side maybe 5 units on a side.

Get that working. Then look at the function CloneMesh ( or CloneMeshFVF ) to add texture coordinates. There are several files in the SDK that demonstrate cloning meshes. [EDIT - sorry. it appears you know about that]

EDIT: All DX functions give some indication of success or failure. In the code you posted, you don't check for success of any function. You may have other problems you don't know about. Take a look at the SUCCEEDED and FAILED macros to test your DX functions calls.

In addition, Debug Runtime is your friend. It will provide a lot of information in the IDE Output window while your app runs.

EDIT2: with regard to your original question about viewing the inside of a sphere, remember that, from the inside, the faces will have a CCW winding order unless you change the indices. You can also change culling mode to CW to view the sphere from the inside.

[Edited by - Buckeye on July 14, 2010 8:04:49 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!