🔒 Locked
NOMINMAX
Advertisement
Original Post
I'm trying to use physx with directx, but i'm having a problem with windows.h, For Physx to work you have to place #define NOMINMAX before windows.h If I do this though, it messes up the rest of the project. Anyone have any suggestions? I figured this didnt have so much to do with either physx or directx as it does general programming.
Quote:Can you provide some details about how it messes up the rest of the project?
Original post by Njguy
I'm trying to use physx with directx, but i'm having a problem with windows.h, For Physx to work you have to place #define NOMINMAX before windows.h If I do this though, it messes up the rest of the project. Anyone have any suggestions? I figured this didnt have so much to do with either physx or directx as it does general programming.
I usually just add NOMINMAX to the preprocessor definitions in the project properties. I haven't had any problems with this approach.
well it only messes up one file. Heres an example of where it declaring NOMINMAX will interfere with this and some other bits of code I have.
// Find the minimum and maximum points of the face along the x axis. Then
// check if these two points are within the box's x axis extents.
float minX = min( vertex0->translation.x, min( vertex1->translation.x, vertex2->translation.x ) );
float maxX = max( vertex0->translation.x, max( vertex1->translation.x, vertex2->translation.x ) );
if( maxX < boxMin.x )
return false;
if( minX > boxMax.x )
return false;
// Find the minimum and maximum points of the face along the x axis. Then
// check if these two points are within the box's x axis extents.
float minX = min( vertex0->translation.x, min( vertex1->translation.x, vertex2->translation.x ) );
float maxX = max( vertex0->translation.x, max( vertex1->translation.x, vertex2->translation.x ) );
if( maxX < boxMin.x )
return false;
if( minX > boxMax.x )
return false;
Quote:Actually, you shouldn't even have to do that. Just include <algorithm> (I think that's where these two functions are located), and then prefix the function names with std:: in your code.
redefine those horrid min and max macros as template functions and you'll be golden.
Quote:
Original post by jyk Quote:Actually, you shouldn't even have to do that. Just include <algorithm> (I think that's where these two functions are located), and then prefix the function names with std:: in your code.
redefine those horrid min and max macros as template functions and you'll be golden.
ok so I included algorithm, so how would I do that with this function. I'm a little lost. Its just a header file so, not sure how that would work.
//-----------------------------------------------------------------------------// Returns true if the given face is inside the given box.//-----------------------------------------------------------------------------inline bool IsFaceInBox( Vertex *vertex0, Vertex *vertex1, Vertex *vertex2, D3DXVECTOR3 boxMin, D3DXVECTOR3 boxMax ){ // Find the minimum and maximum points of the face along the x axis. Then // check if these two points are within the box's x axis extents. float minX = min( vertex0->translation.x, min( vertex1->translation.x, vertex2->translation.x ) ); float maxX = max( vertex0->translation.x, max( vertex1->translation.x, vertex2->translation.x ) ); if( maxX < boxMin.x ) return false; if( minX > boxMax.x ) return false; // Find the minimum and maximum points of the face along the y axis. Then // check if these two points are within the box's y axis extents. float minY = min( vertex0->translation.y, min( vertex1->translation.y, vertex2->translation.y ) ); float maxY = max( vertex0->translation.y, max( vertex1->translation.y, vertex2->translation.y ) ); if( maxY < boxMin.y ) return false; if( minY > boxMax.y ) return false; // Find the minimum and maximum points of the face along the z axis. Then // check if these two points are within the box's z axis extents. float minZ = min( vertex0->translation.z, min( vertex1->translation.z, vertex2->translation.z ) ); float maxZ = max( vertex0->translation.z, max( vertex1->translation.z, vertex2->translation.z ) ); if( maxZ < boxMin.z ) return false; if( minZ > boxMax.z ) return false; return true;}
I personally think it is bad form to force a user on the windows platform to have to define NOMINMAX, it is quite possible to use std::min and std::max when the MS macros are defined; yet on the other hand I think it is bad form on MS' behalf to have used names which are used alot in their macros.
Quote:
Original post by SiCrane
Where you see min, replace with std::min. Where you see max, replace with std::max.
Ok I did this to my engine. I got rid of the 200 errors. The engine compiles flawlessly. Now when compiling the APP I get these few errors. These errors apply to the function I gave you above.
erased errors to save space
Quote:
Original post by jyk Quote:What workaround do you recommend (in lieu of using NOMINMAX, that is)? [Oops, looks like you already answered that question.]
...it is quite possible to use std::min and std::max when the MS macros are defined...
Lol I posted it and then deleted it as the OP had got it working.
It requires (std::min)(foo,bar) instead of std::min(foo,bar)
Quote:No need to do that. The posted errors provide important context; without them, the thread is less useful. (Imagine yourself coming upon this thread at some time in the future while trying to solve exactly the same problem; wouldn't seeing the exact error messages be helpful in this situation?)
I erased some of that to save server space.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement