more camera stuff

This commit is contained in:
Yggdrasil75
2026-02-02 11:21:58 -05:00
parent 3f88fdd14e
commit d719d0a922
2 changed files with 92 additions and 29 deletions

View File

@@ -30,8 +30,8 @@ struct defaults {
bool globalIllumination = true; bool globalIllumination = true;
int rayCount = 3; int rayCount = 3;
int reflectCount = 3; int reflectCount = 3;
int lodDist; int lodDist = 500;
float lodDropoff; float lodDropoff = 0.1;
PNoise2 noise = PNoise2(42); PNoise2 noise = PNoise2(42);
}; };
@@ -39,15 +39,14 @@ struct spheredefaults {
float centerX = 0.0f; float centerX = 0.0f;
float centerY = 0.0f; float centerY = 0.0f;
float centerZ = 0.0f; float centerZ = 0.0f;
float radius = 128.0f; float radius = 1024.0f;
float color[3] = {0.0f, 1.0f, 0.0f}; float color[3] = {0.0f, 1.0f, 0.0f};
bool light = false; bool light = false;
float emittance = 0.0f; float emittance = 0.0f;
float reflection = 0.0f; float reflection = 0.0f;
float refraction = 0.0f; float refraction = 0.0f;
bool fillInside = false; bool fillInside = false;
float voxelSize = 2.f; float voxelSize = 10.f;
int numPoints = 15000;
}; };
struct stardefaults { struct stardefaults {
@@ -558,6 +557,9 @@ int main() {
bool autoRotate = false; bool autoRotate = false;
bool autoRotateView = false; bool autoRotateView = false;
bool orbitEquator = false;
bool orbitPoles = false;
float rotationSpeedX = 0.1f; float rotationSpeedX = 0.1f;
float rotationSpeedY = 0.07f; float rotationSpeedY = 0.07f;
float rotationSpeedZ = 0.05f; float rotationSpeedZ = 0.05f;
@@ -600,7 +602,7 @@ int main() {
deltaTime = currentTime - lastFrameTime; deltaTime = currentTime - lastFrameTime;
lastFrameTime = currentTime; lastFrameTime = currentTime;
if (autoRotate) autoRotationTime += deltaTime; if (orbitEquator || orbitPoles || autoRotate) autoRotationTime += deltaTime;
if (autoRotateView) autoRotationAngle += deltaTime; if (autoRotateView) autoRotationAngle += deltaTime;
glfwPollEvents(); glfwPollEvents();
@@ -646,6 +648,29 @@ int main() {
previewRequested = true; previewRequested = true;
} }
float cx = sphereConf.centerX;
float cy = sphereConf.centerY;
float cz = sphereConf.centerZ;
if (orbitEquator || orbitPoles) {
float speed = 0.5f;
float angle = autoRotationTime * speed;
if (orbitEquator) {
cam.origin[0] = cx + rotationRadius * cosf(angle);
cam.origin[1] = cy;
cam.origin[2] = cz + rotationRadius * sinf(angle);
} else {
cam.origin[0] = cx;
cam.origin[1] = cy + rotationRadius * cosf(angle);
cam.origin[2] = cz + rotationRadius * sinf(angle);
}
PointType target(cx, cy, cz);
cam.direction = (target - cam.origin).normalized();
previewRequested = true;
}
// Update camera position and view direction variables for UI // Update camera position and view direction variables for UI
camX = cam.origin[0]; camX = cam.origin[0];
camY = cam.origin[1]; camY = cam.origin[1];
@@ -671,7 +696,6 @@ int main() {
sphereConf.centerZ = pos[2]; sphereConf.centerZ = pos[2];
} }
ImGui::DragFloat("Radius", &sphereConf.radius, 0.5f, 1.0f, 250.0f); ImGui::DragFloat("Radius", &sphereConf.radius, 0.5f, 1.0f, 250.0f);
ImGui::DragInt("Point Count", &sphereConf.numPoints, 100, 100, 200000);
ImGui::DragFloat("Density (Overlap)", &sphereConf.voxelSize, 0.05f, 0.1f, 5.0f); ImGui::DragFloat("Density (Overlap)", &sphereConf.voxelSize, 0.05f, 0.1f, 5.0f);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Multiplies calculated point size. >1.0 ensures solid surface."); ImGui::SetTooltip("Multiplies calculated point size. >1.0 ensures solid surface.");
@@ -807,6 +831,43 @@ int main() {
cam.movementSpeed = camspeed; cam.movementSpeed = camspeed;
} }
ImGui::Separator();
// Focus Button
if (ImGui::Button("Focus on Planet")) {
PointType target(sphereConf.centerX, sphereConf.centerY, sphereConf.centerZ);
PointType newDir = (target - cam.origin).normalized();
cam.direction = newDir;
camvX = newDir[0];
camvY = newDir[1];
camvZ = newDir[2];
previewRequested = true;
}
ImGui::SameLine();
// Equator Orbit
if (ImGui::Button(orbitEquator ? "Stop Equator" : "Orbit Equator")) {
orbitEquator = !orbitEquator;
if (orbitEquator) {
orbitPoles = false;
autoRotate = false;
autoRotationTime = 0.0f;
}
}
ImGui::SameLine();
// Polar Orbit
if (ImGui::Button(orbitPoles ? "Stop Poles" : "Orbit Poles")) {
orbitPoles = !orbitPoles;
if (orbitPoles) {
orbitEquator = false;
autoRotate = false;
autoRotationTime = 0.0f;
}
}
ImGui::Separator(); ImGui::Separator();
ImGui::Text("Current Camera Position:"); ImGui::Text("Current Camera Position:");
ImGui::Text("X: %.2f, Y: %.2f, Z: %.2f", ImGui::Text("X: %.2f, Y: %.2f, Z: %.2f",
@@ -817,9 +878,11 @@ int main() {
ImGui::Text("Auto-Rotation:"); ImGui::Text("Auto-Rotation:");
// Toggle button for auto-rotation // Toggle button for auto-rotation
if (ImGui::Button(autoRotate ? "Stop Auto-Rotation" : "Start Auto-Rotation")) { if (ImGui::Button(autoRotate ? "Stop random Rotate" : "Start random Rotate")) {
autoRotate = !autoRotate; autoRotate = !autoRotate;
if (autoRotate) { if (autoRotate) {
orbitEquator = false;
orbitPoles = false;
autoRotationTime = 0.0f; autoRotationTime = 0.0f;
initialViewDir = PointType(camvX, camvY, camvZ); initialViewDir = PointType(camvX, camvY, camvZ);
} }
@@ -867,10 +930,10 @@ int main() {
ImGui::SliderFloat("X Speed", &rotationSpeedX, 0.01f, 1.0f); ImGui::SliderFloat("X Speed", &rotationSpeedX, 0.01f, 1.0f);
ImGui::SliderFloat("Y Speed", &rotationSpeedY, 0.01f, 1.0f); ImGui::SliderFloat("Y Speed", &rotationSpeedY, 0.01f, 1.0f);
ImGui::SliderFloat("Z Speed", &rotationSpeedZ, 0.01f, 1.0f); ImGui::SliderFloat("Z Speed", &rotationSpeedZ, 0.01f, 1.0f);
// Slider for orbit radius
ImGui::SliderFloat("Orbit Radius", &rotationRadius, 10.0f, 200.0f);
} }
// Slider for orbit radius
ImGui::SliderFloat("Orbit Radius", &rotationRadius, 10.0f, 2000.0f);
if (autoRotateView) { if (autoRotateView) {
ImGui::SameLine(); ImGui::SameLine();

View File

@@ -874,26 +874,26 @@ public:
[&](OctreeNode* node, const PointType& origin, const PointType& dir, float tMin, float tMax) { [&](OctreeNode* node, const PointType& origin, const PointType& dir, float tMin, float tMax) {
if (!node) return; if (!node) return;
// if (enableLOD && !node->isLeaf) { if (enableLOD && !node->isLeaf) {
// float dist = (node->center - origin).norm(); float dist = (node->center - origin).norm();
// if (dist > lodMinDistance_) { if (dist > lodMinDistance_) {
// float ratio = dist / (node->nodeSize + 0.0001f); float ratio = dist / (node->nodeSize + 0.0001f);
// if (ratio > (invLodf)) { if (ratio > (invLodf)) {
// ensureLOD(node); ensureLOD(node);
// if (node->lodData) { if (node->lodData) {
// float t; float t;
// PointType n; PointType n;
// PointType h; PointType h;
// if (rayCubeIntersect(origin, dir, node->lodData.get(), t, n, h)) { if (rayCubeIntersect(origin, dir, node->lodData.get(), t, n, h)) {
// if (t >= 0 && t <= maxDist) hits.emplace_back(node->lodData); if (t >= 0 && t <= maxDist) hits.emplace_back(node->lodData);
// } }
// return; return;
// } }
// } }
// } }
// } }
if (node->isLeaf) { if (node->isLeaf) {
for (const auto& pointData : node->points) { for (const auto& pointData : node->points) {