Sign in to follow this  

Unknown problem

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

#include "d3dx9math.h"
#pragma comment(lib, "d3dx9.lib")
#include "d3d9.h"
#pragma comment(lib, "d3d9.lib")
#include "d3dx9.h"
#pragma comment(lib, "d3dx9.lib")


//TWorld must have a IDirect3DDevice9 object
class TWorld{
	
public:
	TWorld();
	TWorld(IDirect3DDevice9 *pd3dDevice);
	~TWorld();

	//this method overloads the D3DXMatrixRotation functions with D3DTS_WORLD
	void rotate(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle);
	//this method rotate with relate to the current angle
	void rotateRel(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle);
	void getRotAngle(FLOAT &XAngle, FLOAT &YAngle, FLOAT &ZAngle);

	//this method overloads the D3DXMatrixTranslation functions with D3DTS_WORLD
	void move(FLOAT XMove, FLOAT YMove, FLOAT ZMove);
	//this method translate with relate to the current position
	void moveRel(FLOAT XMove, FLOAT YMove, FLOAT ZMove);
	void getMove(FLOAT &XMove, FLOAT &YMove, FLOAT &ZMove);

	//this method overloads the D3DXMatrixTranslation functions with D3DTS_WORLD
	void scale(FLOAT XScale, FLOAT YScale, FLOAT ZScale);
	//this method translate with relate to the current position
	void scaleRel(FLOAT XScale, FLOAT YScale, FLOAT ZScale);
	void getScale(FLOAT &XScale, FLOAT &YScale, FLOAT &ZScale);

	//this method is used when the Device is losed
	void setDevice(IDirect3DDevice9 *pd3dDevice);
	//this method is overload the D3DXMAtrixMultiply and do all multiply operation
	void combinAll();
	/*
	this method is overload the D3DXMAtrixMultiply
	the order of world combination should be 
	scale -> rotate x -> rotate y -> rotate z -> translate
	and this method must call the upDate() at the end
	*/
	void combin(D3DXMATRIX matIn);
	//this method is only overload the SetTransformat
	void upDate();
	//this method is only overload the D3DXMatrixIdentity
	void reset();

private:

	D3DXMATRIX m_matWorld;
	D3DXMATRIX m_matRotX, m_matRotY, m_matRotZ, m_matMove, m_matScale; 
	IDirect3DDevice9 *m_pd3dDevice;
	FLOAT m_XAngle, m_YAngle, m_ZAngle;
	FLOAT m_XMove, m_YMove, m_ZMove;
	FLOAT m_XScale, m_YScale, m_ZScale;
};



//TView must have a IDirect3DDevice9 object
class TView{
	
public:
	TView();
	TView(IDirect3DDevice9 *pd3dDevice);
	~TView();

	//this method overloads the D3DXMatrixRotation functions with D3DTS_VIEW
	void rotate(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle);
	//this method rotate with relate to the current angle
	void rotateRel(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle);
	void getRotAngle(FLOAT &XAngle, FLOAT &YAngle, FLOAT &ZAngle);

	//this method overloads the D3DXMatrixTranslation functions with D3DTS_WORLD
	void move(FLOAT XMove, FLOAT YMove, FLOAT ZMove);
	//this method translate with relate to the current position
	void moveRel(FLOAT XMove, FLOAT YMove, FLOAT ZMove);
	void getMove(FLOAT &XMove, FLOAT &YMove, FLOAT &ZMove);

	//this method is used when the Device is losed
	void setDevice(IDirect3DDevice9 *pd3dDevice);
	void setEye(FLOAT x, FLOAT y, FLOAT z);
	void setPostion(FLOAT x, FLOAT y, FLOAT z);
	void setYAix(FLOAT x, FLOAT y, FLOAT z);

	//this method is overload the D3DXMAtrixMultiply and do all multiply operation
	void combinAll();
	/*
	this method is overload the D3DXMAtrixMultiply
	the order of world combination should be 
	translation -> rotate z -> rotate y -> rotate x -> scale
	and this method must call the upDate() at the end
	*/
	void combin(D3DXMATRIX matIn);
	//this method is only overload the SetTransformat
	void upDate();
	//this method is only overload the D3DXMatrixIdentity
	void reset();

private:

	D3DXMATRIX m_matView;
	D3DXMATRIX m_matRotX, m_matRotY, m_matRotZ, m_matMove; 
	IDirect3DDevice9 *m_pd3dDevice;
	FLOAT m_XAngle, m_YAngle, m_ZAngle;
	FLOAT m_XMove, m_YMove, m_ZMove;
	D3DXVECTOR3 m_eye;
	D3DXVECTOR3 m_at;
	D3DXVECTOR3 m_up;

};
/*
You will must use the setDevice
Otherwise the projector can't be work
*/
class TProjector{
public:
	TProjector();
	TProjector(float fov, float aspect, float near, float far);
	~TProjector();

	void setDevice(IDirect3DDevice9 *pd3dDevice);
	//fill the data
	void setPerspective(float fov, float aspect, float near, float far);
	//setTransform
	void project();

private:
	D3DXMATRIX m_matProj;
	IDirect3DDevice9 *m_pd3dDevice;
	float m_fovY;
    float m_aspect;
    float m_zn;
    float m_zf;
};


TWorld::TWorld(){
	reset();
}

TWorld::TWorld(IDirect3DDevice9 *pd3dDevice){
	reset();
	setDevice(pd3dDevice);
}

TWorld::~TWorld(){

}

void TWorld::setDevice(IDirect3DDevice9 *pd3dDevice){
	m_pd3dDevice = pd3dDevice;
}

void TWorld::rotate(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle){
	m_XAngle = XAngle;
	m_YAngle = YAngle;
	m_ZAngle = ZAngle;
	D3DXMatrixRotationX(&m_matRotX, m_XAngle);
	D3DXMatrixRotationY(&m_matRotY, m_YAngle);
	D3DXMatrixRotationZ(&m_matRotZ, m_ZAngle);
}

void TWorld::rotateRel(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle){
	m_XAngle += XAngle;
	m_YAngle += YAngle;
	m_ZAngle += ZAngle;
	D3DXMatrixRotationX(&m_matRotX, m_XAngle);
	D3DXMatrixRotationY(&m_matRotY, m_YAngle);
	D3DXMatrixRotationZ(&m_matRotZ, m_ZAngle);
}

void TWorld::getRotAngle(FLOAT &XAngle, FLOAT &YAngle, FLOAT &ZAngle){
	XAngle = m_XAngle;
	YAngle = m_YAngle;
	ZAngle = m_ZAngle;
}

void TWorld::move(FLOAT XMove, FLOAT YMove, FLOAT ZMove){
	m_XMove = XMove;
	m_YMove = YMove;
	m_ZMove = ZMove;
	D3DXMatrixTranslation(&m_matMove, m_XMove, m_YMove, m_ZMove);
}

void TWorld::moveRel(FLOAT XMove, FLOAT YMove, FLOAT ZMove){
	m_XMove += XMove;
	m_YMove += YMove;
	m_ZMove += ZMove;
	D3DXMatrixTranslation(&m_matMove, m_XMove, m_YMove, m_ZMove);
}

void TWorld::getMove(FLOAT &XMove, FLOAT &YMove, FLOAT &ZMove){
	XMove = m_XMove;
	YMove = m_YMove;
	ZMove = m_ZMove;
}

void TWorld::scale(FLOAT XScale, FLOAT YScale, FLOAT ZScale){
	m_XScale = XScale;
	m_YScale = YScale;
	m_ZScale = ZScale;
	D3DXMatrixTranslation(&m_matMove, m_XMove, m_YMove, m_ZMove);
}

void TWorld::scaleRel(FLOAT XScale, FLOAT YScale, FLOAT ZScale){
	m_XScale += XScale;
	m_YScale += YScale;
	m_ZScale += ZScale;
	D3DXMatrixScaling(&m_matScale, m_XScale, m_YScale, m_ZScale);
}

