Archived

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

DirectX+Classes= no good?

This topic is 5768 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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?!?!

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
:: raises an eyebrow at Tron ::

dot product does not a vector make.

Cross product of two vectors on the other hand gets you the normal vector. Just make sure you have the two vectors in the right order or you''re normal iwll be facing the wrong direction.

Also, normalize the vector after you do the cross product. You want normal vectors to be unit length.

Sorrow
Discord -- Work in Progress

Share this post


Link to post
Share on other sites