stuff
This commit is contained in:
parent
39dce85312
commit
e079e3743f
44
main.go
44
main.go
@ -15,9 +15,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
cameraDistance = float32(64.0)
|
||||
cameraYaw = float32(45.0)
|
||||
cameraPitch = float32(30.0)
|
||||
cameraDistance = float32(20.0)
|
||||
cameraYaw = float32(145.0)
|
||||
cameraPitch = float32(90.0)
|
||||
)
|
||||
|
||||
type Tile struct {
|
||||
@ -157,12 +157,6 @@ func UpdatePlayer(player *Player, deltaTime float32, mapGrid [][]Tile, camera *r
|
||||
player.PosTile = targetTile // Update the player's tile position
|
||||
player.TargetPath = player.TargetPath[1:] // Move to the next tile in the path
|
||||
}
|
||||
|
||||
// Update camera target and position
|
||||
camera.Target = player.PosActual
|
||||
camera.Position.X = player.PosActual.X
|
||||
camera.Position.Y = player.PosActual.Y
|
||||
camera.Position.Z = player.PosActual.Z + cameraDistance
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,19 +188,16 @@ func main() {
|
||||
}
|
||||
|
||||
// Initialize 3D camera
|
||||
|
||||
cameraDistance := float32(64.0)
|
||||
cameraYaw := float32(45.0)
|
||||
cameraPitch := float32(30.0)
|
||||
|
||||
camera := rl.Camera3D{
|
||||
Position: rl.NewVector3(player.PosActual.X, player.PosActual.Y, player.PosActual.Z+cameraDistance), // Updated camera position
|
||||
Target: player.PosActual, // The point the camera looks at (player)
|
||||
Up: rl.NewVector3(0, 1, 0), // Camera up vector (y-axis is up)
|
||||
Fovy: 45.0, // Field of view
|
||||
Projection: rl.CameraPerspective, // Perspective camera mode
|
||||
Position: rl.NewVector3(player.PosActual.X+cameraDistance, player.PosActual.Y+cameraDistance, player.PosActual.Z+cameraDistance),
|
||||
Target: player.PosActual, // The point the camera looks at (player)
|
||||
Up: rl.NewVector3(0, 1, 0), // Camera up vector (y-axis is up)
|
||||
Fovy: 45.0, // Field of view
|
||||
Projection: rl.CameraPerspective, // Perspective camera mode
|
||||
}
|
||||
|
||||
camera.Target = player.PosActual
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
@ -215,23 +206,17 @@ func main() {
|
||||
frameCnt++
|
||||
frameCnt %= 60
|
||||
|
||||
HandleInput(&player, mapGrid, &camera)
|
||||
UpdatePlayer(&player, deltaTime, mapGrid, &camera)
|
||||
|
||||
// Update camera based on mouse wheel
|
||||
wheelMove := rl.GetMouseWheelMove()
|
||||
if wheelMove != 0 {
|
||||
cameraDistance += wheelMove * 5
|
||||
if cameraDistance < 10 {
|
||||
cameraDistance = 10
|
||||
cameraDistance += -wheelMove * 5
|
||||
if cameraDistance < 1 {
|
||||
cameraDistance = 1
|
||||
} else if cameraDistance > 100 {
|
||||
cameraDistance = 100
|
||||
}
|
||||
}
|
||||
|
||||
// Update camera position directly above the player
|
||||
camera.Target = player.PosActual // Ensure the camera always looks at the player
|
||||
|
||||
// Update camera based on arrow keys (camera orbits player)
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
cameraYaw -= 60 * deltaTime // Rotate right
|
||||
@ -252,7 +237,10 @@ func main() {
|
||||
} else if cameraPitch < -10.0 {
|
||||
cameraPitch = -10.0
|
||||
}
|
||||
HandleInput(&player, mapGrid, &camera)
|
||||
UpdatePlayer(&player, deltaTime, mapGrid, &camera)
|
||||
|
||||
camera.Target = player.PosActual
|
||||
// Convert spherical coordinates to cartesian to calculate the camera's position
|
||||
camera.Position.X = player.PosActual.X + cameraDistance*float32(math.Cos(float64(cameraPitch)*math.Pi/180.0))*float32(math.Sin(float64(cameraYaw)*math.Pi/180.0))
|
||||
camera.Position.Y = player.PosActual.Y + cameraDistance*float32(math.Sin(float64(cameraPitch)*math.Pi/180.0))
|
||||
|
Loading…
x
Reference in New Issue
Block a user