Initial procedural 3D engine setup
- Updated README.md with modern project structure and features - Cleaned up Android build files (not needed for desktop engine) - Restructured as procedural 3D engine with ImGui integration - Based on Sascha Willems Vulkan framework with dynamic rendering - Added comprehensive build instructions and camera system docs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ca9be0c589
commit
09ba229353
2429 changed files with 7751 additions and 112835 deletions
110
base/camera.hpp
110
base/camera.hpp
|
|
@ -22,29 +22,39 @@ private:
|
|||
{
|
||||
glm::mat4 currentMatrix = matrices.view;
|
||||
|
||||
glm::mat4 rotM = glm::mat4(1.0f);
|
||||
glm::mat4 transM;
|
||||
if (useOrbitMode && type == CameraType::lookat) {
|
||||
// Orbit mode: position camera relative to orbit center using spherical coordinates
|
||||
updateOrbitPosition();
|
||||
|
||||
// Use lookAt matrix for orbit mode
|
||||
matrices.view = glm::lookAt(position, orbitCenter, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
} else {
|
||||
// Standard Sascha camera behavior
|
||||
glm::mat4 rotM = glm::mat4(1.0f);
|
||||
glm::mat4 transM;
|
||||
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
glm::vec3 translation = position;
|
||||
if (flipY) {
|
||||
translation.y *= -1.0f;
|
||||
glm::vec3 translation = position;
|
||||
if (flipY) {
|
||||
translation.y *= -1.0f;
|
||||
}
|
||||
transM = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
if (type == CameraType::firstperson)
|
||||
{
|
||||
matrices.view = rotM * transM;
|
||||
}
|
||||
else
|
||||
{
|
||||
matrices.view = transM * rotM;
|
||||
}
|
||||
|
||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
}
|
||||
transM = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
if (type == CameraType::firstperson)
|
||||
{
|
||||
matrices.view = rotM * transM;
|
||||
}
|
||||
else
|
||||
{
|
||||
matrices.view = transM * rotM;
|
||||
}
|
||||
|
||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
|
||||
if (matrices.view != currentMatrix) {
|
||||
updated = true;
|
||||
|
|
@ -58,6 +68,11 @@ public:
|
|||
glm::vec3 position = glm::vec3();
|
||||
glm::vec4 viewPos = glm::vec4();
|
||||
|
||||
// Orbit camera support
|
||||
glm::vec3 orbitCenter = glm::vec3(0.0f);
|
||||
float orbitDistance = 8.0f;
|
||||
bool useOrbitMode = false;
|
||||
|
||||
float rotationSpeed = 1.0f;
|
||||
float movementSpeed = 1.0f;
|
||||
|
||||
|
|
@ -158,6 +173,61 @@ public:
|
|||
this->movementSpeed = movementSpeed;
|
||||
}
|
||||
|
||||
// Update camera position based on orbit center and current rotation
|
||||
void updateOrbitPosition()
|
||||
{
|
||||
if (!useOrbitMode) return;
|
||||
|
||||
// Convert Euler angles to spherical coordinates around orbit center
|
||||
float pitch = glm::radians(rotation.x);
|
||||
float yaw = glm::radians(rotation.y);
|
||||
|
||||
// Calculate position relative to orbit center using spherical coordinates
|
||||
float x = orbitDistance * cos(pitch) * cos(yaw);
|
||||
float y = orbitDistance * sin(pitch);
|
||||
float z = orbitDistance * cos(pitch) * sin(yaw);
|
||||
|
||||
position = orbitCenter + glm::vec3(x, y, z);
|
||||
}
|
||||
|
||||
// Enable orbit mode and set orbit center
|
||||
void setOrbitMode(glm::vec3 center, float distance)
|
||||
{
|
||||
orbitCenter = center;
|
||||
orbitDistance = distance;
|
||||
useOrbitMode = true;
|
||||
updateViewMatrix();
|
||||
}
|
||||
|
||||
// Disable orbit mode and return to standard camera
|
||||
void disableOrbitMode()
|
||||
{
|
||||
useOrbitMode = false;
|
||||
updateViewMatrix();
|
||||
}
|
||||
|
||||
// Focus camera on an object using orbit mode
|
||||
void focusOnObject(glm::vec3 objectCenter, float objectRadius)
|
||||
{
|
||||
// Calculate optimal viewing distance based on object radius and FOV
|
||||
float halfFovRadians = glm::radians(fov * 0.5f);
|
||||
float distance = objectRadius / glm::tan(halfFovRadians) * 2.5f;
|
||||
distance = glm::max(distance, objectRadius * 3.0f);
|
||||
|
||||
// Set orbit center to the object center
|
||||
orbitCenter = objectCenter;
|
||||
orbitDistance = distance;
|
||||
useOrbitMode = true;
|
||||
|
||||
// Set camera to a good viewing angle (slightly elevated and angled)
|
||||
rotation.x = 15.0f; // Slight elevation
|
||||
rotation.y = 30.0f; // Angled view
|
||||
rotation.z = 0.0f;
|
||||
|
||||
// Update position and view matrix
|
||||
updateViewMatrix();
|
||||
}
|
||||
|
||||
void update(float deltaTime)
|
||||
{
|
||||
updated = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue