DirectX+Classes= no good?

Started by
10 comments, last by KingSnake 22 years, 1 month ago
Hello. I''ve written a dx8 application, it loads a model from 3ds file, puts data into a vetrex buffer (and index buffer) and renders it. works fine. Then i''ve converted it to c++ with classes: class Object has its own vertex/index buffer, code copied from the older app, but when i call lock/unlock on the vertex buffer from OUTSIDE the class Object, or i try to call a Drawprimitive() on the vertex buffer in it, the app hangs. Why? the vertex buffer has to be in the same class where the d3d device was instatiated? Have i to use multiple VBs in the main class? give some answer, please! Bye. P.S: on computing normals: what is the normal in point (1,1,0), that is part of the triangle with vertices (1,1,0) himself, (-1,1,0), (-1,-1,0)? Don''t care about the direction of vectorial product, or give me both answers. Thanks.
Advertisement
Switch to debug DX runtime, and see if it complains about anything.

You don''t need to have the code in the same class.

Does your code work if you put it in the same class?

Make sure your objects are valid when you are using them (ie, don''t create Device object as a local variable).

Add checks for FAILED to all DX return values.

If you are calling something by pointers, make sure pointers are valid (ie, not NULL).

Try stepping through your code, this might help you localize the problem.

Maybe you can zip your project and put it up somewhere?

It seems that you are looking for vertex normals. Take a look at DX Graphics-programmer''s guide-using d3d-vertex data-face and vertex normal vectors in SDK help.
---visit #directxdev on afternet <- not just for directx, despite the name
Yeah you may either want to

1: Make your Device Public in your first class

or

(MY PREFERENCE)
2: Make your Model class a "Friend" of you other class

I would guess that the Device you are using in your Model class is not valid - thus hangs.

Create the class:

void CModel::CModel(CScene *input)
{
Scene=input;
}

When you draw it you could then go

void CModel::Draw()
{
Scene->Device->DrawPrimitive(....);
}

Iitialize the class thus

Scene=new CScene;
Model=new CModel(Scene);

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
Ok, to be precise:
-in the class Engine i put the DX devices.
-i pass them via pointers to the class Object instantiated in Engine
-Object has its own vertex buffer
-the only calls that make the app hang are Lock and unlock on vertex buffers,if made from Engine and Drawprimitive, still from Engine.
-The creation of the VB and the use of lock and unlock from Object is OK.
-all other calls are OK.

still, what''s wrong? I''d post the cose, but is some 4000 lines..
And, about the P.S., Please, give me the answer! I''ve read carefully the section in the sdk docs, but still i have doubts.
Take it as a quitz, give the answer, it will clarify a lot.

Thanks.
quote:Original post by IndirectX
Maybe you can zip your project and put it up somewhere?

If you do, I'll look at it.

A vertex normal of a single vertex (which is what you're asking about) can be literally any vector you choose. You need to clarify your question.


Edited by - IndirectX on February 23, 2002 4:00:31 PM
---visit #directxdev on afternet <- not just for directx, despite the name
For ''Normal'' i mean a vector that makes a right angle with a plane. The plane is individuated by the triangle, that has vertices: (1,1,0), (-1,1,0), (-1,-1,0).
I want the normal in (1,1,0): it has to perpendicular to the triangle face, don''t care for now if the front or back face.
Not sure here... but I''ve had trouble as well with these things (specifically an array of IDirect3DTexture8), turned out that I should''ve used pointers to the devices rather then direct interfaces, that worked fine.

I think you have to use LPDirect3D... and/or PDirect3D - look in the DX SDK, it mentions something about these pointers at the bottom of interface descriptions. (Not much tho).
I always pass the typedefed pointers:

LPDIRECT3D8
LPDIRECT3DDEVICE8

instead of:

IID_Direct3D8 etc and it works fine

I.e. in header:

private:
LPDIRECT3D8 m_pDirect3d;
LPDIRECT3DDEVICE8 m_pDevice;
public:
LPDIRECT3DDEVICE8 GetDevice(){ASSERT(m_pDevice);return m_pDevice;}


and in code:

init D3d ...
create device ...
test device fails using FAILED(HRESULT hr) macro.
#ifndef _DIRECTX PostQuitMessage(0);#endif
Here''s how you can compute a vector perpendicular to a plane given by three points:
D3DXVECTOR3 p1(1,1,0), p2(-1,1,0), p3(-1,-1,0);D3DXPLANE plane;D3DXPlaneFromPoints(&plane, &p1, &p2, &p3);D3DXVECTOR3 normal(plane.a, plane.b, plane.c); 

If you have a plane given by equation ax+by+cz+d=0, then (a,b,c) is the normal vector to this plane.
Keep in mind that these vectors are not normalized.
---visit #directxdev on afternet <- not just for directx, despite the name

This topic is closed to new replies.

Advertisement