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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include "gl.h"
#include "glu.h"
#include "glaux.h"
#define CAMERASPEED 0.03f;
HGLRC hRC=NULL; // render
HDC hDC=NULL; // device
HWND hWnd=NULL;
HINSTANCE hInstance;
GLuint texture[1];
FILE *File;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
bool active = true;
bool fullscreen = false;
bool keys[256];
// camera
typedef struct tVector3
{
tVector3(){}
tVector3(float new_x, float new_y, float new_z)
{
x = new_x;
y = new_y;
z = new_z;
}
tVector3 operator+(tVector3 vVector)
{ return tVector3(vVector.x + x, vVector.y + y, vVector.z + z); }
tVector3 operator-(tVector3 vVector)
{ return tVector3(vVector.x - x, vVector.y - y, vVector.z - z); }
tVector3 operator*(float number)
{ return tVector3(x * number, y * number, z * number); }
tVector3 operator/(float number)
{ return tVector3(x/number, y/number, z/number); }
float x, y, z;
} tVector3;
tVector3 mPos; // camera position
tVector3 mView; // camera target (what we're looking at)
tVector3 mTilt; // camera tilt
void Position_Camera(float pos_x, float pos_y,
float pos_z, float view_x,
float view_y, float view_z,
float tilt_x, float tilt_y,
float tilt_z)
{
mPos = tVector3(pos_x, pos_y, pos_z); // position
mView = tVector3(view_x, view_y, view_z); // view
mTilt = tVector3(tilt_x, tilt_y, tilt_z); // vector
}
void Move_Camera(float speed)
{
tVector3 vVector = mView - mPos;
mPos.x += vVector.x * speed;
mPos.z += vVector.z * speed;
mView.x += vVector.x * speed;
mView.z += vVector.z * speed;
}
void Rotate_Camera(float speed)
{
tVector3 vVector = mView - mPos;
mView.z = (float)(mPos.z + sin(speed) * vVector.x + cos(speed) * vVector.z);
mView.x = (float)(mPos.x + cos(speed) * vVector.x - sin(speed) * vVector.z);
}
void Keyboard_Input()
{
if((GetKeyState(VK_UP) & 0x80))
{
Move_Camera( CAMERASPEED);
}
if((GetKeyState(VK_DOWN) & 0x80))
{
Move_Camera(-CAMERASPEED);
}
if((GetKeyState(VK_LEFT) & 0x80))
{
Rotate_Camera(-CAMERASPEED);
}
if((GetKeyState(VK_RIGHT) & 0x80))
{
Rotate_Camera( CAMERASPEED);
}
}
|