void TWorld::getScale(FLOAT &XScale, FLOAT &YScale, FLOAT &ZScale){
	XScale = m_XScale;
	YScale = m_YScale;
	ZScale = m_ZScale;
}

void TWorld::combinAll(){
	reset();
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &m_matScale);
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &m_matRotX);
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &m_matRotY);
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &m_matRotZ);
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &m_matMove);
	upDate();
}

void TWorld::combin(D3DXMATRIX matIn){
	D3DXMatrixMultiply(&m_matWorld, &m_matWorld, &matIn);
}

void TWorld::upDate(){
	m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_matWorld);
}

void TWorld::reset(){
	D3DXMatrixIdentity(&m_matWorld);
}

TView::TView(){
	setEye(0, 0, 1);
	setPostion(0, 0, 0);
	D3DXMatrixIdentity(&m_matView);
}

TView::TView(IDirect3DDevice9 *pd3dDevice){
	D3DXMatrixIdentity(&m_matView);
	setDevice(pd3dDevice);
	upDate();
}

TView::~TView(){

}

void TView::setDevice(IDirect3DDevice9 *pd3dDevice){
	m_pd3dDevice = pd3dDevice;
}

void TView::rotate(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle){
	m_XAngle = XAngle;
	m_YAngle = YAngle;
	m_ZAngle = ZAngle;
	D3DXMatrixRotationX(&m_matRotX, m_XAngle);
	D3DXMatrixRotationY(&m_matRotY, m_YAngle);
	D3DXMatrixRotationZ(&m_matRotZ, m_ZAngle);
}

void TView::rotateRel(FLOAT XAngle, FLOAT YAngle, FLOAT ZAngle){
	m_XAngle += XAngle;
	m_YAngle += YAngle;
	m_ZAngle += ZAngle;
	D3DXMatrixRotationX(&m_matRotX, m_XAngle);
	D3DXMatrixRotationY(&m_matRotY, m_YAngle);
	D3DXMatrixRotationZ(&m_matRotZ, m_ZAngle);
}

void TView::getRotAngle(FLOAT &XAngle, FLOAT &YAngle, FLOAT &ZAngle){
	XAngle = m_XAngle;
	YAngle = m_YAngle;
	ZAngle = m_ZAngle;
}

void TView::move(FLOAT XMove, FLOAT YMove, FLOAT ZMove){
	m_XMove = XMove;
	m_YMove = YMove;
	m_ZMove = ZMove;
	D3DXMatrixTranslation(&m_matMove, m_XMove, m_YMove, m_ZMove);
}

void TView::moveRel(FLOAT XMove, FLOAT YMove, FLOAT ZMove){
	m_XMove += XMove;
	m_YMove += YMove;
	m_ZMove += ZMove;
	D3DXMatrixTranslation(&m_matMove, m_XMove, m_YMove, m_ZMove);
}

void TView::getMove(FLOAT &XMove, FLOAT &YMove, FLOAT &ZMove){
	XMove = m_XMove;
	YMove = m_YMove;
	ZMove = m_ZMove;
}

void TView::setEye(FLOAT x, FLOAT y, FLOAT z){
	m_eye.x = x;
	m_eye.y = y;
	m_eye.z = z;
}

void TView::setPostion(FLOAT x, FLOAT y, FLOAT z){
	m_at.x = x;
	m_at.y = y;
	m_at.z = z;
}

void TView::setYAix(FLOAT x, FLOAT y, FLOAT z){
	m_up.x = x;
	m_up.y = y;
	m_up.z = z;
}

void TView::combinAll(){
	reset();
	D3DXMatrixMultiply(&m_matView, &m_matView, &m_matMove);
	D3DXMatrixMultiply(&m_matView, &m_matView, &m_matRotZ);
	D3DXMatrixMultiply(&m_matView, &m_matView, &m_matRotY);
	D3DXMatrixMultiply(&m_matView, &m_matView, &m_matRotX);
	upDate();
}

