첫 번째 사항 : 나는 C++ 전문가가 아니며 멀리 떨어져 있습니다. 나는 약 1 년 전에 간단히 훑어 보았고 약 2 주 전 DirectX를 C++로 직접 가르치기로 결정할 때까지 다시 만진 적이 없었습니다. 나는 오류에 대한 나의 공정한 분배를 가졌지 만 (대부분은) 스스로 해결할 수 있었다. 나는이 하나를 단념한다. 지금까지 문제가 mapCube 클래스의 .h 및 .cpp 파일을 어떻게 사용하고 있는지 알 수 있으므로 게시 할 것입니다. 2019 생성자를 제외하고 mapCube 의 모든 기능에 대한되지 않은 외부 기호 오류, 그것은 나에게 말한다들이 메인 프로그램 만 주장 그들이에서 참조 : 나는 LINK를 얻을 :클래스 파일과 함께 발생하는 확인되지 않은 외부 기호
오류 자체가 몇 가지 있지만 화나는 있습니다 초기화되지 않았습니다. 내가 아는 두 번째 오류는 checkColl 함수와 관련이 있습니다. VC++ 2010에서는 x, y 및 z가 더 이상 mapCube 클래스의 일부가 아니라는 것을 결정합니다. 오히려 혼란 스럽습니다.
코드 : mapCube.h
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>
extern const float TILE_WIDTH, TILE_HEIGHT;
extern LPDIRECT3DDEVICE9 d3ddev;
// include the Direct3D Library files
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")
#ifndef MAPCUBE_H
#define MAPCUBE_H
class mapCube{
struct CUSTOMVERTEX {FLOAT X, Y, Z; D3DVECTOR NORMAL; DWORD COLOR;}; //might be able to put these elsewhere
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE) //they are already in main, but mapCube needs them too
public:
LPD3DXMESH cubeMesh;
float x,y,z;
void setCoord(float, float, float);
D3DXVECTOR3 getCoord(){return D3DXVECTOR3(x,y,z);};
mapCube();
mapCube(float, float, float);
mapCube(float, float, float, D3DXCOLOR);
void draw(D3DXMATRIX);
void setColor(D3DXCOLOR);
int checkColl(D3DXVECTOR3, D3DXVECTOR3);
};
#endif
mapCube.cpp
#include "mapCube.h"
mapCube::mapCube()
{
x=0;
y=0;
z=0;
setColor(D3DCOLOR_XRGB(128,128,128));
}
mapCube::mapCube(float nx, float ny, float nz)
{
x=nx;
y=ny;
z=nz;
setColor(D3DCOLOR_XRGB(128,128,128));
}
mapCube::mapCube(float nx, float ny, float nz, D3DXCOLOR color)
{
x=nx;
y=ny;
z=nz;
setColor(color);
}
void mapCube::setCoord(float nx, float ny, float nz) //this function and the next one are both called
{ //when the cube is created because I'm using
x=nx; //an array of cubes instead of one-by-one
y=ny;
z=nz;
};
void mapCube::setColor(D3DXCOLOR color) //basically just colors each vertex 'color'
{
LPD3DXMESH tmpMesh=NULL;
D3DXCreateBox(d3ddev, TILE_WIDTH, TILE_HEIGHT, TILE_WIDTH, &tmpMesh, NULL);
tmpMesh->CloneMeshFVF(0, CUSTOMFVF, d3ddev, &cubeMesh);
LPDIRECT3DVERTEXBUFFER9 tmpVertBuf=NULL;
if(SUCCEEDED(cubeMesh->GetVertexBuffer(&tmpVertBuf)))
{
int nNumVerts = cubeMesh->GetNumVertices();
CUSTOMVERTEX *pVertices = NULL;
tmpVertBuf->Lock(0, 0, (void**)&pVertices, 0);
{
int i=0;
while(i<nNumVerts)
{
pVertices[i].COLOR=color;
i++;
}
}
tmpVertBuf->Unlock();
tmpVertBuf->Release();
}
};
void mapCube::draw(D3DXMATRIX matWorld)
{
D3DXMATRIX matTranslate;
D3DXMatrixTranslation(&matTranslate,x,y,z); //translation to the cubes stored coordinates
d3ddev->SetTransform(D3DTS_WORLD, &(matTranslate * matWorld)); //...combined with the total world transform
cubeMesh->DrawSubset(0);
};
int checkColl(D3DXVECTOR3 vecTest, D3DXVECTOR3 vecThis) //2nd arg bc compiler decided to forget
{ //that this class has x,y,z vars
if(vecTest.x>=vecThis.x-(TILE_WIDTH/2.0f) || vecTest.x<=vecThis.x+(TILE_WIDTH/2.0f)) //rudimentary attempt at collision checking
{
return 1;
}
else if(vecTest.z>=vecThis.z-(TILE_HEIGHT/2.0f) || vecTest.z<=vecThis.z+(TILE_HEIGHT/2.0f))
{
return 2;
}
else
{
return 0;
}
}
죄송 포맷이 조금 떨어져, 이것이 내가이 인터페이스를 처음 사용하는 경우. 어쨌든 마지막 함수에서 x/z 참조를 전달 된 D3D 벡터로 변경하면 컴파일러에서 구문 오류 또는 기타 오류를보고합니다. d3d 또는 C++과 관련하여 도움이나 비평을 환영합니다. 내가 문제가 있다고 생각하지 않기 때문에 나는 주된 소식통을 게시하지 않았다. 그러나 내가 묻는다면 나는 그것을 게시 할 것이다.
이 문제의 해결책에 따라 이제 다음 경고가 표시됩니다. 1> Debug \ mapCube.obj : 경고 LNK4042 : 두 번 이상 지정한 개체. extras ignored CUSTOMVERTEX 및 FVF의 중복 정의를 제거하고 헤더에서 extern을 만들었지 만 이러한 문제를 해결할 수 없습니다.
아무것도 포함하기 전에 'MAPCUBE_H' 헤더 가드가 헤더 파일의 맨 위에 있어야합니다. –
감사합니다. 오류 검사 등을 위해 많은 시간을 들이지 않았으므로 내가 가야 할 때가되었습니다. – coderCobra