Closer to actually editing
This commit is contained in:
@@ -1,28 +1,55 @@
|
||||
import math
|
||||
import time
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
from dusk.defs import defs
|
||||
from editortool.map.map import map
|
||||
|
||||
pixelsPerUnit = float(defs.get('RPG_CAMERA_PIXELS_PER_UNIT'))
|
||||
yOffset = float(defs.get('RPG_CAMERA_Z_OFFSET'))
|
||||
fov = float(defs.get('RPG_CAMERA_FOV'))
|
||||
scale = 8.0
|
||||
class Camera:
|
||||
def __init__(self):
|
||||
self.pixelsPerUnit = float(defs.get('RPG_CAMERA_PIXELS_PER_UNIT'))
|
||||
self.yOffset = float(defs.get('RPG_CAMERA_Z_OFFSET'))
|
||||
self.fov = float(defs.get('RPG_CAMERA_FOV'))
|
||||
self.scale = 8.0
|
||||
self.lastTime = time.time()
|
||||
self.lookAtTarget = [0.0, 0.0, 0.0]
|
||||
|
||||
def setupCamera(vw, vh):
|
||||
z = (vh / 2.0) / (
|
||||
(pixelsPerUnit * scale) * math.tan(math.radians(fov / 2.0))
|
||||
)
|
||||
lookAt = ( 0, 0, 0 )
|
||||
aspectRatio = vw / vh
|
||||
position = lookAt[0], lookAt[1] - yOffset, lookAt[2] + z
|
||||
def setup(self, vw, vh, duration=0.1):
|
||||
now = time.time()
|
||||
delta = now - self.lastTime
|
||||
self.lastTime = now
|
||||
# Calculate ease factor for exponential smoothing over 'duration' seconds
|
||||
ease = 1 - math.exp(-delta / duration)
|
||||
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
gluPerspective(fov, aspectRatio, 0.1, 1000.0)
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
gluLookAt(
|
||||
position[0], position[1], position[2],
|
||||
lookAt[0], lookAt[1], lookAt[2],
|
||||
0.0, 1.0, 0.0
|
||||
)
|
||||
z = (vh / 2.0) / (
|
||||
(self.pixelsPerUnit * self.scale) * math.tan(math.radians(self.fov / 2.0))
|
||||
)
|
||||
lookAt = [
|
||||
map.position[0] * float(defs.get('TILE_WIDTH')),
|
||||
map.position[1] * float(defs.get('TILE_HEIGHT')),
|
||||
map.position[2] * float(defs.get('TILE_DEPTH')),
|
||||
]
|
||||
aspectRatio = vw / vh
|
||||
|
||||
|
||||
# Ease the lookAt target
|
||||
for i in range(3):
|
||||
self.lookAtTarget[i] += (lookAt[i] - self.lookAtTarget[i]) * ease
|
||||
|
||||
# Camera position is now based on the eased lookAtTarget
|
||||
cameraPosition = (
|
||||
self.lookAtTarget[0],
|
||||
self.lookAtTarget[1] - self.yOffset,
|
||||
self.lookAtTarget[2] + z
|
||||
)
|
||||
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
gluPerspective(self.fov, aspectRatio, 0.1, 1000.0)
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
gluLookAt(
|
||||
cameraPosition[0], cameraPosition[1], cameraPosition[2],
|
||||
self.lookAtTarget[0], self.lookAtTarget[1], self.lookAtTarget[2],
|
||||
0.0, 1.0, 0.0
|
||||
)
|
||||
Reference in New Issue
Block a user