aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorrichiesams2013-08-30 17:10:31 -0500
committerWillem Jan Palenstijn2013-09-24 13:59:39 +0200
commit94f350b1542e3129ad6c9597fe3fefdface444ae (patch)
tree86aaa0f96ceb94965c357b6e4516529b20201c54 /engines
parent3c3a6bd93542ad82bd7972050db141628b413b30 (diff)
downloadscummvm-rg350-94f350b1542e3129ad6c9597fe3fefdface444ae.tar.gz
scummvm-rg350-94f350b1542e3129ad6c9597fe3fefdface444ae.tar.bz2
scummvm-rg350-94f350b1542e3129ad6c9597fe3fefdface444ae.zip
ZVISION: Implement TILT RenderTable creation
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/render_table.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp
index 0a83d5e4ae..b457ae0240 100644
--- a/engines/zvision/render_table.cpp
+++ b/engines/zvision/render_table.cpp
@@ -189,12 +189,35 @@ void RenderTable::generatePanoramaLookupTable() {
}
void RenderTable::generateTiltLookupTable() {
- for (uint x = 0; x < _numColumns; x++) {
- for (uint y = 0; y < _numRows; y++) {
- uint32 index = y * _numColumns + x;
+ float halfWidth = (float)_numColumns / 2.0f;
+ float halfHeight = (float)_numRows / 2.0f;
+
+ float fovInRadians = (_tiltOptions.fieldOfView * M_PI / 180.0f);
+ float cylinderRadius = halfWidth / tan(fovInRadians);
+
+ for (uint y = 0; y < _numRows; y++) {
+
+ // Add an offset of 0.01 to overcome zero tan/atan issue (horizontal line on half of screen)
+ // Alpha represents the horizontal angle between the viewer at the center of a cylinder and y
+ float alpha = atan(((float)y - halfHeight + 0.01f) / cylinderRadius);
+
+ // To get y in cylinder coordinates, we just need to calculate the arc length
+ // We also scale it by _tiltOptions.linearScale
+ int32 yInCylinderCoords = int32(floor((cylinderRadius * _tiltOptions.linearScale * alpha) + halfHeight));
- _internalBuffer[index].x = 0;
- _internalBuffer[index].y = 0;
+ float cosAlpha = cos(alpha);
+ uint32 columnIndex = y * _numColumns;
+
+ for (uint x = 0; x < _numColumns; x++) {
+ // To calculate x in cylinder coordinates, we can do similar triangles comparison,
+ // comparing the triangle from the center to the screen and from the center to the edge of the cylinder
+ int32 xInCylinderCoords = int32(floor(halfWidth + ((float)x - halfWidth) * cosAlpha));
+
+ uint32 index = columnIndex + x;
+
+ // Only store the (x,y) offsets instead of the absolute positions
+ _internalBuffer[index].x = xInCylinderCoords - x;
+ _internalBuffer[index].y = yInCylinderCoords - y;
}
}
}