Bobbing
This commit is contained in:
parent
11a7308820
commit
16d9c5479e
|
@ -56,23 +56,10 @@ main :: proc() {
|
|||
ClearBackground(PAL[0])
|
||||
rlPushMatrix()
|
||||
rlRotatef(45, 0, 1, 0)
|
||||
DrawMesh(plane, mat, rl.MatrixIdentity())
|
||||
DrawMesh(plane, mat, rl.Matrix(1))
|
||||
rlPopMatrix()
|
||||
|
||||
|
||||
rlPushMatrix()
|
||||
rlTranslatef(player.position.x, player.position.y, player.position.z)
|
||||
rlTranslatef(player.cameraOffset.x, player.cameraOffset.y, player.cameraOffset.z)
|
||||
rlRotatef(math.to_degrees(player.direction), 0, 1, 0)
|
||||
rlRotatef(math.to_degrees(-player.yaw), 1, 0, 0)
|
||||
rlTranslatef(-1, -0.3, 1)
|
||||
rlScalef(0.5, 0.5, 0.5)
|
||||
DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
||||
rlTranslatef(0, 0, 1)
|
||||
rlScalef(0.4, 0.4, 1)
|
||||
DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
||||
|
||||
rlPopMatrix()
|
||||
player_draw(&player)
|
||||
|
||||
EndMode3D()
|
||||
EndDrawing()
|
||||
|
|
|
@ -8,6 +8,9 @@ Player :: struct {
|
|||
cameraOffset: Vec3,
|
||||
direction: f32,
|
||||
yaw: f32,
|
||||
bob_timer: f64,
|
||||
bob_position: Vec3,
|
||||
bob_factor: f32,
|
||||
camera: rl.Camera3D,
|
||||
}
|
||||
|
||||
|
@ -26,6 +29,7 @@ player_create :: proc() -> Player {
|
|||
|
||||
player_update :: proc(using player: ^Player, delta: f32) {
|
||||
using rl
|
||||
bob_timer += f64(delta)
|
||||
mouseDelta := GetMouseDelta()
|
||||
|
||||
direction -= mouseDelta.x * 0.003
|
||||
|
@ -44,15 +48,41 @@ player_update :: proc(using player: ^Player, delta: f32) {
|
|||
if IsKeyDown(KeyboardKey.A) {motion += right * 0.1}
|
||||
if IsKeyDown(KeyboardKey.D) {motion -= right * 0.1}
|
||||
motion = rl.Vector3ClampValue(motion, 0, 0.2)
|
||||
velocity.xz = motion.xz
|
||||
position += velocity
|
||||
if Vector3Length(motion) != 0 {
|
||||
bob_factor = min(bob_factor + delta * 3, 1)
|
||||
} else {
|
||||
bob_factor = max(bob_factor - delta * 5, 0)
|
||||
}
|
||||
velocity.xz = Vector3MoveTowards(velocity, motion * 100, 100 * delta).xz
|
||||
position += velocity * delta
|
||||
|
||||
camera.position = position + cameraOffset
|
||||
bob_position = Vec3{math.sin_f32(f32(bob_timer * math.PI * 2 + math.PI/4)), math.sin_f32(f32(bob_timer*math.PI * 4)), 0} * bob_factor * 0.3
|
||||
bob_position = Vector3RotateByAxisAngle(bob_position, Vec3{0,1,0}, direction)
|
||||
|
||||
camera.position = position + cameraOffset + bob_position
|
||||
target := Vec3{
|
||||
math.sin(direction) * math.cos(yaw),
|
||||
math.sin(yaw),
|
||||
math.cos(direction) * math.cos(yaw),
|
||||
}
|
||||
camera.target = position + cameraOffset + target
|
||||
camera.target = position + cameraOffset + target + bob_position
|
||||
}
|
||||
|
||||
player_draw :: proc(using player: ^Player) {
|
||||
using rl
|
||||
|
||||
|
||||
rlPushMatrix()
|
||||
offset := position + cameraOffset + bob_position
|
||||
rlTranslatef(offset.x, offset.y, offset.z)
|
||||
rlRotatef(math.to_degrees(player.direction), 0, 1, 0)
|
||||
rlRotatef(math.to_degrees(-player.yaw), 1, 0, 0)
|
||||
rlTranslatef(-1, -0.3, 1)
|
||||
rlScalef(0.5, 0.5, 0.5)
|
||||
DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
||||
rlTranslatef(0, 0, 1)
|
||||
rlScalef(0.4, 0.4, 1)
|
||||
DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
||||
|
||||
rlPopMatrix()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue