Updated VS and added Vec2/Vec3/Vec3 classes from CC project. Also added RenderObject skeleton.
parent
710712f8c1
commit
66eb0364b3
|
@ -77,9 +77,11 @@ xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"</Command>
|
|||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderCamera.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderObject.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderScene.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderSet.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderView.cpp" />
|
||||
<ClCompile Include="..\..\src\Vec.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\Dev\glew-1.11.0\bin\Release\Win32\glew32.dll">
|
||||
|
@ -92,11 +94,13 @@ xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"</Command>
|
|||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\GL.hpp" />
|
||||
<ClInclude Include="..\..\src\common.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderCamera.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderObject.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderScene.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderSet.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderView.hpp" />
|
||||
<ClInclude Include="..\..\src\Vec.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -36,6 +36,12 @@
|
|||
<ClCompile Include="..\..\src\RenderSet.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\RenderObject.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Vec.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll">
|
||||
|
@ -52,14 +58,20 @@
|
|||
<ClInclude Include="..\..\src\RenderView.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\GL.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\RenderScene.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\RenderSet.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\common.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\RenderObject.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Vec.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -11,13 +11,14 @@ RenderScene and outputs all data to the friend class, RenderView.
|
|||
#define RENDERCAMERA_HPP
|
||||
#include "common.hpp"
|
||||
#include "RenderView.hpp"
|
||||
#include "Vec.hpp"
|
||||
class RenderCamera {
|
||||
public:
|
||||
RenderCamera();
|
||||
~RenderCamera();
|
||||
int setRenderView(RenderView *view);
|
||||
private:
|
||||
//Vec3 x, y, z; // TODO: replace with quaternion
|
||||
Vec3 x, y, z; // TODO: replace with quaternion
|
||||
int render_mode; // 0 = perspective, 1 = orthogonal
|
||||
RenderView *render_view; // RenderView to render the scene to
|
||||
};
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* ================================================================
|
||||
RenderSet
|
||||
----------------
|
||||
This header file defines the RenderObject class.
|
||||
================================================================ */
|
||||
#include "RenderObject.hpp"
|
||||
/* ======== Constructors and Destructors ======== */
|
||||
RenderObject::RenderObject() {
|
||||
}
|
||||
RenderObject::~RenderObject() {
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/* ================================================================
|
||||
RenderObject
|
||||
----------------
|
||||
This header file describes the RenderObject class.
|
||||
|
||||
A RenderObject is the basic class that contains information for
|
||||
rendering an object within a RenderScene. An object has, at minimum,
|
||||
a Mesh, a texture, a position, and an orientation.
|
||||
================================================================ */
|
||||
#ifndef RENDEROBJECT_HPP
|
||||
#define RENDEROBJECT_HPP
|
||||
#include "common.hpp"
|
||||
#include "Vec.hpp"
|
||||
class RenderObject {
|
||||
public:
|
||||
RenderObject();
|
||||
~RenderObject();
|
||||
private:
|
||||
// Mesh mesh;
|
||||
// GLuint texture;
|
||||
// TODO: replace position and orientation with matrix?
|
||||
Vec3 position;
|
||||
Vec3 orientation;
|
||||
};
|
||||
#endif
|
|
@ -11,13 +11,14 @@ each of which correspond to a different scene perspective.
|
|||
#define RENDERSCENE_HPP
|
||||
#include "common.hpp"
|
||||
#include "RenderCamera.hpp"
|
||||
#include "RenderSet.hpp"
|
||||
#include <vector>
|
||||
class RenderScene {
|
||||
public:
|
||||
RenderScene();
|
||||
~RenderScene();
|
||||
private:
|
||||
std::vector<RenderCamera> cameras; // Our scene's cameras
|
||||
//std::vector<RenderSet> render_sets; // Our scene's render sets
|
||||
std::vector<RenderCamera> cameras; // Our scene's cameras
|
||||
std::vector<RenderSet> render_sets; // Our scene's render sets
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -11,14 +11,15 @@ rendering layers of the program.
|
|||
#ifndef RENDERSET_HPP
|
||||
#define RENDERSET_HPP
|
||||
#include "common.hpp"
|
||||
#include "RenderObject.hpp"
|
||||
#include <vector>
|
||||
class RenderSet {
|
||||
public:
|
||||
RenderSet();
|
||||
~RenderSet();
|
||||
private:
|
||||
int mode; // bitflag, 0 = normal, 1 = hide
|
||||
//std::vector<RenderObject> objects; // Our vector of objects to render
|
||||
GLuint program; // Our rendering program
|
||||
int mode; // bitflag, 0 = normal, 1 = hide
|
||||
std::vector<RenderObject> objects; // Our vector of objects to render
|
||||
GLuint program; // Our rendering program
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,265 @@
|
|||
/* ================================================================
|
||||
Vec2/Vec3/Vec4
|
||||
----------------
|
||||
This file defines the classes for Vec2 and Vec3, 2D and 3D Vectors respectively.
|
||||
================================================================ */
|
||||
#include "Vec.hpp"
|
||||
#include <stdlib.h> // abs
|
||||
#include <math.h> // sqrt
|
||||
Vec2::Vec2() {
|
||||
x = y = 0.0f;
|
||||
}
|
||||
// constructor
|
||||
Vec2::Vec2(float x_, float y_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
// operators
|
||||
// add
|
||||
Vec2 Vec2::operator+(const Vec2 &Vec) {
|
||||
return Vec2(x + Vec.x, y + Vec.y);
|
||||
}
|
||||
void Vec2::operator+=(const Vec2 &Vec) {
|
||||
x += Vec.x;
|
||||
y += Vec.y;
|
||||
}
|
||||
// sub
|
||||
Vec2 Vec2::operator-(const Vec2 &Vec) {
|
||||
return Vec2(x - Vec.x, y - Vec.y);
|
||||
}
|
||||
void Vec2::operator-=(const Vec2 &Vec) {
|
||||
x -= Vec.x;
|
||||
y -= Vec.y;
|
||||
}
|
||||
// mul
|
||||
Vec2 Vec2::operator*(const Vec2 &Vec) {
|
||||
return Vec2(x * Vec.x, y * Vec.y);
|
||||
}
|
||||
void Vec2::operator*=(const float &val) {
|
||||
x *= val;
|
||||
y *= val;
|
||||
}
|
||||
// mul overload
|
||||
Vec2 Vec2::operator*(const float &val) {
|
||||
return Vec2(x * val, y * val);
|
||||
}
|
||||
// div
|
||||
Vec2 Vec2::operator/(const float &val) {
|
||||
return Vec2(x / val, y / val);
|
||||
}
|
||||
// div overload
|
||||
Vec2 Vec2::operator/(const Vec2 &Vec) {
|
||||
return Vec2(x / Vec.x, y / Vec.y);
|
||||
}
|
||||
// div assign
|
||||
void Vec2::operator/=(const float &val) {
|
||||
x /= val;
|
||||
y /= val;
|
||||
}
|
||||
// other stuff
|
||||
void Vec2::normalize() {
|
||||
float magnitude = sqrt((x * x) + (y * y));
|
||||
if (magnitude != 0) {
|
||||
x /= magnitude;
|
||||
y /= magnitude;
|
||||
}
|
||||
}
|
||||
void Vec2::zero() {
|
||||
x = y = 0;
|
||||
}
|
||||
float Vec2::dotProduct(const Vec2 &Vec) {
|
||||
return x * Vec.x + y * Vec.y;
|
||||
}
|
||||
float Vec2::distanceTo(const Vec2 &Vec) {
|
||||
float dx = abs(Vec.x - x);
|
||||
float dy = abs(Vec.y - y);
|
||||
return dx+dy;
|
||||
}
|
||||
/* Vec3
|
||||
```````````````````````````````````````````````````````````````` */
|
||||
Vec3::Vec3() {
|
||||
x = y = z = 0.0f;
|
||||
}
|
||||
// constructor
|
||||
Vec3::Vec3(float x_, float y_, float z_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
z = z_;
|
||||
}
|
||||
// operators
|
||||
// add
|
||||
Vec3 Vec3::operator+(const Vec3 &Vec) {
|
||||
return Vec3(x + Vec.x, y + Vec.y, z + Vec.z);
|
||||
}
|
||||
void Vec3::operator+=(const Vec3 &Vec) {
|
||||
x += Vec.x;
|
||||
y += Vec.y;
|
||||
z += Vec.z;
|
||||
}
|
||||
// sub
|
||||
Vec3 Vec3::operator-(const Vec3 &Vec) {
|
||||
return Vec3(x - Vec.x, y - Vec.y, z - Vec.z);
|
||||
}
|
||||
void Vec3::operator-=(const Vec3 &Vec) {
|
||||
x -= Vec.x;
|
||||
y -= Vec.y;
|
||||
z -= Vec.z;
|
||||
}
|
||||
// mul
|
||||
Vec3 Vec3::operator*(const Vec3 &Vec) {
|
||||
return Vec3(x * Vec.x, y * Vec.y, z * Vec.z);
|
||||
}
|
||||
void Vec3::operator*=(const float &val) {
|
||||
x *= val;
|
||||
y *= val;
|
||||
z *= val;
|
||||
}
|
||||
// mul overload
|
||||
Vec3 Vec3::operator*(const float &val) {
|
||||
return Vec3(x * val, y * val, z * val);
|
||||
}
|
||||
// div
|
||||
Vec3 Vec3::operator/(const float &val) {
|
||||
return Vec3(x / val, y / val, z / val);
|
||||
}
|
||||
// div overload
|
||||
Vec3 Vec3::operator/(const Vec3 &Vec) {
|
||||
return Vec3(x / Vec.x, y / Vec.y, z / Vec.z);
|
||||
}
|
||||
// div assign
|
||||
void Vec3::operator/=(const float &val) {
|
||||
x /= val;
|
||||
y /= val;
|
||||
z /= val;
|
||||
}
|
||||
// other stuff
|
||||
Vec3 Vec3::getInverse() {
|
||||
return Vec3(-x, -y, -z);
|
||||
}
|
||||
void Vec3::normalize() {
|
||||
float magnitude = sqrt((x * x) + (y * y) + (z * z));
|
||||
if (magnitude != 0) {
|
||||
x /= magnitude;
|
||||
y /= magnitude;
|
||||
z /= magnitude;
|
||||
}
|
||||
}
|
||||
void Vec3::zero() {
|
||||
x = y = z = 0;
|
||||
}
|
||||
float Vec3::dotProduct(const Vec3 &Vec) {
|
||||
return (x * Vec.x + y * Vec.y + z * Vec.z);
|
||||
}
|
||||
Vec3 Vec3::crossProduct(const Vec3 &Vec) {
|
||||
return Vec3(y * Vec.z - z * Vec.y, z * Vec.x - x * Vec.z, x * Vec.y - y * Vec.x);
|
||||
}
|
||||
float Vec3::distanceTo(const Vec3 &Vec) {
|
||||
float dx = abs(Vec.x - x);
|
||||
float dy = abs(Vec.y - y);
|
||||
float dz = abs(Vec.z - z);
|
||||
return dx+dy+dz;
|
||||
}
|
||||
float Vec3::lengthSquared() {
|
||||
return x*x + y*y + z*z;
|
||||
}
|
||||
|
||||
/* Vec4
|
||||
```````````````````````````````````````````````````````````````` */
|
||||
Vec4::Vec4() {
|
||||
values[0] = values[1] = values[2] = values[3] = 0.0f;
|
||||
}
|
||||
// constructor
|
||||
Vec4::Vec4(float x_, float y_, float z_, float w_) {
|
||||
values[0] = x_;
|
||||
values[1] = y_;
|
||||
values[2] = z_;
|
||||
values[3] = w_;
|
||||
}
|
||||
// operators
|
||||
// add
|
||||
Vec4 Vec4::operator+(const Vec4 &Vec) {
|
||||
return Vec4(values[0] + Vec[0], values[1] + Vec[1], values[2] + Vec[2], values[3] + Vec[3]);
|
||||
}
|
||||
void Vec4::operator+=(const Vec4 &Vec) {
|
||||
values[0] += Vec[0];
|
||||
values[1] += Vec[1];
|
||||
values[2] += Vec[2];
|
||||
values[3] += Vec[3];
|
||||
}
|
||||
// sub
|
||||
Vec4 Vec4::operator-(const Vec4 &Vec) {
|
||||
return Vec4(values[0] - Vec[0], values[1] - Vec[1], values[2] - Vec[2], values[3] - Vec[3]);
|
||||
}
|
||||
void Vec4::operator-=(const Vec4 &Vec) {
|
||||
values[0] -= Vec[0];
|
||||
values[1] -= Vec[1];
|
||||
values[2] -= Vec[2];
|
||||
values[3] -= Vec[3];
|
||||
}
|
||||
Vec4 Vec4::operator-(const float &val) {
|
||||
return Vec4(values[0] - val, values[1] - val, values[2] - val, values[3] - val);
|
||||
}
|
||||
// mul
|
||||
Vec4 Vec4::operator*(const Vec4 &Vec) {
|
||||
return Vec4(values[0] * Vec[0], values[1] * Vec[1], values[2] * Vec[2], values[3] * Vec[3]);
|
||||
}
|
||||
void Vec4::operator*=(const Vec4 &Vec) {
|
||||
values[0] *= Vec[0];
|
||||
values[1] *= Vec[1];
|
||||
values[2] *= Vec[2];
|
||||
values[3] *= Vec[3];
|
||||
}
|
||||
void Vec4::operator*=(const float &val) {
|
||||
values[0] *= val;
|
||||
values[1] *= val;
|
||||
values[2] *= val;
|
||||
values[3] *= val;
|
||||
}
|
||||
// mul overload
|
||||
Vec4 Vec4::operator*(const float &val) {
|
||||
return Vec4(values[0] * val, values[1] * val, values[2] * val, values[3] * val);
|
||||
}
|
||||
// div
|
||||
Vec4 Vec4::operator/(const float &val) {
|
||||
return Vec4(values[0] / val, values[1] / val, values[2] / val, values[3] / val);
|
||||
}
|
||||
// div overload
|
||||
Vec4 Vec4::operator/(const Vec4 &Vec) {
|
||||
return Vec4(values[0] / Vec[0], values[1] / Vec[1], values[2] / Vec[2], values[3] / Vec[3]);
|
||||
}
|
||||
// div assign
|
||||
void Vec4::operator/=(const float &val) {
|
||||
values[0] /= val;
|
||||
values[1] /= val;
|
||||
values[2] /= val;
|
||||
values[3] /= val;
|
||||
}
|
||||
const float& Vec4::operator[](int index) const {
|
||||
return values[index];
|
||||
}
|
||||
float& Vec4::operator[](int index) {
|
||||
return values[index];
|
||||
}
|
||||
|
||||
// other stuff
|
||||
void Vec4::normalize() {
|
||||
float magnitude = sqrt((values[0] * values[0]) + (values[1] * values[1]) + (values[2] * values[2]) + (values[3] * values[3]));
|
||||
if (magnitude != 0) {
|
||||
values[0] /= magnitude;
|
||||
values[1] /= magnitude;
|
||||
values[2] /= magnitude;
|
||||
values[3] /= magnitude;
|
||||
}
|
||||
}
|
||||
void Vec4::zero() {
|
||||
values[0] = values[1] = values[2] = values[3] = 0;
|
||||
}
|
||||
float Vec4::dotProduct(const Vec4 &Vec) {
|
||||
return values[0] * Vec[0] + values[1] * Vec[1] + values[2] * Vec[2] + values[3] * Vec[3];
|
||||
}
|
||||
float Vec4::distanceTo(const Vec4 &Vec) {
|
||||
float dx = abs(Vec[0] - values[0]);
|
||||
float dy = abs(Vec[1] - values[1]);
|
||||
float dz = abs(Vec[2] - values[2]);
|
||||
return dx+dy+dz;
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/* ================================================================
|
||||
Vec2/Vec3/Vec4
|
||||
----------------
|
||||
This header file describes the classes for 2d, 3d, and 4d Vectors.
|
||||
================================================================ */
|
||||
#ifndef VEC_HPP
|
||||
#define VEC_HPP
|
||||
|
||||
class Vec2 {
|
||||
public:
|
||||
float x, y;
|
||||
// default constructor
|
||||
Vec2();
|
||||
// constructor
|
||||
Vec2(float x_, float y_);
|
||||
// operators
|
||||
// add
|
||||
Vec2 operator+(const Vec2 &Vec);
|
||||
void operator+=(const Vec2 &Vec);
|
||||
Vec2 operator-(const Vec2 &Vec);
|
||||
void operator-=(const Vec2 &Vec);
|
||||
// mul
|
||||
Vec2 operator*(const Vec2 &Vec);
|
||||
void operator*=(const float &val);
|
||||
// mul overload
|
||||
Vec2 operator*(const float &val);
|
||||
// div
|
||||
Vec2 operator/(const float &val);
|
||||
// div overload
|
||||
Vec2 operator/(const Vec2 &Vec);
|
||||
// div assign
|
||||
void operator/=(const float &val);
|
||||
// other stuff
|
||||
void normalize();
|
||||
void zero();
|
||||
float dotProduct(const Vec2 &Vec);
|
||||
float distanceTo(const Vec2 &Vec);
|
||||
};
|
||||
class Vec3 {
|
||||
public:
|
||||
float x, y, z;
|
||||
// default constructor
|
||||
Vec3();
|
||||
// constructor
|
||||
Vec3(float x_, float y_, float z_);
|
||||
// operators
|
||||
// add
|
||||
Vec3 operator+(const Vec3 &Vec);
|
||||
void operator+=(const Vec3 &Vec);
|
||||
Vec3 operator-(const Vec3 &Vec);
|
||||
void operator-=(const Vec3 &Vec);
|
||||
// mul
|
||||
Vec3 operator*(const Vec3 &Vec);
|
||||
void operator*=(const float &val);
|
||||
// mul overload
|
||||
Vec3 operator*(const float &val);
|
||||
// div
|
||||
Vec3 operator/(const float &val);
|
||||
// div overload
|
||||
Vec3 operator/(const Vec3 &Vec);
|
||||
// div assign
|
||||
void operator/=(const float &val);
|
||||
// other stuff
|
||||
Vec3 getInverse();
|
||||
void normalize();
|
||||
void zero();
|
||||
float dotProduct(const Vec3 &Vec);
|
||||
Vec3 crossProduct(const Vec3 &Vec);
|
||||
float distanceTo(const Vec3 &Vec);
|
||||
float lengthSquared();
|
||||
};
|
||||
class Vec4 {
|
||||
public:
|
||||
float values[4];
|
||||
// default constructor
|
||||
Vec4();
|
||||
// constructor
|
||||
Vec4(float x_, float y_, float z_, float w_);
|
||||
// operators
|
||||
// add
|
||||
Vec4 operator+(const Vec4 &Vec);
|
||||
void operator+=(const Vec4 &Vec);
|
||||
Vec4 operator-(const Vec4 &Vec);
|
||||
Vec4 operator-(const float &val);
|
||||
void operator-=(const Vec4 &Vec);
|
||||
// mul
|
||||
Vec4 operator*(const Vec4 &Vec);
|
||||
void operator*=(const Vec4 &Vec);
|
||||
void operator*=(const float &val);
|
||||
// mul overload
|
||||
Vec4 operator*(const float &val);
|
||||
// div
|
||||
Vec4 operator/(const float &val);
|
||||
// div overload
|
||||
Vec4 operator/(const Vec4 &Vec);
|
||||
// div assign
|
||||
void operator/=(const float &val);
|
||||
const float& operator[](int index) const;
|
||||
float& operator[](int index);
|
||||
// other stuff
|
||||
void normalize();
|
||||
void zero();
|
||||
float dotProduct(const Vec4 &Vec);
|
||||
float distanceTo(const Vec4 &Vec);
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue