Sign in to follow this  

I want dead the problem kill me

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


#ifndef __d3dUtilityH__
#define __d3dUtilityH__

#include "CCamera.h"
#include <d3dx9.h>
#include <d3d9.h>


	const D3DXCOLOR      WHITE( D3DCOLOR_XRGB(255, 255, 255) );
	const D3DXCOLOR      BLACK( D3DCOLOR_XRGB(  0,   0,   0) );
	const D3DXCOLOR        RED( D3DCOLOR_XRGB(255,   0,   0) );
	const D3DXCOLOR      GREEN( D3DCOLOR_XRGB(  0, 255,   0) );
	const D3DXCOLOR       BLUE( D3DCOLOR_XRGB(  0,   0, 255) );
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) );
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) );
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) );

	//
	// Materials
	//

	D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);

	const D3DMATERIAL9 WHITE_MTRL  = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
	const D3DMATERIAL9 RED_MTRL    = InitMtrl(RED, RED, RED, BLACK, 2.0f);
	const D3DMATERIAL9 GREEN_MTRL  = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
	const D3DMATERIAL9 BLUE_MTRL   = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
	const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);

	//strcpy
	void CopyString(const char* input, char** output);

	int EnterMsgLoop( 
		bool (*ptr_display)(float timeDelta));


	template<class T> void Release(T t)
	{
		if( t )
		{
			t->Release();
			t = 0;
		}
	}
		
	template<class T> void Delete(T t)
	{
		if( t )
		{
			delete t;
			t = 0;
		}
	}


	//
	//
	//
	void CameraByKey(float,Camera&);
	void CameraByMouse(Camera&);
	void Cleanup();

	char* fpsCount(float sumtimeDelta);

#endif // __d3dUtilityH__

the head file work fine with some cpp file it need,but no work with other cpp . there are many error rise.but I know these error is not actual error.something else cause these error.these error is C2059 C2143 C2988 ... but if I put the head file at top of the cpp ,I mean above all other .h file all is ok. what the hell is the problem? I guess template is "big problem"

Share this post


Link to post
Share on other sites
header file

// ...

extern const D3DXCOLOR WHITE, BLACK, RED, GREEN, ........

// ...



source file

// ...

const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255, 255, 255) ),
BLACK( D3DCOLOR_XRGB( 0, 0, 0) ),
RED( D3DCOLOR_XRGB(255, 0, 0) ),
GREEN( D3DCOLOR_XRGB( 0, 255, 0) ),
BLUE( D3DCOLOR_XRGB( 0, 0, 255) ),
YELLOW( D3DCOLOR_XRGB(255, 255, 0) ),
CYAN( D3DCOLOR_XRGB( 0, 255, 255) ),
MAGENTA( D3DCOLOR_XRGB(255, 0, 255) );

// ...

Share this post


Link to post
Share on other sites

template<class T> void Delete(T t)
{
if( t )
{
delete t;
t = 0;
}
}



You don't need to check that t != 0 as delete 0 is a no-op (no operation).
Also to get the effect you really want it should be:


template<class T> void Delete(T*& t)
{
delete t;
t = 0;
}


That way, you really are deleting a pointer and setting it to zero will affect the pointer passed to you because it has been passed by reference.

Share this post


Link to post
Share on other sites
Quote:
Original post by Catafriggm
I'm going to venture a guess that smart_idiot is right


I'm going to venture a guess that he's not (although he usually is) - const variables are implicitly static, by which I mean they will not be exported outside of the translation unit (that is, defining the same const variable in two .cpp files is perfectly fine).

That said, I could be totally missing something that smart_idiot's noticed, in which case ignore me. Especially considering I can't tell what the hell the the OP is saying most of the time, and see no problems with his code, and am guessing the bug is elsewhere.

Dave Hunt: CCamera.h should include d3d9.h/d3dx9.h itself if it uses types from those headers.

derek7: Post the full errors, not just their codes.

Share this post


Link to post
Share on other sites
I solve this problem through removing template define.the camera.h may be just fine.beacuse
the Uitility.h work fine with some cpp.


#ifndef __cameraH__
#define __cameraH__

#include <d3dx9.h>
#include "aabb.h"

class Camera
{
public:
enum CameraType { LANDOBJECT, AIRCRAFT };

Camera();
Camera(CameraType cameraType);
~Camera();

void strafe(float units); // left/right
void fly(float units); // up/down
void walk(float units); // forward/backward

void pitch(float angle); // rotate on right vector
void yaw(float angle); // rotate on up vector
void roll(float angle); // rotate on look vector

void getViewMatrix(D3DXMATRIX* V);
void setCameraType(CameraType cameraType);
void getPosition(D3DXVECTOR3* pos);
void setPosition(D3DXVECTOR3* pos);

void getRight(D3DXVECTOR3* right);
void getUp(D3DXVECTOR3* up);
void getLook(D3DXVECTOR3* look);
void getTranslationMatrix(D3DXMATRIX *);
AABB &updateAABB();

private:

CameraType _cameraType;
D3DXVECTOR3 _right;
D3DXVECTOR3 _up;
D3DXVECTOR3 _look;
D3DXVECTOR3 _pos;
AABB _box;
AABB t;

};
#endif // __cameraH__








#ifndef __aabb__
#define __aabb__

#include <d3dx9.h>

struct AABB
{
D3DXVECTOR3 max;
D3DXVECTOR3 min;
};

bool intersectAABBs(
const AABB &box1,
const AABB &box2,
AABB *boxIntersect
);

#endif


Share this post


Link to post
Share on other sites

This topic is 4579 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this