Skip to main content
gamedev.net
🔒 Locked

NOMINMAX

Started by Njguy 13 replies 4.1k views
Original Post
Njguy
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.
Zakwayda
Zakwayda
Quote:
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.
Can you provide some details about how it messes up the rest of the project?

I usually just add NOMINMAX to the preprocessor definitions in the project properties. I haven't had any problems with this approach.
Njguy
Njguy
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;
mrbastard
mrbastard
redefine those horrid min and max macros as template functions and you'll be golden.
[size="1"]
Zakwayda
Zakwayda
Quote:
redefine those horrid min and max macros as template functions and you'll be golden.
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.
Njguy
Njguy
Quote:
Original post by jyk
Quote:
redefine those horrid min and max macros as template functions and you'll be golden.
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.




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;}
SiCrane
SiCrane
Where you see min, replace with std::min. Where you see max, replace with std::max.
gameXcore
gameXcore
Little more information, the :: is the scope operator, when you include <algorithm> the min and max functions it contains are in the "std" namespace, which is why you prefix thm with std::, this allows your compiler to select the correct function.
Game development blog and portfolio: http://gamexcore.co.uk
CmpDev
CmpDev
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.
Njguy
Njguy
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

SiCrane
SiCrane
That probably means that you haven't defined NOMINMAX properly.
Njguy
Njguy
Quote:
Original post by SiCrane
That probably means that you haven't defined NOMINMAX properly.


WOW lol now I feel stupid. Your absolutely right. Works 100% thxs so much your a life saver. All of you. I erased some of that to save server space.
Zakwayda
Zakwayda
Quote:
...it is quite possible to use std::min and std::max when the MS macros are defined...
What workaround do you recommend (in lieu of using NOMINMAX, that is)? [Oops, looks like you already answered that question.]
CmpDev
CmpDev
Quote:
Original post by jyk
Quote:
...it is quite possible to use std::min and std::max when the MS macros are defined...
What workaround do you recommend (in lieu of using NOMINMAX, that is)? [Oops, looks like you already answered that question.]


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)
Zakwayda
Zakwayda
Quote:
I erased some of that to save server space.
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?)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.