3DS 포맷 정보와 관련 소스이다.
Posted by chungki
Frustum Culling은 많이 공개되어서 특별한 것은 없지만 단지 Directx와 Opengl에서 구현할 때 행렬문제로 인해 실수가 경우가 많다. 그래서 OpenGL 구현코드를 직접 적는다.
행렬을 아래와 같이 정의한다. t_를 붙인 이유는 보통 행행렬을 많이 사용하지만 OpenGL에서는 열행렬이기 때문에 transpose라는 의미에서 t_라고 붙였다.
struct TMATRIX16
현재 세팅된 Projection Matrix와 ModelViewMatrix를 가져온다.
- TMATRIX16 mxModelView, mxProjView;
- ::glGetFloatv(GL_MODELVIEW_MATRIX,mxModelView.m_MX); ::glGetFloatv(GL_PROJECTION_MATRIX,mxProjView.m_MX);
TMATRIX16 mxFrustum; MultiMatrix(mxModelView, mxProjView, mxFrustum);
typedef struct tagFrustumPlane
{
union
{
struct
{
float x;
float y;
float z;
float d;
};
float _m[4];
};
} FRUSTUM_PLANE;
typedef enum emViewPlane
{
VP_LEFT,
VP_RIGHT,
VP_TOP,
VP_BOTTOM,
VP_NEAR,
VP_FAR,
};
_Plans[VP_LEFT].x=mxFrustum.t_m41+mxFrustum.t_m11; _Plans[VP_LEFT].y=mxFrustum.t_m42+mxFrustum.t_m12; _Plans[VP_LEFT].z=mxFrustum.t_m43+mxFrustum.t_m13; _Plans[VP_LEFT].d=mxFrustum.t_m44+mxFrustum.t_m14; _Plans[VP_RIGHT].x=mxFrustum.t_m41-mxFrustum.t_m11; _Plans[VP_RIGHT].y=mxFrustum.t_m42-mxFrustum.t_m12; _Plans[VP_RIGHT].z=mxFrustum.t_m43-mxFrustum.t_m13; _Plans[VP_RIGHT].d=mxFrustum.t_m44-mxFrustum.t_m14;// _Plans[VP_TOP].x=mxFrustum.t_m41-mxFrustum.t_m21; _Plans[VP_TOP].y=mxFrustum.t_m42-mxFrustum.t_m22; _Plans[VP_TOP].z=mxFrustum.t_m43-mxFrustum.t_m23; _Plans[VP_TOP].d=mxFrustum.t_m44-mxFrustum.t_m24;
_Plans[VP_BOTTOM].x=mxFrustum.t_m41+mxFrustum.t_m21; _Plans[VP_BOTTOM].y=mxFrustum.t_m42+mxFrustum.t_m22; _Plans[VP_BOTTOM].z=mxFrustum.t_m43+mxFrustum.t_m23; _Plans[VP_BOTTOM].d=mxFrustum.t_m44+mxFrustum.t_m24;
_Plans[VP_NEAR].x=mxFrustum.t_m41+mxFrustum.t_m31; _Plans[VP_NEAR].y=mxFrustum.t_m42+mxFrustum.t_m32; _Plans[VP_NEAR].z=mxFrustum.t_m43+mxFrustum.t_m33; _Plans[VP_NEAR].d=mxFrustum.t_m44+mxFrustum.t_m34;
_Plans[VP_FAR].x=mxFrustum.t_m41-mxFrustum.t_m31; _Plans[VP_FAR].y=mxFrustum.t_m42-mxFrustum.t_m32; _Plans[VP_FAR].z=mxFrustum.t_m43-mxFrustum.t_m33; _Plans[VP_FAR].d=mxFrustum.t_m44-mxFrustum.t_m34;
Posted by chungki
Posted by chungki
U3DFont::U3DFont(void)
{
}
U3DFont::~U3DFont(void)
{
for(int i=0;(int)i<strlen(s);i++)
glDeleteLists(lists[i],1);
}
void U3DFont::SetText(char* text)
{
for(int i=0;(int)i<strlen(s);i++)
glDeleteLists(lists[i],1);
HDC hdc=0;
extern HWND hwnd;
hdc=GetDC(hwnd);
if(!hwnd)
hdc=engine.hDC;
strcpy(s,text);
HGDIOBJ hh=SelectObject(hdc ,hfont);
glPushAttrib(GL_LIST_BIT|GL_COLOR_BUFFER_BIT);
// glListBase(1000);
#define FONTLIST 1000
GLYPHMETRICSFLOAT gmf[FONTLIST];
wchar_t dwChar[256];
int nLength = MultiByteToWideChar(936, MB_PRECOMPOSED, s, -1, dwChar, 256);
for(int i=0;i<nLength-1;i++)
{
int nn=glGenLists(1);
lists[i]=nn;
wglUseFontOutlinesW(hdc, dwChar[i], 1, nn, 0.0f, 0.1f, WGL_FONT_POLYGONS, gmf);
}
glPopAttrib();
SelectObject(hdc ,(HFONT)hh);
ReleaseDC(hwnd,hdc);
}
void U3DFont:: Draw( )
{
glPushMatrix();
for(int i=0;i<(int)strlen(s);i++)
glCallList(lists[i]);
glPopMatrix();
}
void U3DFont::Init(char* fontName,float size)
{
const char *p=fontName;
BYTE charset;
if(p[0]==0 )
charset=SYMBOL_CHARSET;
else
charset=GB2312_CHARSET;
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
lf.lfHeight = (long)size;//size has no effect
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = 0;
lf.lfUnderline = 1;
lf.lfStrikeOut = 1;
lf.lfCharSet =
lf.lfOutPrecision = 1;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = 0;
DeleteObject(hfont);
lstrcpy(lf.lfFaceName, fontName);
hfont=CreateFontIndirect(&lf);
}
Posted by chungki

Posted by chungki
Nice !!!!!!!!
- chungki
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 |