Skip to content

Commit

Permalink
Standardized cameraRatio options, even though apparently GameFreak ha…
Browse files Browse the repository at this point in the history
…s done all the work on the camera stuff.

Signed-off-by: Adam Hintz <adam.o.dev@gmail.com>
  • Loading branch information
adam000 committed Jul 7, 2010
1 parent db81cef commit 85f4117
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 118 deletions.
4 changes: 3 additions & 1 deletion Conceptual/List of comment tags.txt
Expand Up @@ -12,4 +12,6 @@ Tags:
[DEMO3] - Something to be done by Demo 3.
[FIX] - Code that needs to somehow be fixed.
[WIP] - Code that is a work in progress and should not be removed or messed with except by its author (or with permission).
[HARDCODED] - Marks code that is hardcoded and should be made more flexible in the future.
[HARDCODE] or [HARDCODED] - Marks code that is hardcoded and should be made more flexible in the future.
[TEMPORARY] - Code that will eventually be deleted
[CLEANUP] - Code that's nasty that needs to be cleaned up
60 changes: 29 additions & 31 deletions Resources/Scripts/Modes/Demo3.lua
Expand Up @@ -45,8 +45,6 @@ end
mouse_movement = false
mousePos = vec(0, 0)
mouseStart = 0
cameraRatioOrig = nil
cameraRatioT = cameraRatio
function init ()
start_time = mode_manager.time()
Expand Down Expand Up @@ -138,61 +136,61 @@ function update ()
--]]
--[[ this structure needs to be removed
if cameraRatioNum > 5 and cameraChanging == false then
if cameraRatio.num > 5 and cameraChanging == false then
-- this is constantly modified, but not done smoothly, so it looks bad
if cameraRatioNum == 6 then
if cameraRatio.num == 6 then
local diff = { x = math.abs(computerShip.physicsObject.position.x - playerShip.physicsObject.position.x) + computerShip.size.x / 2, y = math.abs(computerShip.physicsObject.position.y - playerShip.physicsObject.position.y) + computerShip.size.y / 2 }
cameraRatioOrig = cameraRatio
cameraRatio.orig = cameraRatio.curr
if (math.abs(hypot1(diff) / hypot1(camera)) > 0.5) then
cameraChanging = true
x = 0.6
timeInterval = 0.6
cameraRatioOrig = cameraRatio
cameraRatio.orig = cameraRatio.curr
else
if diff.x == 0 or diff.y == 0 or aspectRatio == 0 then
cameraRatio = 2
cameraRatio.curr = 2
else
cameraRatio = (440) / (hypot1(diff) * 2)
cameraRatio.curr = (440) / (hypot1(diff) * 2)
end
end
else
print("DONT DO EET") -- temp error message because cameraRatioNum is greater than 5 but not equal to 6, somehow
print("DONT DO EET") -- temp error message because cameraRatio.num is greater than 5 but not equal to 6, somehow
end
if cameraRatio > 2 then
cameraRatio = 2
if cameraRatio.curr > 2 then
cameraRatio.curr = 2
end
if (cameraRatio < 1 / 8 and cameraRatioOrig > 1 / 8) or (cameraRatio > 1 / 8 and cameraRatioOrig < 1 / 8) then
if (cameraRatio.curr < 1 / 8 and cameraRatio.orig > 1 / 8) or (cameraRatio.curr > 1 / 8 and cameraRatio.orig < 1 / 8) then
sound.play("ZoomChange")
end
camera = { w = 640 / cameraRatio, h }
camera = { w = 640 / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
arrowLength = ARROW_LENGTH / cameraRatio
arrowVar = ARROW_VAR / cameraRatio
arrowDist = ARROW_DIST / cameraRatio
arrowLength = ARROW_LENGTH / cameraRatio.curr
arrowVar = ARROW_VAR / cameraRatio.curr
arrowDist = ARROW_DIST / cameraRatio.curr
end--]]

if cameraChanging == true then
x = x - dt
if x < 0 then
x = 0
cameraChanging = false
playerShip.beam.width = cameraRatio
playerShip.beam.width = cameraRatio.curr
soundJustPlayed = false
end
if x >= 0 then
cameraRatio = cameraRatioOrig + cameraRatioOrig * multiplier * math.pow(math.abs((x - timeInterval) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]]
-- print(cameraRatio, timeInterval)
cameraRatio.curr = cameraRatio.orig + cameraRatio.orig * multiplier * math.pow(math.abs((x - timeInterval) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]]
-- print(cameraRatio.curr, timeInterval)
end
camera = { w = 640 / cameraRatio, h }
camera = { w = 640 / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
arrowLength = ARROW_LENGTH / cameraRatio
arrowVar = ARROW_VAR / cameraRatio
arrowDist = ARROW_DIST / cameraRatio
if (cameraRatio < 1 / 8 and cameraRatioOrig > 1 / 8) or (cameraRatio > 1 / 8 and cameraRatioOrig < 1 / 8) then
arrowLength = ARROW_LENGTH / cameraRatio.curr
arrowVar = ARROW_VAR / cameraRatio.curr
arrowDist = ARROW_DIST / cameraRatio.curr
if (cameraRatio.curr < 1 / 8 and cameraRatio.orig > 1 / 8) or (cameraRatio.curr > 1 / 8 and cameraRatio.orig < 1 / 8) then
if soundJustPlayed == false then
sound.play("ZoomChange")
soundJustPlayed = true
Expand Down Expand Up @@ -420,7 +418,7 @@ function render ()
else
warpStatus = 0.0
end
graphics.begin_warp(warpStatus, (2.5*math.pi) - math.atan2(playerShip.physicsObject.velocity.x, playerShip.physicsObject.velocity.y), cameraRatio)
graphics.begin_warp(warpStatus, (2.5*math.pi) - math.atan2(playerShip.physicsObject.velocity.x, playerShip.physicsObject.velocity.y), cameraRatio.curr)
-- extract camera coordinates from here during update() and place finalized numbers here
graphics.set_camera(-playerShip.physicsObject.position.x + shipAdjust - (camera.w / 2.0), -playerShip.physicsObject.position.y - (camera.h / 2.0), -playerShip.physicsObject.position.x + shipAdjust + (camera.w / 2.0), -playerShip.physicsObject.position.y + (camera.h / 2.0))
graphics.draw_starfield(3.4)
Expand Down Expand Up @@ -448,7 +446,7 @@ function render ()
graphics.draw_line({ x = i * GRID_DIST_BLUE, y = -60000 }, { x = i * GRID_DIST_BLUE, y = 60000 }, 1, ClutColour(4, 8))
end
else
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
graphics.draw_line({ x = -60000, y = -i * GRID_DIST_BLUE }, { x = 60000, y = -i * GRID_DIST_BLUE }, 1, ClutColour(4, 11))
graphics.draw_line({ x = -60000, y = i * GRID_DIST_BLUE }, { x = 60000, y = i * GRID_DIST_BLUE }, 1, ClutColour(4, 11))
graphics.draw_line({ x = -i * GRID_DIST_BLUE, y = -60000 }, { x = -i * GRID_DIST_BLUE, y = 60000 }, 1, ClutColour(4, 11))
Expand All @@ -464,7 +462,7 @@ function render ()
function drawPlanet(planet)
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
local planetCoord = graphics.sprite_dimensions("Planets/" .. planet.image)
graphics.draw_sprite("Planets/" .. planet.image, planet.position, planetCoord, 1)
else
Expand All @@ -484,7 +482,7 @@ function render ()
------------------]]--
if computerShip ~= nil then
if computerShip.life > 0 then
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
graphics.draw_sprite("Ships/Gaitori/Carrier", computerShip.physicsObject.position, computerShip.size, computerShip.physicsObject.angle)
else
graphics.draw_rdia(computerShip.physicsObject.position, 60, ClutColour(16, 1) )
Expand All @@ -493,7 +491,7 @@ function render ()
-- This explosion code is a hack. We need a way to deal with explosions in a better method.
-- Let's figure it out when we get Sfiera's data
if computerShip ~= nil then
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
graphics.draw_sprite(bestExplosion.image, computerShip.physicsObject.position, bestExplosion.size, frame / 6 * math.pi)
end
if frame == 0 then
Expand All @@ -510,7 +508,7 @@ function render ()
if otherShip ~= nil then
num = 1
while otherShip[num] ~= nil do
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
if otherShip[num].name ~= "Transport" then
graphics.draw_sprite(otherShip[num].image, otherShip[num].physicsObject.position, otherShip[num].size, otherShip[num].physicsObject.angle)
else
Expand Down Expand Up @@ -558,7 +556,7 @@ function render ()
graphics.end_warp()
if cameraRatio > 1 / 8 then
if cameraRatio.curr > 1 / 8 then
graphics.draw_sprite(playerShip.image, playerShip.physicsObject.position, playerShip.size, playerShip.physicsObject.angle)
else
graphics.draw_rtri(playerShip.physicsObject.position, 60)
Expand Down
12 changes: 6 additions & 6 deletions Resources/Scripts/Modes/Demo4.lua
Expand Up @@ -15,7 +15,7 @@ import('Physics')
import('Effects')

