Skip to content

Camera3D issue #85

@nyrix-git

Description

@nyrix-git

When the fps is higher than approximately 500, the camera starts bugging out with it glitching. If the fps is at a fixed rate like 60 fps, then the camera starts acting normal. Here's the code that I wrote, could be a issue in my code or the library itself. Note: my code is running at 60 tps if that could be the issue also, although it doesn't seem like it...

package com.Continuity.camera;

import static com.raylib.Raylib.*;

public class PlayerCamera {
// use CAMERA_ORBITAL later

private static Camera3D camera = new Camera3D();

private float cameraSensitivity = 0.005f;

private float cameraYaw = 0f;
private float cameraPitch = 0f;

public void init(Vector3 startPos) {

	camera._position(startPos);
	camera.target(new Vector3().x(0).y(0).z(0));
	camera.up(new Vector3().x(0).y(1).z(0));

	camera.fovy(60);
	camera.projection(CAMERA_PERSPECTIVE);
}

public void tick(Vector3 playerPos) {

	Vector2 mouse = GetMouseDelta();

	cameraYaw -= mouse.x() * cameraSensitivity;
	cameraPitch -= mouse.y() * cameraSensitivity;

	if (cameraPitch > 1.5f) {
		cameraPitch = 1.5f;			
	}
	if (cameraPitch < -1.5f) {
		cameraPitch = -1.5f;			
	}

	float cosPitch = (float) Math.cos(cameraPitch);
	float sinPitch = (float) Math.sin(cameraPitch);
	float sinYaw = (float) Math.sin(cameraYaw);
	float cosYaw = (float) Math.cos(cameraYaw);

	Vector3 direction = new Vector3().x(cosPitch * sinYaw).y(sinPitch).z(cosPitch * cosYaw);

	Vector3 eye = new Vector3().x(playerPos.x()).y(playerPos.y() + 1.6f).z(playerPos.z());

	camera._position(eye);

	camera.target(new Vector3().x(eye.x() + direction.x()).y(eye.y() + direction.y()).z(eye.z() + direction.z()));
}

public float getYaw() {
	return cameraYaw;
}

public static Camera3D getCamera() {
	return camera;
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions