commit ec41d3430ed4f1bae6bac39dc96797ba1276ba9b Author: aNNiMON Date: Thu Feb 22 19:38:30 2024 +0200 Initial commit diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fe228c0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,292 @@ +#include +#include +#include +#include "prim.h" +#include "waxloader.h" +#include + +class Pos +{ +public: + float x,y,z; + Pos() + { + x=0; + y=0; + z=0; + } +}; + + + +static HGLRC hRC; +static HDC hDC; + +BOOL keys[256]; +GLsizei w,h; +Wax * wax; +GLfloat X, Z; +GLfloat HeadMovement, HeadMovAngle; +POINT mpos; +POINT ompos; +GLfloat camy,camx; +Pos pos; + +GLvoid InitGL(GLsizei Width, GLsizei Height) +{ + glClearColor(0, 0, 0, 0.0f); + glClearDepth(1.0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + glMatrixMode(GL_PROJECTION); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_NORMALIZE); + glLoadIdentity(); + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,1000.0f); + + glMatrixMode(GL_MODELVIEW); +} + +GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) +{ + if (Height==0) + Height=1; + + glViewport(0, 0, Width, Height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,1000.0f); + glMatrixMode(GL_MODELVIEW); +} + +GLvoid DrawGLScene() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + glRotatef(-camx, 1, 0, 0); + glRotatef(-camy, 0, 1, 0); + glTranslatef(pos.x,pos.y,pos.z); + + for(int i=0; icount; i++) + { + wax->p[i].draw(); + } + +} + +LRESULT CALLBACK WndProc( + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + GLuint PixelFormat; + static PIXELFORMATDESCRIPTOR pfd= + { + sizeof(PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, + 24, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 0, + 0, 0, 0, 0, + 16, + 0, + 0, + PFD_MAIN_PLANE, + 0, + 0, 0, 0 + }; + switch (message) + { + case WM_CREATE: + ShowCursor(false); + wax=new Wax((char*)"room.wax"); + hDC = GetDC(hWnd); + PixelFormat = ChoosePixelFormat(hDC, &pfd); + if (!PixelFormat) + { + MessageBox(0,"Can't Find A Suitable PixelFormat.","Error",MB_OK|MB_ICONERROR); + PostQuitMessage(0); + break; + } + if(!SetPixelFormat(hDC,PixelFormat,&pfd)) + { + MessageBox(0,"Can't Set The PixelFormat.","Error",MB_OK|MB_ICONERROR); + PostQuitMessage(0); + break; + } + hRC = wglCreateContext(hDC); + if(!hRC) + { + MessageBox(0,"Can't Create A GL Rendering Context.","Error",MB_OK|MB_ICONERROR); + PostQuitMessage(0); + break; + } + if(!wglMakeCurrent(hDC, hRC)) + { + MessageBox(0,"Can't activate GLRC.","Error",MB_OK|MB_ICONERROR); + PostQuitMessage(0); + break; + } + InitGL(w, h); + break; + + case WM_DESTROY: + case WM_CLOSE: + ChangeDisplaySettings(NULL, 0); + + wglMakeCurrent(hDC,NULL); + wglDeleteContext(hRC); + ReleaseDC(hWnd,hDC); + + PostQuitMessage(0); + break; + + case WM_KEYDOWN: + keys[wParam] = TRUE; + break; + + case WM_KEYUP: + keys[wParam] = FALSE; + break; + + case WM_SIZE: + ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); + break; + + default: + return (DefWindowProc(hWnd, message, wParam, lParam)); + } + return (0); +} + +int WINAPI WinMain( + HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + MSG msg; + WNDCLASS wc; + HWND hWnd; + + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC) WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = "OpenGL WinClass"; + + if(!RegisterClass(&wc)) + { + MessageBox(0,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR); + return FALSE; + } + w=GetSystemMetrics(SM_CXSCREEN); + h=GetSystemMetrics(SM_CYSCREEN); + hWnd = CreateWindow( + "OpenGL WinClass", + "Wax", + + WS_POPUP | + WS_CLIPCHILDREN | + WS_CLIPSIBLINGS, + + 0, 0, + w, h, + + NULL, + NULL, + hInstance, + NULL); + + if(!hWnd) + { + MessageBox(0,"Window Creation Error.","Error",MB_OK|MB_ICONERROR); + return FALSE; + } + + DEVMODE dmScreenSettings; // Режим работы + + memset(&dmScreenSettings, 0, sizeof(DEVMODE)); // Очистка для хранения установок + dmScreenSettings.dmSize = sizeof(DEVMODE); // Размер структуры Devmode + dmScreenSettings.dmPelsWidth = w; // Ширина экрана + dmScreenSettings.dmPelsHeight = h; // Высота экрана + dmScreenSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; // Режим Пиксела + ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); + + ShowWindow(hWnd, SW_SHOW); + UpdateWindow(hWnd); + SetFocus(hWnd); + + while (1) + { + // Обработка всех сообщений + while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) + { + if (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + else + { + return TRUE; + } + } + DrawGLScene(); // Нарисовать сцену + SwapBuffers(hDC); // Переключить буфер экрана + GetCursorPos(&mpos); + camy=camy-(mpos.x-ompos.x)/2; + camx=camx-(mpos.y-ompos.y)/2; + if(camx>90) camx=90; + if(camx<-90) camx=-90; + ompos=mpos; + + if(mpos.x>w-20) + { + ompos.x=20; + SetCursorPos(20,mpos.y); + } + if(mpos.x<20) + { + ompos.x=w-20; + SetCursorPos(w-20,mpos.y); + } + if (keys[VK_ESCAPE]) SendMessage(hWnd,WM_CLOSE,0,0); // Если ESC - выйти + if(keys['w']||keys['W']||keys['ц']||keys['Ц']) + { + pos.x=pos.x+cos(-camy* 0.01745329F+90); + pos.z=pos.z+sin(-camy* 0.01745329F+90); + } + if(keys['s']||keys['S']||keys['ы']||keys['Ы']) + { + pos.x=pos.x-cos(-camy* 0.01745329F+90); + pos.z=pos.z-sin(-camy* 0.01745329F+90); + } + if(keys['a']||keys['A']||keys['ф']||keys['Ф']) + { + pos.x=pos.x+sin(-camy* 0.01745329F+90); + pos.z=pos.z-cos(-camy* 0.01745329F+90); + } + if(keys['d']||keys['D']||keys['в']||keys['В']) + { + pos.x=pos.x-sin(-camy* 0.01745329F+90); + pos.z=pos.z+cos(-camy* 0.01745329F+90); + } + } +} diff --git a/prim.cpp b/prim.cpp new file mode 100644 index 0000000..024f2c5 --- /dev/null +++ b/prim.cpp @@ -0,0 +1,2 @@ +#include "prim.h" + diff --git a/prim.h b/prim.h new file mode 100644 index 0000000..af9172d --- /dev/null +++ b/prim.h @@ -0,0 +1,94 @@ +#pragma once +#include +#include +#include +#include +class Prim +{ +public: + float lx,ly,lz; + float rx,ry,rz; + float sx,sy,sz; + float cx,cy,cz; + int type; + GLUquadricObj *quadObj; + Prim() {} + Prim(char* ttype) + { + if(strstr(ttype,"box")!=NULL) type=1; + else type=2; + quadObj = gluNewQuadric(); + } + void draw() + { + GLfloat*c = new GLfloat[3]; + c[0]=cx; + c[1]=cy; + c[2]=cz; + glMaterialfv(GL_FRONT, GL_DIFFUSE, c); + glPushMatrix(); + //glLoadIdentity(); + glTranslatef(lx, ly, lz); + glRotatef(rx, 1.0, 0.0, 0.0); + glRotatef(ry, 0.0, 1.0, 0.0); + glRotatef(rz, 0.0, 0.0, 1.0); + glScalef(sx,sy,sz); + if(type==1) + { + glBegin(GL_POLYGON); + glNormal3f(0.0, 0.0, 2.0); + glVertex3f(2.0, 2.0, 2.0); + glVertex3f(-2.0, 2.0, 2.0); + glVertex3f(-2.0, -2.0, 2.0); + glVertex3f(2.0, -2.0, 2.0); + glEnd(); + + glBegin(GL_POLYGON); + glNormal3f(0.0, 0.0, -2.0); + glVertex3f(2.0, 2.0, -2.0); + glVertex3f(2.0, -2.0, -2.0); + glVertex3f(-2.0, -2.0, -2.0); + glVertex3f(-2.0, 2.0, -2.0); + glEnd(); + + glBegin(GL_POLYGON); + glNormal3f(-2.0, 0.0, 0.0); + glVertex3f(-2.0, 2.0, 2.0); + glVertex3f(-2.0, 2.0, -2.0); + glVertex3f(-2.0, -2.0, -2.0); + glVertex3f(-2.0, -2.0, 2.0); + glEnd(); + + glBegin(GL_POLYGON); + glNormal3f(2.0, 0.0, 0.0); + glVertex3f(2.0, 2.0, 2.0); + glVertex3f(2.0, -2.0, 2.0); + glVertex3f(2.0, -2.0, -2.0); + glVertex3f(2.0, 2.0, -2.0); + glEnd(); + + glBegin(GL_POLYGON); + glNormal3f(0.0, 2.0, 0.0); + glVertex3f(-2.0, 2.0, -2.0); + glVertex3f(-2.0, 2.0, 2.0); + glVertex3f(2.0, 2.0, 2.0); + glVertex3f(2.0, 2.0, -2.0); + glEnd(); + + glBegin(GL_POLYGON); + glNormal3f(0.0, -2.0, 0.0); + glVertex3f(-2.0, -2.0, -2.0); + glVertex3f(2.0, -2.0, -2.0); + glVertex3f(2.0, -2.0, 2.0); + glVertex3f(-2.0, -2.0, 2.0); + glEnd(); + } + else + { + gluQuadricDrawStyle(quadObj, GLU_FILL); + gluCylinder(quadObj, 2, 2, 2, 20, 20); + } + glPopMatrix(); + delete c; + } +}; diff --git a/wax.cbp b/wax.cbp new file mode 100644 index 0000000..af4d697 --- /dev/null +++ b/wax.cbp @@ -0,0 +1,50 @@ + + + + + + diff --git a/wax.depend b/wax.depend new file mode 100644 index 0000000..68e3d80 --- /dev/null +++ b/wax.depend @@ -0,0 +1,27 @@ +# depslib dependency file v1.0 +1296658495 source:c:\users\kostia\documents\codeblocks_projects\wax\prim.cpp + "prim.h" + +1296660979 source:c:\users\kostia\documents\codeblocks_projects\wax\waxloader.cpp + "waxloader.h" + +1296653771 c:\users\kostia\documents\codeblocks_projects\wax\waxloader.h + + + + "prim.h" + +1296664967 c:\users\kostia\documents\codeblocks_projects\wax\prim.h + + + + + +1296673218 source:c:\users\kostia\documents\codeblocks_projects\wax\main.cpp + + + + "prim.h" + "waxloader.h" + + diff --git a/wax.layout b/wax.layout new file mode 100644 index 0000000..3577aa6 --- /dev/null +++ b/wax.layout @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/waxloader.cpp b/waxloader.cpp new file mode 100644 index 0000000..3e69ddc --- /dev/null +++ b/waxloader.cpp @@ -0,0 +1,305 @@ +#include "waxloader.h" +void Wax::loadconfig(char*s) +{ + char *s2; + int i; + char *buf; + s=strstr(s,"root"); + s=strstr(s,"\""); + s+=1; + s2=s; + s2=(strstr(s2,",")); + i=s2-s; + buf = new char[i]; + for(int c=0; c +#include +#include +#include "prim.h" + +class Wax +{ +public: +Prim* p; +float bcx,bcy,bcz; +float anglex,angley; +float radius; +int count; + Wax() {} + Wax(char*path); + void loadconfig(char*s); + void loadprim(char*&s, Prim& p); +};