Created Primitive struct

This commit is contained in:
Jack Christensen 2023-11-07 14:57:26 -05:00
parent ad58a13733
commit 378bffbbfc
6 changed files with 161 additions and 8 deletions

View File

@ -28,6 +28,7 @@
<ClCompile Include="imgui\imgui_widgets.cpp" />
<ClCompile Include="src\Application.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\Primitive.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="imgui\.editorconfig" />
@ -46,6 +47,7 @@
<ClInclude Include="imgui\imstb_textedit.h" />
<ClInclude Include="imgui\imstb_truetype.h" />
<ClInclude Include="include\Camera.h" />
<ClInclude Include="include\Primitive.h" />
</ItemGroup>
<ItemGroup>
<Text Include="imgui\LICENSE.txt" />

View File

@ -48,6 +48,9 @@
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="src\Primitive.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="shaders\parade_vs.glsl">
@ -94,6 +97,9 @@
<ClInclude Include="imgui\backends\imgui_impl_opengl3.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="include\Primitive.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="imgui\LICENSE.txt">

103
include/Primitive.h Normal file
View File

@ -0,0 +1,103 @@
#pragma once
#include <glm/glm.hpp>
using namespace glm;
struct Primitive
{
private:
vec3 m_ambientColor;
vec3 m_diffuseColor;
vec3 m_specularColor;
vec3 m_position;
public:
vec3& ambientColor() { return m_ambientColor; }
const vec3& ambientColor() const { return m_ambientColor; }
vec3& diffuseColor() { return m_diffuseColor; }
const vec3& diffuseColor() const { return m_diffuseColor; }
vec3& specularColor() { return m_specularColor; }
const vec3& specularColor() const { return m_specularColor; }
vec3& position() { return m_position; }
const vec3& position() const { return m_position; }
};
struct Sphere : Primitive
{
private:
float m_radius;
public:
float& radius() { return m_radius; }
const float& radius() const { return m_radius; }
};
struct Torus : Primitive
{
private:
float m_outerRadius;
float m_innerRadius;
public:
float& outerRadius() { return m_outerRadius; }
const float& outerRadius() const { return m_outerRadius; }
float& innerRadius() { return m_innerRadius; }
const float& innerRadius() const { return m_innerRadius; }
};
struct Cube : Primitive
{
private:
float m_size;
public:
float& radius() { return m_size; }
const float& radius() const { return m_size; }
};
struct RoundedCube : Primitive
{
private:
float m_size;
float m_radius;
public:
float& radius() { return m_size; }
const float& radius() const { return m_size; }
float& radius() { return m_radius; }
const float& radius() const { return m_radius; }
};
struct Cylinder : Primitive
{
private:
float m_height;
float m_radius;
public:
float& radius() { return m_height; }
const float& radius() const { return m_height; }
float& radius() { return m_radius; }
const float& radius() const { return m_radius; }
};
struct Cone : Primitive
{
private:
float m_height;
float m_radius;
public:
float& radius() { return m_height; }
const float& radius() const { return m_height; }
float& radius() { return m_radius; }
const float& radius() const { return m_radius; }
};

View File

@ -134,9 +134,6 @@ void main(void)
float distTorus = torusSDF(ray_pos.xyz, torus.R, torus.r);
float distSphere = sphereSDF(ray_pos.xyz, sphere.center, sphere.r);
float minDist = smoothMinSDF(distTorus, distSphere, k);
//float minDist = max(distTorus, distSphere);
//bool isTorus = distTorus < distSphere;
//float minDist = min(distTorus, distSphere);
if (minDist <= epsilon)
{
@ -149,11 +146,6 @@ void main(void)
normals = estimateSmoothNormals(ray_pos.xyz, k);
//if (isTorus)
// normals = estimateNormalsTorus(ray_pos.xyz);
//else
// normals = estimateNormalsSphere(ray_pos.xyz);
vec3 nw = normalize(normals);
vec3 lw = normalize(light_pos - ray_pos.xyz);
float dist = length(vec4(ray_pos.xyz - light_pos, 1.0));

View File

@ -16,6 +16,7 @@
#include <glm/gtc/type_ptr.hpp>
#include <Camera.h>
#include <Primitive.h>
float vertices[] = {
-0.5f, -0.5f, 0.0f,
@ -40,6 +41,7 @@ namespace window
namespace scene
{
std::vector<Primitive> prims;
Camera camera;
unsigned int shader = -1;
@ -91,6 +93,11 @@ static char* ReadShaderSource(const char* shaderFile)
return NULL;
}
void addPrim(std::vector<Primitive>* p, Primitive newPrim)
{
p->push_back(newPrim);
}
static unsigned int CompileShader(unsigned int type, const std::string& source)
{
unsigned int id = glCreateShader(type);

43
src/Primitive.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "Primitive.h"
struct Primitive {
glm::vec3 m_ambientColor;
glm::vec3 m_diffuseColor;
glm::vec3 m_specularColor;
glm::vec3 m_position;
};
struct Sphere : public Primitive
{
float m_radius;
};
struct Torus : public Primitive
{
float m_outerRadius;
float m_innerRadius;
};
struct Cube : public Primitive
{
float m_size;
};
struct RoundedCube : public Primitive
{
float m_size;
float m_radius;
};
struct Cylinder : public Primitive
{
float m_height;
float m_radius;
};
struct Cone : public Primitive
{
float m_height;
float m_radius;
};