-
Notifications
You must be signed in to change notification settings - Fork 1
/
AnaglyphCamera.h
121 lines (85 loc) · 3.43 KB
/
AnaglyphCamera.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// OffAxisProjectionCamera.h
// starfield
//
// Created by Cyril Diagne on 04/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#ifndef starfield_AnaglyphCamera_h
#define starfield_AnaglyphCamera_h
#include "ofCamera.h"
class AnaglyphCamera : public ofCamera {
public:
//----------------------------------------
void beginBlue() {
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
ofRectangle viewport = ofGetCurrentViewport();
if(!isActive) ofPushView();
isActive = true;
ofSetCoordHandedness(OF_RIGHT_HANDED);
// autocalculate near/far clip planes if not set by user
calcClipPlanes(viewport);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLdouble aspect = viewport.width/viewport.height;
GLdouble top = tan(fov*1.5*3.14159/360.0) * nearClip;
GLdouble bottom = -1.18;
GLdouble left = - aspect * top * 0.50;
GLdouble right = aspect * top * 0.50;
//gluPerspective(fov, viewport.width/viewport.height, nearClip, farClip);
glFrustum(left, right, bottom, top, nearClip, farClip);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
ofViewport(viewport);
//store current matrices
if (bCacheMatrices)
{
glGetFloatv(GL_PROJECTION_MATRIX, matProjection.getPtr());
glGetFloatv(GL_MODELVIEW_MATRIX, matModelView.getPtr());
hasStoredMatrices = true;
}
}
void beginRed() {
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
//glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
ofRectangle viewport = ofGetCurrentViewport();
if(!isActive) ofPushView();
isActive = true;
ofSetCoordHandedness(OF_RIGHT_HANDED);
// autocalculate near/far clip planes if not set by user
calcClipPlanes(viewport);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLdouble aspect = viewport.width/viewport.height;
GLdouble top = tan(fov*1.5*3.14159/360.0) * nearClip;
GLdouble bottom = -1.18;
GLdouble left = - aspect * top * 0.48;
GLdouble right = aspect * top * 0.52;
//gluPerspective(fov, viewport.width/viewport.height, nearClip, farClip);
glFrustum(left, right, bottom, top, nearClip, farClip);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
ofViewport(viewport);
//store current matrices
if (bCacheMatrices)
{
glGetFloatv(GL_PROJECTION_MATRIX, matProjection.getPtr());
glGetFloatv(GL_MODELVIEW_MATRIX, matModelView.getPtr());
hasStoredMatrices = true;
}
}
// if begin(); pushes first, then we need an end to pop
//----------------------------------------
void end() {
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (isActive)
{
ofPopView();
isActive = false;
}
}
};
#endif