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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include <rw.h>
#include <skeleton.h>
#include "subrast.h"
rw::Camera *Camera;
rw::Camera *SubCameras[4];
void
CameraSetViewWindow(rw::Camera *camera, float width, float height, float vw)
{
rw::V2d viewWindow;
// TODO: aspect ratio when fullscreen
if(width > height){
viewWindow.x = vw;
viewWindow.y = vw / (width/height);
}else{
viewWindow.x = vw / (height/width);
viewWindow.y = vw;
}
camera->setViewWindow(&viewWindow);
}
void
UpdateSubRasters(rw::Camera *mainCamera, rw::int32 mainWidth, rw::int32 mainHeight)
{
rw::Rect rect[4];
float width, height, border;
border = mainHeight*0.05f;
width = (mainWidth - border*3.0f) / 2.0f;
height = (mainHeight - border*3.0f) / 2.0f;
// top left
rect[0].x = border;
rect[0].y = border;
rect[0].w = width;
rect[0].h = height;
// top right
rect[1].x = border*2 + width;
rect[1].y = border;
rect[1].w = width;
rect[1].h = height;
// bottom left
rect[2].x = border;
rect[2].y = border*2 + height;
rect[2].w = width;
rect[2].h = height;
// bottom left
rect[3].x = border*2 + width;
rect[3].y = border*2 + height;
rect[3].w = width;
rect[3].h = height;
CameraSetViewWindow(SubCameras[0], width, height, 0.5f);
for(int i = 1; i < 4; i++)
CameraSetViewWindow(SubCameras[i], width, height, 0.5f + 0.4f);
for(int i = 0; i < 4; i++){
SubCameras[i]->frameBuffer->subRaster(mainCamera->frameBuffer, &rect[i]);
SubCameras[i]->zBuffer->subRaster(mainCamera->zBuffer, &rect[i]);
}
}
void
PositionSubCameras(void)
{
rw::Frame *frame;
rw::V3d pos;
const float dist = 2.5f;
// perspective
pos.x = pos.y = 0.0f;
pos.z = -4.0f;
frame = SubCameras[0]->getFrame();
frame->translate(&pos, rw::COMBINEREPLACE);
// look along z
pos.x = pos.y = 0.0f;
pos.z = -dist;
frame = SubCameras[1]->getFrame();
frame->translate(&pos, rw::COMBINEREPLACE);
// look along x
pos.x = -dist;
pos.y = pos.z = 0.0f;
frame = SubCameras[2]->getFrame();
frame->rotate(&Yaxis, 90.0f, rw::COMBINEREPLACE);
frame->translate(&pos, rw::COMBINEPOSTCONCAT);
// look along y
pos.x = pos.z = 0.0f;
pos.y = -dist;
frame = SubCameras[3]->getFrame();
frame->rotate(&Xaxis, -90.0f, rw::COMBINEREPLACE);
frame->translate(&pos, rw::COMBINEPOSTCONCAT);
}
void
CreateCameras(rw::World *world)
{
Camera = sk::CameraCreate(sk::globals.width, sk::globals.height, 1);
assert(Camera);
for(int i = 0; i < 4; i++){
SubCameras[i] = sk::CameraCreate(0, 0, 1);
assert(SubCameras[i]);
SubCameras[i]->setNearPlane(0.1f);
SubCameras[i]->setFarPlane(30.0f);
world->addCamera(SubCameras[i]);
if(i > 0)
SubCameras[i]->setProjection(rw::Camera::PARALLEL);
}
PositionSubCameras();
}
void
DestroyCameras(rw::World *world)
{
if(Camera){
sk::CameraDestroy(Camera);
Camera = nil;
}
for(int i = 0; i < 4; i++)
if(SubCameras[i]){
world->removeCamera(SubCameras[i]);
sk::CameraDestroy(SubCameras[i]);
SubCameras[i] = nil;
}
}
|