idk what i was doing
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -47,7 +47,7 @@ if (WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
|
||||
|
||||
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")
|
||||
file(GLOB_RECURSE ASSETS "assets/*")
|
||||
|
@@ -633,21 +633,12 @@ namespace JGL::J3D {
|
||||
/// @param box_count The number of AABBs to draw.
|
||||
void BatchFillAABB(const Color4& color, const AABB* boxes, const size_t& box_count);
|
||||
|
||||
/// Draws an outline of an oriented bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param position The point in 3D space that is the center of the AABB.
|
||||
/// @param radii The radii along x,y,z axes to size the bounding box.
|
||||
/// @param orientation The rotation in 3D space of the OBB.
|
||||
/// @param thickness The line-width to draw the OBB outline with.
|
||||
void WireframeOBB(const Color4& color, const Vector3& position, const Vector3& radii, const Matrix3x3& orientation, float thickness = 1.f);
|
||||
|
||||
/// Draws an outline of an oriented bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param obb The OBB object to visualize.
|
||||
/// @param thickness The line-width to draw the OBB outline with.
|
||||
void WireframeOBB(const Color4& color, const OBB& obb, float thickness = 1.f);
|
||||
void WireframeOBB(const Color4& color, const Vector3& center, const Vector3& radii, const Matrix3x3& rotation_matrix, float thickness = 1.f);
|
||||
|
||||
void BatchWireframeOBB(const Color4& color, const OBB* boxes, const size_t& box_count, float thickness = 1.f);
|
||||
|
||||
/// Draws a solid oriented bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
|
58
include/JGL/types/Light2D.h
Normal file
58
include/JGL/types/Light2D.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include <J3ML/LinearAlgebra/Vector4.hpp>
|
||||
#include <Colors.hpp>
|
||||
namespace JGL::J2D {
|
||||
class Light;
|
||||
class PointLight;
|
||||
}
|
||||
|
||||
// TODO Static member function to transform to RenderTarget space.
|
||||
// For ex, If the render target would be positioned at 10, 10 and the light is at 0, 0. Then fix it such that for the Render Target the light is at -10, -10.
|
||||
/// Only works if we know where the Render Target will be on screen beforehand. But that's the only scenario you'd need to be able to do this anyways - Redacted.
|
||||
class JGL::J2D::Light {
|
||||
protected:
|
||||
Vector4 light_pos = Vector4::Zero;
|
||||
Color4 ambient = Colors::White;
|
||||
Color4 diffuse = Colors::White;
|
||||
float constant_attenuation = 1;
|
||||
float linear_attenuation = 0;
|
||||
float quadratic_attenuation = 0;
|
||||
public:
|
||||
/// @returns The position of this light in screen-world 2D space.
|
||||
[[nodiscard]] Vector2 Position() const;
|
||||
/// @returns The ambient light color.
|
||||
[[nodiscard]] Color4 Ambient() const;
|
||||
/// @returns The diffuse light color.
|
||||
[[nodiscard]] Color4 Diffuse() const;
|
||||
/// @returns The constant attenuation value
|
||||
[[nodiscard]] float Constant() const;
|
||||
/// @returns The linear attenuation value.
|
||||
[[nodiscard]] float Linear() const;
|
||||
/// @returns The quadratic attenuation value.
|
||||
[[nodiscard]] float Quadratic() const;
|
||||
public:
|
||||
/// Set the position of this light in screen-world 2D space.
|
||||
void Position(const Vector2& new_position);
|
||||
/// Set the ambient light color.
|
||||
void Ambient(const Color4& new_ambient);
|
||||
/// Set the diffuse light color.
|
||||
void Diffuse(const Color4& new_diffuse);
|
||||
/// Set the constant attenuation value (0 - 1).
|
||||
void Constant(float new_constant_attenuation);
|
||||
/// Set the linear attenuation value (0 -1).
|
||||
void Linear(float new_linear_attenuation);
|
||||
/// Set the quadratic attenuation value (0 - 1).
|
||||
void Quadratic(float new_quadratic_attenuation);
|
||||
public:
|
||||
/// @returns float (0 - 1) representing how much this light impacts a given position in 2D space.
|
||||
[[nodiscard]] virtual float MeasureIntensityAtPosition(const Vector2& position) const = 0;
|
||||
};
|
||||
|
||||
class JGL::J2D::PointLight : public Light {
|
||||
public:
|
||||
[[nodiscard]] float MeasureIntensityAtPosition(const Vector2& position) const override;
|
||||
public:
|
||||
PointLight(const Vector2& position, const Color4& ambient, const Color4& diffuse,
|
||||
float constant_attenuation = 1, float linear_attenuation = 0, float quadratic_attenuation = 0);
|
||||
};
|
||||
|
10
main.cpp
10
main.cpp
@@ -169,7 +169,7 @@ public:
|
||||
camera->render();
|
||||
// All 3D elements of the scene and JGL elements *must* be rendered before the 2D stuff
|
||||
/* if rendering to screen space directly. */
|
||||
auto test_light = PointLight({2,1,2}, {pulse,pulse,pulse, 255}, {pulse, pulse, pulse, 255}, {0,0,0}, 1, 0.1, 0.01);
|
||||
auto test_light = PointLight({2,1,2}, {0, 0, 0, 255}, {pulse, pulse, pulse, 255}, {0,0,0}, 0, 0.1, 0.01);
|
||||
// If a 3D object has transparency. The things you'd like to see through it must be drawn before.
|
||||
|
||||
J3D::Begin();
|
||||
@@ -179,9 +179,12 @@ public:
|
||||
//J3D::WireframeSphere(Colors::Green, {0,0,0.5f}, 0.25f, 1, 128, 128);
|
||||
Sphere sphere = {{1,0, 0.5f}, 0.2125};
|
||||
J3D::BatchWireframeRevoSphere(Colors::Green, &sphere, 1, 1, 8, 8, true);
|
||||
J3D::RequiredLight(&test_light);
|
||||
J3D::FillAABB(Colors::Whites::AliceBlue, {0,0,0.5f}, {0.05f, 0.05f, 0.05f});
|
||||
J3D::RequiredLight(&test_light);glEnable(GL_NORMALIZE);
|
||||
|
||||
J3D::FillAABB(Colors::Whites::AliceBlue, {0,0,0.5f}, {0.05f, 0.05f, 0.05f});
|
||||
J3D::WireframeAABB(Colors::Yellow, {0.5, 0, 0.5}, {0.125, 0.125, 0.125}, 1);
|
||||
Matrix3x3 cube_rotation = Matrix3x3(Quaternion(EulerAngleXYZ(0, 20, 0)));
|
||||
J3D::WireframeOBB(Colors::Red, {0.25, 0 , 0.5}, {0.125, 0.125, 0.125}, cube_rotation, 1);
|
||||
J3D::End();
|
||||
|
||||
J2D::Begin(j2d_render_target, true);
|
||||
@@ -294,7 +297,6 @@ public:
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
auto* window = new JGLDemoWindow("JGL Demo Window", 1280, 720);
|
||||
if (!window->Open())
|
||||
exit(-1);
|
||||
|
@@ -1,57 +1,58 @@
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
static std::array<Vector3, 8> cube_v {
|
||||
Vector3(1.0f, 1.0f, -1.0f),
|
||||
Vector3(1.0f, -1.0f, -1.0f),
|
||||
Vector3(1.0f, 1.0f, 1.0f),
|
||||
Vector3(1.0f, -1.0f, 1.0f),
|
||||
Vector3(-1.0f, 1.0f, -1.0f),
|
||||
Vector3(-1.0f, -1.0f, -1.0f),
|
||||
Vector3(-1.0f, 1.0f, 1.0f),
|
||||
Vector3(-1.0f, -1.0f, 1.0f)
|
||||
};
|
||||
|
||||
std::array<unsigned int, 36> cube_ind {
|
||||
4, 2, 0,
|
||||
2, 7, 3,
|
||||
6, 5, 7,
|
||||
1, 7, 5,
|
||||
0, 3, 1,
|
||||
4, 1, 5,
|
||||
4, 6, 2,
|
||||
2, 6, 7,
|
||||
6, 4, 5,
|
||||
1, 3, 7,
|
||||
0, 2, 3,
|
||||
4, 0, 1
|
||||
};
|
||||
|
||||
std::array<Vector3, 8> cube_vn {
|
||||
Vector3( 0.816f, 0.408f, -0.408f),
|
||||
Vector3( 0.333f, -0.667f, -0.667f),
|
||||
Vector3( 0.333f, 0.667f, 0.667f),
|
||||
Vector3( 0.816f, -0.408f, 0.408f),
|
||||
Vector3(-0.333f, 0.667f, -0.667f),
|
||||
Vector3(-0.816f, -0.408f, -0.408f),
|
||||
Vector3(-0.816f, 0.408f, 0.408f),
|
||||
Vector3(-0.333f, -0.667f, 0.667f)
|
||||
};
|
||||
|
||||
std::array<Vector2, 4> square_v { Vector2(0, 0), {1, 0}, {1, -1}, {0, -1} };
|
||||
std::array<GLfloat, 3> square_vn {0, 0, 1};
|
||||
|
||||
void JGL::ShapeCache::Init() {
|
||||
std::array<Vector3, 8> vertices = {
|
||||
Vector3(1.0f, 1.0f, -1.0f),
|
||||
Vector3(1.0f, -1.0f, -1.0f),
|
||||
Vector3(1.0f, 1.0f, 1.0f),
|
||||
Vector3(1.0f, -1.0f, 1.0f),
|
||||
Vector3(-1.0f, 1.0f, -1.0f),
|
||||
Vector3(-1.0f, -1.0f, -1.0f),
|
||||
Vector3(-1.0f, 1.0f, 1.0f),
|
||||
Vector3(-1.0f, -1.0f, 1.0f)
|
||||
};
|
||||
std::array<unsigned int, 36> indices = {
|
||||
4, 2, 0,
|
||||
2, 7, 3,
|
||||
6, 5, 7,
|
||||
1, 7, 5,
|
||||
0, 3, 1,
|
||||
4, 1, 5,
|
||||
4, 6, 2,
|
||||
2, 6, 7,
|
||||
6, 4, 5,
|
||||
1, 3, 7,
|
||||
0, 2, 3,
|
||||
4, 0, 1
|
||||
};
|
||||
|
||||
std::array<Vector3, 8> vertex_normals = {
|
||||
Vector3( 0.816f, 0.408f, -0.408f),
|
||||
Vector3( 0.333f, -0.667f, -0.667f),
|
||||
Vector3( 0.333f, 0.667f, 0.667f),
|
||||
Vector3( 0.816f, -0.408f, 0.408f),
|
||||
Vector3(-0.333f, 0.667f, -0.667f),
|
||||
Vector3(-0.816f, -0.408f, -0.408f),
|
||||
Vector3(-0.816f, 0.408f, 0.408f),
|
||||
Vector3(-0.333f, -0.667f, 0.667f)
|
||||
};
|
||||
|
||||
if (!cube_vertex_data)
|
||||
cube_vertex_data = new VRamList(vertices.data(), vertices.size());
|
||||
cube_vertex_data = new VRamList(cube_v.data(), cube_v.size());
|
||||
|
||||
if (!cube_index_data)
|
||||
cube_index_data = new VRamList(indices.data(), indices.size());
|
||||
cube_index_data = new VRamList(cube_ind.data(), cube_ind.size());
|
||||
|
||||
if (!cube_normal_data)
|
||||
cube_normal_data = new VRamList(vertex_normals.data(), vertex_normals.size());
|
||||
cube_normal_data = new VRamList(cube_vn.data(), cube_vn.size());
|
||||
|
||||
if (!square_origin_topleft_vertex_data) {
|
||||
std::array<Vector2, 4> square_vertices = { Vector2(0, 0), {1, 0}, {1, -1}, {0, -1} };
|
||||
square_origin_topleft_vertex_data = new VRamList(square_vertices.data(), square_vertices.size());
|
||||
}
|
||||
if (!j2d_default_normal_data) {
|
||||
std::array<GLfloat, 3> normal {0, 0, 1};
|
||||
j2d_default_normal_data = new VRamList(normal.data(), normal.size());
|
||||
}
|
||||
if (!square_origin_topleft_vertex_data)
|
||||
square_origin_topleft_vertex_data = new VRamList(square_v.data(), square_v.size());
|
||||
|
||||
if (!j2d_default_normal_data)
|
||||
j2d_default_normal_data = new VRamList(square_vn.data(), square_vn.size());
|
||||
}
|
@@ -18,15 +18,15 @@ std::array<GLfloat, 16> JGL::OpenGLPerspectiveProjectionRH(float fovY, float asp
|
||||
return result;
|
||||
}
|
||||
|
||||
void JGL::J3D::ChangeFOV(float fov) {
|
||||
JGL::J3D::fov = fov;
|
||||
void J3D::ChangeFOV(float fov) {
|
||||
J3D::fov = fov;
|
||||
}
|
||||
|
||||
void JGL::J3D::ChangeFarPlane(float far_plane) {
|
||||
JGL::J3D::far_plane = far_plane;
|
||||
void J3D::ChangeFarPlane(float far_plane) {
|
||||
J3D::far_plane = far_plane;
|
||||
}
|
||||
|
||||
void JGL::J3D::RequiredLight(const JGL::LightBase* light) {
|
||||
void J3D::RequiredLight(const LightBase* light) {
|
||||
bool success = false;
|
||||
for (auto& i : current_state.required_lights)
|
||||
if (i == nullptr) {
|
||||
@@ -39,12 +39,12 @@ void JGL::J3D::RequiredLight(const JGL::LightBase* light) {
|
||||
Logger::Error("You cannot specify more than 8 required lights.");
|
||||
}
|
||||
|
||||
void JGL::J3D::OptionalLights(const JGL::LightBase** lights, const size_t& light_count) {
|
||||
void J3D::OptionalLights(const LightBase** lights, const size_t& light_count) {
|
||||
for (size_t i = 0; i < light_count; i++)
|
||||
current_state.optional_lights.push_back(lights[i]);
|
||||
}
|
||||
|
||||
void JGL::J3D::Begin(bool two_pass) {
|
||||
void J3D::Begin(bool two_pass) {
|
||||
auto aspect = (float) window_size.x / (float) window_size.y;
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
@@ -97,7 +97,7 @@ void JGL::J3D::Begin(bool two_pass) {
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void JGL::J3D::End() {
|
||||
void J3D::End() {
|
||||
if (!current_state.depth_test)
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -138,7 +138,7 @@ void JGL::J3D::End() {
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::DrawLine(const Color4& color, const Vector3& A, const Vector3& B, float thickness) {
|
||||
void J3D::DrawLine(const Color4& color, const Vector3& A, const Vector3& B, float thickness) {
|
||||
Vector3 vertices[] = {A, B};
|
||||
|
||||
glLineWidth(thickness);
|
||||
@@ -148,16 +148,16 @@ void JGL::J3D::DrawLine(const Color4& color, const Vector3& A, const Vector3& B,
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
Sphere sphere = {position, radius};
|
||||
BatchWireframeSphere(color,& sphere, 1, thickness, sectors, stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeSphere(const Color4& color, const Sphere& sphere, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::WireframeSphere(const Color4& color, const Sphere& sphere, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
BatchWireframeSphere(color,& sphere, 1, thickness, sectors, stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::BatchWireframeSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::BatchWireframeSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, float thickness, unsigned int sectors, unsigned int stacks) {
|
||||
// Create one sphere with a radius of 1 about 0, 0.
|
||||
float r = 1;
|
||||
std::vector<Vector3> vertices((sectors + 1) * (stacks + 1));
|
||||
@@ -196,16 +196,16 @@ void JGL::J3D::BatchWireframeSphere(const Color4& color, const Sphere* spheres,
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeRevoSphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
void J3D::WireframeRevoSphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
Sphere sphere = {position, radius};
|
||||
BatchWireframeRevoSphere(color,& sphere, 1, thickness, sectors, revolutions, draw_stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeRevoSphere(const Color4& color, const Sphere& sphere, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
void J3D::WireframeRevoSphere(const Color4& color, const Sphere& sphere, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
BatchWireframeRevoSphere(color,& sphere, 1, thickness, sectors, revolutions, draw_stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::BatchWireframeRevoSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
void J3D::BatchWireframeRevoSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, float thickness, unsigned int sectors, unsigned int revolutions, bool draw_stacks) {
|
||||
float r = 1;
|
||||
std::vector<Vector3> vertices;
|
||||
vertices.reserve((sectors + 1) * (revolutions + 1));
|
||||
@@ -255,7 +255,7 @@ void JGL::J3D::BatchWireframeRevoSphere(const Color4& color, const Sphere* spher
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int subdivisions) {
|
||||
void J3D::WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int subdivisions) {
|
||||
|
||||
// NOTE2SELF: Code i'm borrowing this from uses float-packed-arrays rather than discrete Vectors
|
||||
// working on translating that correctly...
|
||||
@@ -325,7 +325,7 @@ void JGL::J3D::WireframeIcosphere(const Color4& color, const Vector3& position,
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeIcosahedron(const Color4& color, const Vector3& position, float radius, float thickness) {
|
||||
void J3D::WireframeIcosahedron(const Color4& color, const Vector3& position, float radius, float thickness) {
|
||||
// TODO: Revise this once J3ML::Geometry::Icosahedron is implemented.
|
||||
const float h_angle = J3ML::Math::Pi / 180.f * 72.f; // 72 degree = 360 / 5;
|
||||
const float v_angle = J3ML::Math::Atan(1.0f / 2.f); // elevation = 26.565;
|
||||
@@ -367,7 +367,7 @@ void JGL::J3D::WireframeIcosahedron(const Color4& color, const Vector3& position
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::BatchWireframeAABB(const Color4& color, const AABB* boxes, const size_t& box_count, float thickness) {
|
||||
void J3D::BatchWireframeAABB(const Color4& color, const AABB* boxes, const size_t& box_count, float thickness) {
|
||||
glColor4ubv(color.ptr());
|
||||
glLineWidth(thickness);
|
||||
|
||||
@@ -388,12 +388,33 @@ void JGL::J3D::BatchWireframeAABB(const Color4& color, const AABB* boxes, const
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeAABB(const Color4& color, const Vector3& pos, const Vector3& radii, float thickness) {
|
||||
void J3D::WireframeOBB(const Color4& color, const Vector3& center, const Vector3& radii, const Matrix3x3& rotation_matrix, float thickness) {
|
||||
glColor4ubv(color.ptr());
|
||||
glLineWidth(thickness);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, ShapeCache::cube_vertex_data->GetHandle());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), nullptr);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ShapeCache::cube_index_data->GetHandle());
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(center.x, center.y, center.z);
|
||||
// TODO AxisAngle directly from rotation matrix.
|
||||
AxisAngle rotate_part = AxisAngle(Quaternion(rotation_matrix));
|
||||
glRotatef(rotate_part.angle, rotate_part.axis.x, rotate_part.axis.y, rotate_part.axis.z);
|
||||
glScalef(radii.x, radii.y, radii.z);
|
||||
glDrawElements(GL_LINE_LOOP, ShapeCache::cube_index_data->GetLength(), GL_UNSIGNED_INT, nullptr);
|
||||
glPopMatrix();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void J3D::WireframeAABB(const Color4& color, const Vector3& pos, const Vector3& radii, float thickness) {
|
||||
AABB aabb = {Vector3(pos.x - radii.x, pos.y - radii.y, pos.z - radii.z), Vector3(pos.x + radii.x, pos.y + radii.y, pos.z + radii.z)};
|
||||
BatchWireframeAABB(color, &aabb, 1, thickness);
|
||||
}
|
||||
|
||||
void JGL::J3D::BatchFillAABB(const Color4& color, const AABB* boxes, const size_t& box_count) {
|
||||
void J3D::BatchFillAABB(const Color4& color, const AABB* boxes, const size_t& box_count) {
|
||||
glColor4ubv(color.ptr());
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, ShapeCache::cube_vertex_data->GetHandle());
|
||||
@@ -430,20 +451,20 @@ void JGL::J3D::BatchFillAABB(const Color4& color, const AABB* boxes, const size_
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
void JGL::J3D::FillAABB(const Color4& color, const Vector3& pos, const Vector3& radii) {
|
||||
void J3D::FillAABB(const Color4& color, const Vector3& pos, const Vector3& radii) {
|
||||
AABB box = {pos - radii, pos + radii};
|
||||
BatchFillAABB(color, &box, 1);
|
||||
}
|
||||
|
||||
void JGL::J3D::FillAABB(const Color4& color, const AABB& aabb) {
|
||||
void J3D::FillAABB(const Color4& color, const AABB& aabb) {
|
||||
BatchFillAABB(color, &aabb, 1);
|
||||
}
|
||||
|
||||
void JGL::J3D::FillSphere(const Color4& color, const Sphere& sphere, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::FillSphere(const Color4& color, const Sphere& sphere, unsigned int sectors, unsigned int stacks) {
|
||||
BatchFillSphere(color, &sphere, 1, sectors, stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::BatchFillSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::BatchFillSphere(const Color4& color, const Sphere* spheres, const size_t& sphere_count, unsigned int sectors, unsigned int stacks) {
|
||||
float r = 1;
|
||||
std::vector<Vector3> vertices((sectors + 1) * (stacks + 1));
|
||||
std::vector<unsigned int> indices; indices.reserve(sectors * stacks * 6);
|
||||
@@ -503,50 +524,16 @@ void JGL::J3D::BatchFillSphere(const Color4& color, const Sphere* spheres, const
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::FillSphere(const Color4& color, const Vector3& position, float radius, unsigned int sectors, unsigned int stacks) {
|
||||
void J3D::FillSphere(const Color4& color, const Vector3& position, float radius, unsigned int sectors, unsigned int stacks) {
|
||||
Sphere sphere = {position, radius};
|
||||
BatchFillSphere(color, &sphere, 1, sectors, stacks);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeAABB(const Color4& color, const AABB& aabb, float thickness) {
|
||||
void J3D::WireframeAABB(const Color4& color, const AABB& aabb, float thickness) {
|
||||
BatchWireframeAABB(color, &aabb, 1, thickness);
|
||||
}
|
||||
|
||||
// TODO Make it work the same as AABB batching. I couldn't get rotation to do anything more than twitch in place :(.
|
||||
void JGL::J3D::BatchWireframeOBB(const Color4& color, const OBB* boxes, const size_t& box_count, float thickness) {
|
||||
std::array<Vector3, 8> corner_points;
|
||||
std::array<GLuint, 24> indices =
|
||||
{
|
||||
0, 1, 1, 2, 2, 3, 3, 0,
|
||||
4, 5, 5, 6, 6, 7, 7, 4,
|
||||
0, 4, 1, 5, 2, 6, 3, 7
|
||||
};
|
||||
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), corner_points.data());
|
||||
|
||||
for (size_t i = 0; i < box_count; i++) {
|
||||
boxes[i].GetCornerPoints(corner_points.data());
|
||||
glPushMatrix();
|
||||
glTranslatef(boxes[i].pos.x, boxes[i].pos.y, boxes[i].pos.z);
|
||||
glDrawElements(GL_LINES, indices.size(), GL_UNSIGNED_INT, indices.data());
|
||||
glPopMatrix();
|
||||
}
|
||||
glColor4fv(current_state.draw_color);
|
||||
}
|
||||
|
||||
void JGL::J3D::WireframeOBB(const Color4& color, const OBB& obb, float thickness) {
|
||||
BatchWireframeOBB(color, &obb, 1, thickness);
|
||||
}
|
||||
|
||||
/*
|
||||
void JGL::J3D::WireframeOBB(const Color4& color, const Vector3& position, const Vector3& radii, const Matrix3x3& orientation, float thickness) {
|
||||
WireframeOBB(color, OBB(position, radii, orientation. * Vector3::UnitX, rotation * Vector3::UnitY, rotation * Vector3::UnitZ), thickness);
|
||||
}
|
||||
*/
|
||||
|
||||
void JGL::J3D::DrawCubicBezierCurve(const Color4& color, const Vector3& controlA, const Vector3& pointA,
|
||||
void J3D::DrawCubicBezierCurve(const Color4& color, const Vector3& controlA, const Vector3& pointA,
|
||||
const Vector3& pointB, const Vector3& controlB, int subdivisions, float thickness) {
|
||||
Vector3 last = controlA;
|
||||
const Vector3& first = controlB;
|
||||
@@ -562,7 +549,7 @@ void JGL::J3D::DrawCubicBezierCurve(const Color4& color, const Vector3& controlA
|
||||
DrawLine(color, last, first, thickness);
|
||||
}
|
||||
|
||||
void JGL::J3D::DrawVertexArray(const Color4& color, const VertexArray& vertex_array, const Vector3& position) {
|
||||
void J3D::DrawVertexArray(const Color4& color, const VertexArray& vertex_array, const Vector3& position) {
|
||||
glColor4ubv(color.ptr());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
@@ -580,5 +567,4 @@ void JGL::J3D::DrawVertexArray(const Color4& color, const VertexArray& vertex_ar
|
||||
glColor4fv(current_state.draw_color);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
71
src/types/Light2D.cpp
Normal file
71
src/types/Light2D.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <JGL/types/Light2D.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
JGL::J2D::PointLight::PointLight(const Vector2& position, const Color4& ambient, const Color4& diffuse, float constant_attenuation, float linear_attenuation, float quadratic_attenuation) {
|
||||
light_pos = Vector4(position.x, position.y, 1, 1);
|
||||
this->ambient = ambient;
|
||||
this->diffuse = diffuse;
|
||||
this->constant_attenuation = constant_attenuation;
|
||||
this->linear_attenuation = linear_attenuation;
|
||||
this->quadratic_attenuation = quadratic_attenuation;
|
||||
}
|
||||
|
||||
float JGL::J2D::PointLight::MeasureIntensityAtPosition(const Vector2& position) const {
|
||||
float d = Vector2::Distance( Vector2(light_pos.x, light_pos.y), position);
|
||||
|
||||
// Fix possible divide by zero if the position we're measuring happens to be directly on-top of the light.
|
||||
if (d == 0)
|
||||
d = 0.00001;
|
||||
|
||||
return 1.f / (constant_attenuation + linear_attenuation * d + quadratic_attenuation * d * d);
|
||||
}
|
||||
|
||||
Vector2 JGL::J2D::Light::Position() const {
|
||||
return { light_pos.x, light_pos.y };
|
||||
}
|
||||
|
||||
Color4 JGL::J2D::Light::Ambient() const {
|
||||
return ambient;
|
||||
}
|
||||
|
||||
Color4 JGL::J2D::Light::Diffuse() const {
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
float JGL::J2D::Light::Constant() const {
|
||||
return constant_attenuation;
|
||||
}
|
||||
|
||||
float JGL::J2D::Light::Linear() const {
|
||||
return linear_attenuation;
|
||||
}
|
||||
|
||||
float JGL::J2D::Light::Quadratic() const {
|
||||
return quadratic_attenuation;
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Position(const Vector2& new_position) {
|
||||
light_pos.x = new_position.x;
|
||||
light_pos.y = new_position.y;
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Ambient(const Color4& new_ambient) {
|
||||
ambient = new_ambient;
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Diffuse(const Color4& new_diffuse) {
|
||||
diffuse = new_diffuse;
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Constant(float new_constant_attenuation) {
|
||||
constant_attenuation = std::clamp(new_constant_attenuation, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Linear(float new_linear_attenuation) {
|
||||
linear_attenuation = std::clamp(new_linear_attenuation, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void JGL::J2D::Light::Quadratic(float new_quadratic_attenuation) {
|
||||
quadratic_attenuation = std::clamp(new_quadratic_attenuation, 0.0f, 1.0f);
|
||||
}
|
Reference in New Issue
Block a user