-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewing3D.c
92 lines (76 loc) · 2.34 KB
/
viewing3D.c
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
/*
* viewing3D.c
* VIEWING3D implementation file - contains the code for stuff
* regarding 3D stuff.
* INIT implementation file - contains the code used to initialize
* stuff.
*
* badpointer - Nov/2011
*/
/* "Imports" */
/* ------------------------------------------------------------------ */
#include <GL/glut.h>
#include "viewing3D.h"
#include "globals.h"
/* ------------------------------------------------------------------ */
/* public methods */
/* ------------------------------------------------------------------ */
void project( void )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(toggleMode){
//gluPerspective(fov, asp, dim/4, 4*dim);
gluPerspective(fov, asp, zNear, zFar);
}
else{
//glOrtho(-dim*asp, +dim*asp, -dim, +dim, -dim, +dim);
glOrtho(left, right, bottom, top, zNear, zFar);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void transfWindowViewport( void )
{
float aspectRatio;
float middleX, middleY;
float newWindowHeightXOY, newWindowWidthXOY;
/* Do nothing if the window has been minimized */
if( (windowHeight < 1) || (windowWidth<1) )
return;
/* establish the window*/
/* use window dimentions to determin aspect ratio */
/* occupie biggest possible area without distortions */
if( windowWidth <= windowHeight )
{
/* adjust window height on XOY plane */
/* aspect ratio of output window */
aspectRatio = (float) windowHeight / (float) windowWidth;
/* for the window on XOY plane */
middleY = (float) ( bottom + top ) / 2.0;
newWindowHeightXOY = aspectRatio * ( right - left );
/* keep the center of window on the plane */
bottom = middleY - newWindowHeightXOY / 2;
top = middleY + newWindowHeightXOY / 2;
}
else
{
/* adjust window height on XOY plane */
/* aspect ratio of output window */
aspectRatio = (float) windowWidth / (float) windowHeight;
/* for the window on XOY plane */
middleX = (float) ( left + right ) / 2.0;
newWindowWidthXOY = aspectRatio * ( top - bottom );
/* keep the center of window on the plane */
left = middleX - newWindowWidthXOY / 2;
right = middleX + newWindowWidthXOY / 2;
}
/* establish visual volume */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
asp = aspectRatio;
/*Use all output window */
glViewport( 0, 0, windowWidth, windowHeight);
project();
}
/* ------------------------------------------------------------------ */