mdown = false
mrad = MOUSE_RADIUS / cameraRatio
mrad = MOUSE_RADIUS / cameraRatio.curr
aimMethod = "smart"

function init()
Expand Down Expand Up @@ -291,16 +291,16 @@ function render()
CameraToObject(scen.playerShip)
graphics.begin_warp(scen.playerShip.warp.factor,scen.playerShip.physics.angle, cameraRatio)
graphics.begin_warp(scen.playerShip.warp.factor,scen.playerShip.physics.angle, cameraRatio.curr)
graphics.draw_starfield(3.4)
graphics.draw_starfield(1.8)
graphics.draw_starfield(0.6)
graphics.draw_starfield(-0.3)
graphics.draw_starfield(-0.9)
-- DEBUG version, keep:
-- graphics.end_warp(scen.playerShip.warp.factor, scen.playerShip.physics.angle, cameraRatio, scen.playerShip.physics.position)
-- DEBUG version, keep:
-- graphics.end_warp(scen.playerShip.warp.factor, scen.playerShip.physics.angle, cameraRatio.curr, scen.playerShip.physics.position)
graphics.end_warp()
DrawGrid()
Expand Down Expand Up @@ -525,7 +525,7 @@ function DrawObject(o)
end
end
else
if cameraRatio >= 1 / 4 then
if cameraRatio.curr >= 1 / 4 then
if o.type == "animation" then
graphics.draw_sprite_frame(o.gfx.sprite, o.physics.position, o.gfx.dimensions, Animate(o))
else -- Rotational
Expand All @@ -542,7 +542,7 @@ function DrawObject(o)
color = ClutColour(16,1)
end
local iconScale = 1.0/cameraRatio
local iconScale = 1.0 / cameraRatio.curr
if o.base["tiny-shape"] == "solid-square" then
graphics.draw_rbox(o.physics.position, o.base["tiny-size"] * iconScale, color)
elseif o.base["tiny-shape"] == "plus" then
Expand Down
74 changes: 43 additions & 31 deletions Resources/Scripts/Modules/Camera.lua
Expand Up @@ -3,10 +3,23 @@ WINDOW.width, WINDOW.height = window.size()

