Need help converting a macro for directx 9...

Advanced game related topics
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Need help converting a macro for directx 9...

Post by Codemonger »

Ok I finally worked out getting a triangle to display really great in d3d9 but I am moving on to transformation with matrices etc... so I'm in the middle of trying to get a macro converted. I'm lost on this one, if anyone can help I would appreciate it. Thanks
Here is part of the header I am trying to convert :

Code: Select all


typedef enum _D3DTRANSFORMSTATETYPE {
    D3DTS_VIEW          = 2,
    D3DTS_PROJECTION    = 3,
    D3DTS_TEXTURE0      = 16,
    D3DTS_TEXTURE1      = 17,
    D3DTS_TEXTURE2      = 18,
    D3DTS_TEXTURE3      = 19,
    D3DTS_TEXTURE4      = 20,
    D3DTS_TEXTURE5      = 21,
    D3DTS_TEXTURE6      = 22,
    D3DTS_TEXTURE7      = 23,
    D3DTS_FORCE_DWORD     = 0x7fffffff, /* force 32-bit size enum */
} D3DTRANSFORMSTATETYPE;

#define D3DTS_WORLDMATRIX(index) (D3DTRANSFORMSTATETYPE)(index + 256)
#define D3DTS_WORLD  D3DTS_WORLDMATRIX(0)
I need D3DTS_WORLD which is defined as a macro ?? hmmm. any ideas of what it should look like...
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

_D3DTRANSFORMSTATETYPE is an enumeration, so you could convert it
to a PB Enumeration. But since all values are given, that doesn't make any sense.

In PB:

Code: Select all

#D3DTS_VIEW          = 2
#D3DTS_PROJECTION    = 3
#D3DTS_TEXTURE0      = 16
#D3DTS_TEXTURE1      = 17
#D3DTS_TEXTURE2      = 18
#D3DTS_TEXTURE3      = 19
#D3DTS_TEXTURE4      = 20
#D3DTS_TEXTURE5      = 21
#D3DTS_TEXTURE6      = 22
#D3DTS_TEXTURE7      = 23
D3DTS_FORCE_DWORD is not needed, as it is only there to make the
enumerationtype 32bit.

Macros are simple replacements, so if you replace one macro after the
other here, you end up with the value 256 for D3DTS_WORLD

Timo
quidquid Latine dictum sit altum videtur
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

Thanks again Freak, I knew about the enumeration, but the macro I wasn't sure about the getting the end result. Anyway I'll try to plug in the value and see if I can get a matrix tutorial up and running. I have to clean my code up also, before I post it for everybody to try out.
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

Stumped on this structure ... it looks like it uses a multi-dimensional array in the structure, can this be done ? I tried with no luck.
typedef struct _D3DMATRIX {
union {
struct {
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;

};
float m[4][4];
};
} D3DMATRIX;
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

For me, #define D3DTS_WORLD macro is like '#D3DTS_WORLD = 256' in PureBasic.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Codemonger wrote: float m[4][4];
maybe like this?

Code: Select all

Structure M_HELP
  m.f[4]
EndStructure

Structure D3DMATRIX
  StructureUnion
    _11.f : _12.f : _13.f : _14.f
    _21.f : _22.f : _23.f : _24.f
    _31.f : _32.f : _33.f : _34.f
    _41.f : _42.f : _43.f : _44.f
    m.M_HELP[4]
  EndStructureUnion
EndStructure

myvar.D3DMATRIX
myvar\m[0]\m[0] = 0.1
myvar\m[1]\m[0] = 0.2
myvar\m[0]\m[1] = 0.3

Debug myvar\m[1]\m[0]
does this help?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

No you would have to do something like this in PB to get a somewhat similar structure:

Code: Select all

Structure M_HELP
  m.f[4]
EndStructure

Structure _help
  _11.f : _12.f : _13.f : _14.f
  _21.f : _22.f : _23.f : _24.f
  _31.f : _32.f : _33.f : _34.f
  _41.f : _42.f : _43.f : _44.f
EndStructure

Structure D3DMATRIX
  StructureUnion
    n._help
    m.M_HELP[4]
  EndStructureUnion
EndStructure

myvar.D3DMATRIX
myvar\m[0]\m[0] = 0.1
myvar\m[1]\m[0] = 0.2
myvar\m[0]\m[1] = 0.3

Debug myvar\m[1]\m[0]
Debug myvar\n\_21
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

Thanks guys, but i think this is going to be a long haul so I'm going to throw the all the code up and make it open source , so people can test it and add more to it. I'll start something on one of my websites. Just too many little details and road blocks for me. Thanks for the help and I'll post a link up to a dedicated area for anyone that is interested in tackling DirectX 9 conversion :wink:
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Post Reply