Skip to content

Commit

Permalink
remove explicit ref copy constructor in vec and quat
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarpilote committed Dec 6, 2021
1 parent 2d1a228 commit 2dc6351
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(Myosotis VERSION 0.1)

set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
set( CMAKE_VERBOSE_MAKEFILE OFF )
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE )

configure_file(
${PROJECT_SOURCE_DIR}/config/version.h.in
Expand Down
2 changes: 1 addition & 1 deletion extern/miniply/miniply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ namespace miniply {
uint32_t propIdx = listPropIdx + 1 + i;

PLYProperty& itemProp = properties[propIdx];
snprintf(nameBuf, sizeof(nameBuf), "%s_%u", oldListProp.name.c_str(), i);
snprintf(nameBuf, nameBufSize, "%s_%u", oldListProp.name.c_str(), i);
itemProp.name = nameBuf;
itemProp.type = oldListProp.type;
itemProp.countType = PLYPropertyType::None;
Expand Down
7 changes: 0 additions & 7 deletions include/hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ static inline size_t hash_lookup(K *keys, size_t buckets, H hasher, K key)
return 0;
}

static size_t hashtable_buckets(size_t n)
{
size_t ret = 1;
while (ret < n) ret *= 2;
return ret;
}

template<typename K, typename V, typename H>
HashTable<K, V, H>::HashTable(size_t expected_keys, H hasher)
{
Expand Down
16 changes: 1 addition & 15 deletions include/myosotis.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct MyosotisCfg
bool smooth_shading = true;
bool vsync = true;
float camera_fov = 45.0f;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ImVec4 clear_color = ImVec4(0.25f, 0.22f, 0.15f, 1.00f);
};

struct Myosotis {
Expand All @@ -30,17 +30,3 @@ struct Myosotis {
};


static void
resize_window_callback(GLFWwindow* window, int width, int height);

static void
mouse_button_callback(GLFWwindow* window, int button, int action, int mods);

static void
cursor_position_callback(GLFWwindow* window, double xpos, double ypos);

static void
scroll_callback(GLFWwindow* window, double xoffset, double yoffset);

static void
key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
2 changes: 1 addition & 1 deletion include/ndc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ constexpr bool reversed_y = NDC_REVERSED_Y ? true : false;
constexpr bool reversed_z = NDC_REVERSED_Z ? true : false;
constexpr bool z_zero_one = NDC_Z_ZERO_ONE ? true : false;

constexpr Vec3 nwd_to_ndc(float x, float y, float depth)
inline Vec3 nwd_to_ndc(float x, float y, float depth)
{
Vec3 ndc {0, 0, 0};

Expand Down
17 changes: 8 additions & 9 deletions include/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct alignas(4 * sizeof(T)) TQuat {

/* Constructors */
TQuat() = default;
constexpr TQuat(const TQuat& q);
constexpr TQuat(T x, T y, T z, T w);
constexpr TQuat(TVec3<T> xyz, T w);

Expand Down Expand Up @@ -71,9 +70,6 @@ TQuat<T> slerp(TQuat<T>& q0, TQuat<T>q1, T t);

/* Methods implementation */

template <typename T>
inline constexpr TQuat<T>::TQuat(const TQuat<T>& q): xyz{q.xyz}, w{q.w} {}

template <typename T>
inline constexpr TQuat<T>::TQuat(T x, T y, T z, T w): x{x}, y{y}, z{z}, w{w} {}

Expand Down Expand Up @@ -157,11 +153,14 @@ inline T norm(const TQuat<T>& a)
template <typename T>
TQuat<T> pow(TQuat<T>& q, T t)
{
double omega = acos((double)q.w);
T w = cos(t * omega);
T mult = sin(omega) ? sin(t * omega) / sin(omega) : t;

return {mult * q.xyz, w};
T qw = q.w < -1 ? -1 : q.w > 1 ? 1 : q.w;
T omega = acos(qw);
T cto = cos(t * omega);
T sto = sin(t * omega);
T so = sin(omega);
T mult = (so != 0) ? sto / so : t;

return {mult * q.xyz, cto};
}

template <typename T>
Expand Down
6 changes: 1 addition & 5 deletions include/vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ struct TVec2 {

/* Constructors */
constexpr TVec2() = default;
constexpr TVec2(const TVec2& a);
constexpr TVec2(T x, T y);
explicit TVec2(const T* t);
explicit TVec2(const T* t);

/* Index Accessor */
T& operator[] (int n);
Expand Down Expand Up @@ -66,9 +65,6 @@ TVec2<T> normalized(const TVec2<T>& a);

/* Functions implementations */

template <typename T>
inline constexpr TVec2<T>::TVec2(const TVec2<T>& a): x{a.x}, y{a.y} {}

template <typename T>
inline constexpr TVec2<T>::TVec2(T x, T y): x{x}, y{y} {}

Expand Down
4 changes: 0 additions & 4 deletions include/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct TVec3 {

/* Constructors */
constexpr TVec3() = default;
constexpr TVec3(const TVec3& a);
constexpr TVec3(T x, T y, T z);
explicit TVec3(const T* t);

Expand Down Expand Up @@ -68,9 +67,6 @@ TVec3<T> normalized(const TVec3<T>& a);

/* Functions implementations */

template <typename T>
inline constexpr TVec3<T>::TVec3(const TVec3<T>& a): x{a.x}, y{a.y}, z{a.z} {}

template <typename T>
inline constexpr TVec3<T>::TVec3(T x, T y, T z): x{x}, y{y}, z{z} {}

Expand Down
5 changes: 0 additions & 5 deletions include/vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct alignas(4 * sizeof(T)) TVec4 {

/* Constructors */
constexpr TVec4() = default;
constexpr TVec4(const TVec4& a);
constexpr TVec4(T x, T y, T z, T w);
constexpr TVec4(const TVec3<T>& xyz, T w);
explicit TVec4(const T* t);
Expand Down Expand Up @@ -73,10 +72,6 @@ const TVec4<T> TVec4<T>::Zero {0, 0, 0};

/* Functions implementations */

template <typename T>
inline constexpr TVec4<T>::TVec4(const TVec4<T>& a):
x{a.x}, y{a.y}, z{a.z}, w{a.w} {}

template <typename T>
inline constexpr TVec4<T>::TVec4(T x, T y, T z, T w): x{x}, y{y}, z{z}, w{w} {}

Expand Down
4 changes: 2 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
echo "Building DEBUG version."
echo "-----------------------"
make --no-print-directory -C build/debug
make --no-print-directory -C build/debug -j 4

echo
echo "Building RELEASE version."
echo "-----------------------"
make --no-print-directory -C build/release
make --no-print-directory -C build/release -j 4

mkdir -p bin
echo
Expand Down
16 changes: 8 additions & 8 deletions shaders/default.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ layout (location = 3) uniform bool smooth_shading;
layout (location = 0) out vec4 color;

#define AMBIENT_COLOR vec3(1.f, 0.8f, 1.f)
#define Ka 0.2f
#define DIFFUSE_COLOR vec3(1.f, 1.f, 1.f)
#define Kd 0.6f
#define SPECULAR_COLOR vec3(.8f, .8f, 1.f)
#define Ka 0.1f
#define DIFFUSE_COLOR vec3(.88f, .75f, 0.43f)
#define Kd .7f
#define SPECULAR_COLOR vec3(1.f, 1.f, 1.f)
#define Ks 0.2f
#define shininess 80
#define shininess 8


void main() {
Expand Down Expand Up @@ -49,10 +49,10 @@ void main() {
//vec3 R = 2.f * dot(N, L) * N - L;
vec3 R = reflect(-L, N);
float ca = max(dot(R, V), 0.f);
Is = pow(ca, shininess);
Is = pow(ca, shininess) * shininess / 4;
}
vec3 full = Ka * AMBIENT_COLOR;
full += Kd * Id * DIFFUSE_COLOR;
full += Ks * Is * SPECULAR_COLOR;
full += Kd * Id * DIFFUSE_COLOR;
full += Ks * Is * SPECULAR_COLOR;
color = vec4(full, 1.0f);
}
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_executable(main
../extern/imgui/imgui_impl_opengl3.cpp
)

target_compile_features(main PUBLIC cxx_std_20)
target_compile_features(main PRIVATE cxx_std_17)
target_compile_options(main PRIVATE -Wall -Wextra)
target_link_libraries(main OpenGL glfw ${CMAKE_DL_LIBS})

2 changes: 0 additions & 2 deletions src/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ void timer_stop(const char *str = "")
gettimeofday(&tv1, NULL);
unsigned int mus = 1000000 * (tv1.tv_sec - tv0.tv_sec);
mus += (tv1.tv_usec - tv0.tv_usec);
int s = mus >= 1000000;
int ms = mus >= 1000;
printf("Timer %s: ", str);
if (mus >= 1000000)
{
Expand Down
7 changes: 3 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ int main(int argc, char **argv)
{
timer_start();
int level = atoi(argv[2]);
Vec3 extent = bbox.max - bbox.min;
float cube_size = model_size;
Grid grid = {bbox.min, cube_size / (1 << level)};
MeshData data2;
Expand All @@ -105,7 +104,7 @@ int main(int argc, char **argv)
/* Main window and context */
Myosotis app;

if (!app.init(200, 100))
if (!app.init(1920, 1080))
{
return (EXIT_FAILURE);
}
Expand All @@ -121,8 +120,8 @@ int main(int argc, char **argv)
GLuint idx, pos, nml, tex, vao;

glEnable(GL_DEBUG_OUTPUT);
glDisable(GL_CULL_FACE);
//glEnable(GL_CULL_FACE);
//glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);
Expand Down
3 changes: 2 additions & 1 deletion src/mesh_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int obj_to_mesh(const fastObjMesh& obj, MeshData& data, Mesh& mesh)

data.reserve_indices(index_count);

bool has_normals, has_uv;
bool has_normals = false;
bool has_uv = false;
for (size_t i = 0; i < obj_vertex_count; ++i)
{
has_normals |= (obj.indices[i].n != 0);
Expand Down
26 changes: 24 additions & 2 deletions src/myosotis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@
#include "myosotis.h"
#include "viewer.h"

static void
resize_window_callback(GLFWwindow* window, int width, int height);

static void
mouse_button_callback(GLFWwindow* window, int button, int action, int mods);

static void
cursor_position_callback(GLFWwindow* window, double xpos, double ypos);

static void
scroll_callback(GLFWwindow* window, double xoffset, double yoffset);

static void
key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);

static void
GL_debug_callback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message,
const void* user_param)
{
(void) source;
(void) length;
(void) user_param;
(void) id;
if (type == GL_DEBUG_TYPE_ERROR)
{
printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x,\
Expand Down Expand Up @@ -45,8 +63,10 @@ bool Myosotis::init(int width, int height)
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);

window = glfwCreateWindow(mode->width, mode->height, "Myosotis",
glfwGetPrimaryMonitor(), NULL);
//window = glfwCreateWindow(mode->width, mode->height, "Myosotis",
//glfwGetPrimaryMonitor(), NULL);
window = glfwCreateWindow(width, height, "Myosotis", NULL, NULL);

if (!window)
{
return (false);
Expand Down Expand Up @@ -190,6 +210,8 @@ scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
static void
key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
(void) scancode;
(void) mods;
Myosotis* app = (Myosotis*)glfwGetWindowUserPointer(window);

if (app->io->WantCaptureKeyboard)
Expand Down
4 changes: 3 additions & 1 deletion src/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ void Viewer3D::mouse_move(float px, float py)

void Viewer3D::mouse_scroll(float xoffset, float yoffset)
{

(void)xoffset;
Vec3 old_pos = camera.get_position();
Vec3 new_pos = target + exp(-ZOOM_SENSITIVITY * yoffset) * (old_pos - target);
camera.set_position(new_pos);
}

void Viewer3D::key_pressed(int key, int action)
{
(void)key;
(void)action;
}

0 comments on commit 2dc6351

Please sign in to comment.