panels = { left = { width = 128, height = 768, center = { x = -WINDOW.width / 2, y = 0 } }, right = { width = 32, height = 768, center = { x = WINDOW.width / 2, y = 0 } } }

cameraRatio = 1
cameraRatioTarget = 1
--[[
[CR CONVERT]
cameraRatio.curr - cameraRatio.curr
cameraRatio.target - cameraRatio.target
??? - cameraRatio.num
--]]
cameraRatio = { curr = 1, orig = 1, num = 2, target = 1 }
-- how this works when not zooming: curr = target = CAMERA_RATIO_OPTIONS[num]
-- when moving, zooming from curr = CAMERA_RATIO_OPTIONS[num] to target, set num
-- to the proper value once we reachy the target
-- should I add a function that checks to make sure that the camera ratio is the
-- same as the target, and adjusting if not? [ADAM] [TODO]
aspectRatio = WINDOW.width / WINDOW.height
camera = { w = WINDOW.width / cameraRatio, h }
camera = { w = WINDOW.width / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
timeInterval = 1
Expand All @@ -26,56 +39,55 @@ CAMERA_RATIO_OPTIONS = {
function() -- Zoom to 2:1
return 2
end,
function() -- Zoom to 1:1
return 1
end,
function() -- Zoom to 1:2
return 1/2
end,
function() --
function() -- Zoom to 1:4
return 1/4
end,
function()
function() -- Zoom to 1:16
return 1/16
end,
function() -- zoom to nearest hostile object
return 1/8 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this
end,
function() -- zoom to nearest object
return 1/9 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this
end,
function() -- zoom to all
return 1/10 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this
end
}
CAMERA_RATIO = { curr = 1, num = 2, target = 1 }
-- how this works when not zooming: curr = target = CAMERA_RATIO_OPTIONS[num]
-- when moving, zooming from curr = CAMERA_RATIO_OPTIONS[num] to target, set num
-- to the proper value once we reachy the target

-- should I add a function that checks to make sure that the camera ratio is the
-- same as the target, and adjusting if not? [ADAM] [TODO]

function CameraInterpolate(dt) -- note: this function now controlls both quadratic zooming and snap zooming (not good from a code design philosophy)
if cameraChanging == true then
zoomTime = zoomTime - dt
if zoomTime < 0 then
zoomTime = 0
cameraChanging = false
-- scen.playerShip.weapon.beam.width = cameraRatio
-- scen.playerShip.weapon.beam.width = cameraRatio.curr
soundJustPlayed = false
end
if zoomTime >= 0 then
cameraRatio = cameraRatioOrig + cameraRatioOrig * multiplier * math.pow(math.abs((timeInterval - zoomTime) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]]
cameraRatio.curr = cameraRatio.orig + cameraRatio.orig * multiplier * math.pow(math.abs((timeInterval - zoomTime) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]]
end
camera = { w = WINDOW.width / cameraRatio, h }
camera = { w = WINDOW.width / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
arrowLength = ARROW_LENGTH / cameraRatio
arrowVar = ARROW_VAR / cameraRatio
arrowDist = ARROW_DIST / cameraRatio
if (cameraRatio < 1 / 4 and cameraRatioOrig > 1 / 4) or (cameraRatio > 1 / 4 and cameraRatioOrig < 1 / 4) then
arrowLength = ARROW_LENGTH / cameraRatio.curr
arrowVar = ARROW_VAR / cameraRatio.curr
arrowDist = ARROW_DIST / cameraRatio.curr
if (cameraRatio.curr < 1 / 4 and cameraRatio.orig > 1 / 4) or (cameraRatio.curr > 1 / 4 and cameraRatio.orig < 1 / 4) then
if soundJustPlayed == false then
sound.play("ZoomChange")
soundJustPlayed = true
Expand All @@ -100,34 +112,34 @@ end
function CameraSnap()
if cameraChanging == true then
cameraRatio = cameraRatioTarget
camera = { w = WINDOW.width / cameraRatio, h }
cameraRatio.curr = cameraRatio.target
camera = { w = WINDOW.width / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
arrowLength = ARROW_LENGTH / cameraRatio
arrowVar = ARROW_VAR / cameraRatio
arrowDist = ARROW_DIST / cameraRatio
arrowLength = ARROW_LENGTH / cameraRatio.curr
arrowVar = ARROW_VAR / cameraRatio.curr
arrowDist = ARROW_DIST / cameraRatio.curr
end
end
-- Adam's replacement for CameraSnap()
function InstantCamera(zoomLevel)
zoomLevel = zoomLevel or 1 -- optional arguments, huzzah
print(zoomLevel, "ZOOM LEVEL")
CAMERA_RATIO.target = CAMERA_RATIO_OPTIONS[zoomLevel]() -- currently, no error checking
CAMERA_RATIO.curr = CAMERA_RATIO.target
cameraRatio.target = CAMERA_RATIO_OPTIONS[zoomLevel]() -- currently, no error checking
cameraRatio.curr = cameraRatio.target
ChangeCamAndWindow()
UpdateWindow()
end
function ChangeCamAndWindow()
camera = { w = WINDOW.width / CAMERA_RATIO.curr, h }
camera = { w = WINDOW.width / cameraRatio.curr, h }
camera.h = camera.w / aspectRatio
shipAdjust = .045 * camera.w
arrowLength = ARROW_LENGTH / CAMERA_RATIO.curr
arrowVar = ARROW_VAR / CAMERA_RATIO.curr
arrowDist = ARROW_DIST / CAMERA_RATIO.curr
arrowLength = ARROW_LENGTH / cameraRatio.curr
arrowVar = ARROW_VAR / cameraRatio.curr
arrowDist = ARROW_DIST / cameraRatio.curr
end
function CameraToObject(object)
Expand Down
6 changes: 6 additions & 0 deletions Resources/Scripts/Modules/GlobalVars.lua
Expand Up @@ -3,6 +3,12 @@ import('AresCLUT')
import('data')
import('Camera')

--[[
[TODO]
This file needs to be better split into chunks so that the information is
decipherable.
--]]
RELEASE_BUILD = mode_manager.is_release()
WARP_TIME = 1.2
Expand Down

0 comments on commit 85f4117

Please sign in to comment.