-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStereoCamera.cpp
More file actions
80 lines (65 loc) · 2.54 KB
/
StereoCamera.cpp
File metadata and controls
80 lines (65 loc) · 2.54 KB
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
/*
* StereoCamera.cpp
* 3d Ink
*
* Code provided by Geng Sun, Durham University
*
*/
#include <cmath>
#include "Camera.h"
void StereoCamera::setupFrustum(GLdouble nearDisplayBoundary, GLdouble farDisplayBoundary, GLdouble nearSceneBoundary, GLdouble farSceneBoundary) {
// calculate screen disparity ranges
GLdouble nearDisparity = eyeSeperation*(zViewing - nearDisplayBoundary)/nearDisplayBoundary;
GLdouble farDisparity = eyeSeperation*(farDisplayBoundary-zViewing)/farDisplayBoundary;
GLdouble ratio = nearDisparity/farDisparity;
// distance to the vitrual display
sceneZ = (farSceneBoundary*nearSceneBoundary+farSceneBoundary*nearSceneBoundary*ratio)/(farSceneBoundary+nearSceneBoundary*ratio);
sceneWidth = sceneZ * tan(theta/2.0);
sceneHeight = sceneWidth * displayRatio;
GLdouble distanceToScene = sceneWidth / halfWidth;
// calculate camera position
// check that this means angle of seperation
GLdouble angleSeperation = nearSceneBoundary*distanceToScene*nearDisparity/(sceneZ-nearSceneBoundary);
cameraSeperation = angleSeperation*2;
// Left camera position
leftFrom = angleSeperation;
leftTo[0] = angleSeperation;
leftTo[2] = sceneZ;
// Left camera frustum
leftFrustum[0] = -(nearSceneBoundary * ((sceneWidth - angleSeperation) / sceneZ)); // Left
leftFrustum[1] = (nearSceneBoundary * ((sceneWidth + angleSeperation) / sceneZ)); // Right
leftFrustum[2] = -(nearSceneBoundary * sceneHeight / sceneZ); // Bottom
leftFrustum[3] = (nearSceneBoundary * sceneHeight / sceneZ); // Top
leftFrustum[4] = nearSceneBoundary; // Near
leftFrustum[5] = farSceneBoundary; // Far
// Right camera position
rightFrom = -angleSeperation;
rightTo[0] = -angleSeperation;
rightTo[2] = sceneZ;
// Right camera frustum
rightFrustum[0] = -(nearSceneBoundary * ((sceneWidth + angleSeperation) / sceneZ)); // Left
rightFrustum[1] = (nearSceneBoundary * ((sceneWidth - angleSeperation) / sceneZ)); // Right
rightFrustum[2] = -(nearSceneBoundary * sceneHeight / sceneZ); // Bottom
rightFrustum[3] = (nearSceneBoundary * sceneHeight / sceneZ); // Top
rightFrustum[4] = nearSceneBoundary; // Near
rightFrustum[5] = farSceneBoundary; // Far
Model::getInstance()->vAngle=theta;
}
double* StereoCamera::getLeftFrustum() {
return leftFrustum;
}
double* StereoCamera::getRightFrustum() {
return rightFrustum;
}
double StereoCamera::getLeftFrom() {
return leftFrom;
}
double* StereoCamera::getLeftTo() {
return leftTo;
}
double StereoCamera::getRightFrom() {
return rightFrom;
}
double* StereoCamera::getRightTo() {
return rightTo;
}