Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andgate committed Dec 16, 2018
1 parent e4ca064 commit 363004d
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 79 deletions.
7 changes: 4 additions & 3 deletions Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

#include "Vector3f.h"
#include "Constants.h"

Camera::Camera(float viewportWidth, float viewportHeight)
: position(0.0f, 0.0f, -3.0f)
: position(CAM_INITIAL_POS)
, direction(0.0f, 0.0f, 1.0f)
, up(0.0f, 1.0f, 0.0f)
, viewportWidth(viewportWidth)
Expand Down Expand Up @@ -119,7 +120,7 @@ float Camera::estimateMandelbulbDistance() const

float Camera::scale(const float &unit) const
{
float idist = sdfMandelbulb(CAM_INITIAL_POS, POWER);
float mdist = estimateMandelbulbDistance();
if (abs(mdist) >= unit) return unit;
else return abs(mdist / unit);
return min(idist, abs(mdist / idist));
}
1 change: 0 additions & 1 deletion CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void CameraController::mouseScrolled(const float scrollDelta, const int mouseX,
{
speed += scrollDelta*0.2f;
speed = max(0.1f, speed);
cout << speed << endl;
}

// Unused functions
Expand Down
23 changes: 16 additions & 7 deletions Constants.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H

#include "Vector3f.h"

const bool IS_FULLSCREEN = false;
const int DEFAULT_FPS = 60;
const int INFO_FONT_SIZE_PX = 24;

const Vector3f CAM_INITIAL_POS = Vector3f(0.0f, 0.0f, -3.0f);
const float CAM_UNIT_SPEED = 1.0f;
const float CAM_DEGREES_PER_PIXEL = 0.2f;
const float CAM_SPEED_UP = 5.0f;
Expand All @@ -12,16 +16,21 @@ const float FOV = 67.0f;
const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 768;

const float EPSILON_FACTOR = 0.001f;
const float EPSILON_LIMIT = 1e-6f;
const float MAX_BAILOUT = 2.0f;
const int MAX_ITER = 100;
const int MIN_ITER = 4;
const int MAX_STEPS = 100;
const float MAX_DIST = 400.0f;
const float EPSILON_FACTOR = 0.0001;
const float EPSILON_LIMIT = 4e-6f;
const float MAX_BAILOUT = 2.0f; // Also called "DIVERGENCE"
const int MAX_ITER = 10;
const int MIN_ITER = 10;
const int MAX_STEPS = 20;
const float MAX_DIST = 350.0f;
const int POWER = 8;

const bool FOG_ENABLED = true;
const float FOG_MAX_DIST = 300.0f;

const float GLOW_DIST = 0.5f;
const bool GLOW_ENABLED = true;

const bool HEAT_ENABLED = false;

#endif /* CONSTANTS_H */
9 changes: 9 additions & 0 deletions MandelbulbViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void MandelbulbViewer::update(const float dt)
shader->setUniform("fog_enabled", viewer->fogToggle);
shader->setUniform("fog_max_dist", FOG_MAX_DIST);

shader->setUniform("glow_dist", GLOW_DIST);
shader->setUniform("glow_enabled", viewer->glowToggle);

shader->setUniform("heat_enabled", viewer->heatToggle);

sf::Shader::bind(NULL);

if (viewer->infoToggle) updateInfo();
Expand Down Expand Up @@ -182,6 +187,8 @@ void MandelbulbViewer::updateInfo()
MandelbulbViewer::ViewerInputListener::ViewerInputListener()
: infoToggle(false)
, fogToggle(FOG_ENABLED)
, glowToggle(GLOW_ENABLED)
, heatToggle(HEAT_ENABLED)
{}

void MandelbulbViewer::ViewerInputListener::update(const float dt) {}
Expand All @@ -190,6 +197,8 @@ void MandelbulbViewer::ViewerInputListener::keyPressed(const sf::Keyboard::Key &
{
if (key == sf::Keyboard::Tab) infoToggle = !infoToggle;
if (key == sf::Keyboard::Num1) fogToggle = !fogToggle;
if (key == sf::Keyboard::Num2) glowToggle = !glowToggle;
if (key == sf::Keyboard::Num3) heatToggle = !heatToggle;
}

void MandelbulbViewer::ViewerInputListener::keyHeld(const sf::Keyboard::Key &key, const float dt) {}
Expand Down
2 changes: 2 additions & 0 deletions MandelbulbViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MandelbulbViewer
public:
bool infoToggle;
bool fogToggle;
bool glowToggle;
bool heatToggle;

ViewerInputListener();

Expand Down
25 changes: 13 additions & 12 deletions fig2-10.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -23,31 +23,32 @@
<SccLocalPath />
<ProjectGuid>{4824792B-FE40-57BD-EBD6-B3A2B1E6AE38}</ProjectGuid>
<ProjectName>mandelbulb</ProjectName>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -143,7 +144,7 @@
<ObjectFileName>$(SolutionDir)$(Platform)\$(Configuration)\</ObjectFileName>
<ProgramDataBaseFileName>$(SolutionDir)$(Platform)\$(Configuration)\</ProgramDataBaseFileName>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<AdditionalIncludeDirectories>$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)\SFML-2.5.0\include</AdditionalIncludeDirectories>
</ClCompile>
<Midl>
<TypeLibraryName>.\Debug\fig2-10.tlb</TypeLibraryName>
Expand Down Expand Up @@ -232,7 +233,7 @@ copy "$(SolutionDir)\SFML-2.5.1-windows-vc12-32-bit\bin\sfml-window-2.dll" "$(Ta
<PrecompiledHeaderOutputFile>$(SolutionDir)$(Platform)\$(Configuration)\mandelbulb.pch</PrecompiledHeaderOutputFile>
<ObjectFileName>$(SolutionDir)$(Platform)\$(Configuration)\</ObjectFileName>
<ProgramDataBaseFileName>$(SolutionDir)$(Platform)\$(Configuration)\</ProgramDataBaseFileName>
<AdditionalIncludeDirectories>$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)\SFML-2.5.0\include;</AdditionalIncludeDirectories>
</ClCompile>
<Midl>
<TypeLibraryName>.\Release\fig2-10.tlb</TypeLibraryName>
Expand All @@ -249,13 +250,13 @@ copy "$(SolutionDir)\SFML-2.5.1-windows-vc12-32-bit\bin\sfml-window-2.dll" "$(Ta
<SuppressStartupBanner>true</SuppressStartupBanner>
<SubSystem>Console</SubSystem>
<OutputFile>$(SolutionDir)$(Platform)\$(Configuration)\mandelbulb.exe</OutputFile>
<AdditionalDependencies>freetype.lib;sfml-graphics.lib;sfml-window.lib;sfml-system.lib;sfml-main.lib;freetype.lib;opengl32.lib;winmm.lib;gdi32.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\lib;</AdditionalLibraryDirectories>
<AdditionalDependencies>freetype.lib;sfml-graphics.lib;sfml-window.lib;sfml-system.lib;sfml-main.lib;opengl32.lib;winmm.lib;gdi32.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\SFML-2.5.0\lib;</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>copy "$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\bin\sfml-system-2.dll" "$(OutDir)"
copy "$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\bin\sfml-window-2.dll" "$(OutDir)"
copy "$(SolutionDir)\SFML-2.4.2-windows-vc11-64-bit\bin\sfml-graphics-2.dll" "$(OutDir)"
<Command>copy "$(SolutionDir)\SFML-2.5.0\bin\sfml-system-2.dll" "$(OutDir)"
copy "$(SolutionDir)\SFML-2.5.0\bin\sfml-window-2.dll" "$(OutDir)"
copy "$(SolutionDir)\SFML-2.5.0\bin\sfml-graphics-2.dll" "$(OutDir)"
copy "$(SolutionDir)\mandelbulb.vert" "$(OutDir)"
copy "$(SolutionDir)\mandelbulb.frag" "$(OutDir)"
copy "$(SolutionDir)\arial.ttf" "$(OutDir)"</Command>
Expand Down
3 changes: 1 addition & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ using namespace std;
#include "MandelbulbViewer.h"
#include "Constants.h"

int main (int argc, char** argv)
{
int main (int argc, char** argv){
MandelbulbViewer viewer(SCREEN_WIDTH, SCREEN_HEIGHT, DEFAULT_FPS);
return viewer.run();
}
Loading

0 comments on commit 363004d

Please sign in to comment.