void TView::combin(D3DXMATRIX matIn){
	D3DXMatrixMultiply(&m_matView, &m_matView, &matIn);
}

void TView::upDate(){
	D3DXMatrixLookAtLH(&m_matView, &m_eye, &m_at, &m_up);
	m_pd3dDevice->SetTransform(D3DTS_VIEW, &m_matView);
}

void TView::reset(){
	D3DXMatrixIdentity(&m_matView);
}

TProjector::TProjector(){
	setPerspective(D3DX_PI / 4, 1.0f, 0.5f, 100.0f);
}

TProjector::TProjector(float fov, float aspect, float near, float far){
	setPerspective(fov, 
		aspect, 
		near,   //can't complie!  syntax error : ','
		far);
}

TProjector::~TProjector(){
	
}

void TProjector::setDevice(IDirect3DDevice9 *pd3dDevice){
	m_pd3dDevice = pd3dDevice;
}

void TProjector::setPerspective(float fov, float aspect, float near, float far)
{
	m_fovY = fov;
	m_aspect = aspect;
	m_zf = near;  //can't complie!  syntax error : ';'
	m_zn = far;   //can't complie!  syntax error : ';'
}

void TProjector::project(){
	D3DXMatrixPerspectiveFovLH(&m_matProj, m_fovY, m_aspect, m_zn, m_zf);
	m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &m_matProj);
}

I am using Visual C++, i don't know why it can complie There are 3 error
Fruny - added source tags.

Share this post


Link to post
Share on other sites
Dumping your code without explanation is not going to win you any friends.

Quote:
I am using Visual C++, i don't know why it can complie
There are 3 error


What are they?

Share this post


Link to post
Share on other sites
Quick review of your code says that it was copied from some competent source. No errors are obvious for me. Quote your compiler please...

Share this post


Link to post
Share on other sites
Strange things happens:
....

d:\Ìîè äîêóìåíòû\Visual Studio Projects\gamedev\gd.cpp(370): error C2059: syntax error : ';'
d:\Ìîè äîêóìåíòû\Visual Studio Projects\gamedev\gd.cpp(369): error C2059: syntax error : ';'
d:\Ìîè äîêóìåíòû\Visual Studio Projects\gamedev\gd.cpp(354): error C2059: syntax error : ','

Share this post


Link to post
Share on other sites
here: setPerspective(fov, aspect, near,far);
here: m_zf = near; //can't complie! syntax error : ';'
and here: m_zn = far; //can't complie! syntax error : ';'

Share this post


Link to post
Share on other sites
Ummm, in your class declaration, in your code, are you using FLOAT or float. I see a wide varity of mixtures in there. I do not know if it was GD or your code. Secondly it looks like you might have a global variable name collision somehow with some variables. Give this a try:


void TProjector::setPerspective(float a_fov, float a_aspect, float a_near, float _far)
{
m_fovY = a_fov;
m_aspect = a_aspect;
m_zf = a_near; //can't complie! syntax error : ';'
m_zn = a_far; //can't complie! syntax error : ';'
}
...
TProjector::TProjector(float a_fov, float a_aspect, float a_near, float a_far){
setPerspective(a_fov,
a_aspect,
a_near, //can't complie! syntax error : ','
a_far);
}


Other than that I don't know really. Everything else looks fine to me upon inspection. I don't think that won't work so the only other thing I can think of is change the float to FLOAT [lol]. That seems to be the only difference between your other code and that of which does not work.

- Drew


[Edited by - Drew_Benton on March 8, 2005 11:42:28 AM]

Share this post


Link to post
Share on other sites
Smells like the old near and far keywords (indicating 12 or 16 bit pointers, IIRC) are causing you trouble.

Drew_Benton - never prefix a symbol with an underscore.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
Smells like the old near and far keywords (indicating 12 or 16 bit pointers, IIRC) are causing you trouble.
I agree. There was a thread either here or in General Programming yesterday where someone had this exact problem.

Just rename "near" and "far" to something else (but preferably not something starting with an underscore - they're reserved keywords for the compiler)

Share this post


Link to post
Share on other sites

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