-
Notifications
You must be signed in to change notification settings - Fork 1
/
local.cpp
executable file
·93 lines (80 loc) · 2.31 KB
/
local.cpp
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
#include "local.h"
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <windows.h>
#include <gl/gl.h>
using namespace std;
// RandRange
int RandRange( int min, int max )
{
return (rand() % (max-min+1)) + min ;
}
float RandRange( float min, float max )
{
double d = max - min; // difference
if( d==0.0 ) return min;
// diferrense = mant * e^exp
int exp;
double mant = frexp( d, &exp );
int precision = 1000; // more accurate
mant *= precision;
double new_mant = rand() % (int)mant;
new_mant /= precision;
return min + (float)ldexp( new_mant, exp ); // return min + (new_mant * e^exp)
}
// TRS
// from the translate, rotate and scale calculate and return the
// correct mat4x4. AKA: mat4 = ToMat4(translate) * ToMat4(rotate) * ToMat4(scale)
void TRS( vec3_t& translate, mat3_t& rotate, float scale, mat4_t& transform )
{
transform.LoadIdent();
transform.LoadMat3( rotate*scale );
transform[0][3] = translate.x();
transform[1][3] = translate.y();
transform[2][3] = translate.z();
}
// RenderCube
void RenderCube()
{
glBegin( GL_QUADS );
// Front Face
glNormal3f( 0.0f, 0.0f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// Back Face
glNormal3f( 0.0f, 0.0f,-0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
// Top Face
glNormal3f( 0.0f, 0.5f, 0.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
// Bottom Face
glNormal3f( 0.0f,-0.5f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
// Right face
glNormal3f( 0.5f, 0.0f, 0.0f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
// Left Face
glNormal3f(-0.5f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();
}