Sending up work
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m44s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m44s
This commit is contained in:
@@ -308,10 +308,15 @@ namespace JGL {
|
|||||||
/// Drawing functions for primitive 3D Shapes.
|
/// Drawing functions for primitive 3D Shapes.
|
||||||
namespace J3D {
|
namespace J3D {
|
||||||
void Init(const Vector2 &window_size, float fov, float far_plane);
|
void Init(const Vector2 &window_size, float fov, float far_plane);
|
||||||
|
|
||||||
void ChangeFOV(float fov);
|
void ChangeFOV(float fov);
|
||||||
|
|
||||||
void ChangeFarPlane(float far_plane);
|
void ChangeFarPlane(float far_plane);
|
||||||
|
|
||||||
void Begin();
|
void Begin();
|
||||||
|
|
||||||
void End();
|
void End();
|
||||||
|
|
||||||
void SetMatrix(const std::vector<GLfloat> &matrix, const Vector2 &window_size);
|
void SetMatrix(const std::vector<GLfloat> &matrix, const Vector2 &window_size);
|
||||||
|
|
||||||
/// Draws a line in 3D space.
|
/// Draws a line in 3D space.
|
||||||
@@ -321,9 +326,10 @@ namespace JGL {
|
|||||||
/// @param thickness
|
/// @param thickness
|
||||||
void DrawLine(const Color4 &color, const Vector3 &A, const Vector3 &B, float thickness = 1.f);
|
void DrawLine(const Color4 &color, const Vector3 &A, const Vector3 &B, float thickness = 1.f);
|
||||||
|
|
||||||
|
void WireframeIcosahedron(const Color4 &color, const Vector3 &position, float radius, float thickness = 1.f);
|
||||||
|
|
||||||
void WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
void WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, uint sectors = 10, uint stacks = 10);
|
||||||
void WireframeSphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, unsigned int subdivisions = 10);
|
void WireframeSphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, uint sectors = 10, uint stacks = 10);
|
||||||
void WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
void WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||||
void WireframeIcosphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, unsigned int subdivisions = 10);
|
void WireframeIcosphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||||
void WireframeCubesphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
void WireframeCubesphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||||
|
16
main.cpp
16
main.cpp
@@ -166,7 +166,8 @@ public:
|
|||||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
||||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
||||||
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
|
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
|
||||||
J3D::WireframeSphere(Colors::Green, {0,0,1.f}, 0.25f, 25, 1.f);
|
J3D::WireframeSphere(Colors::Green, {0,0,0.5f}, 0.25f, 1.f, 10, 10);
|
||||||
|
//J3D::WireframeIcosahedron(Colors::Green, {0,0,0.5f}, 0.125f, 1.f);
|
||||||
J3D::End();
|
J3D::End();
|
||||||
|
|
||||||
J2D::Begin(j2d_render_target, true);
|
J2D::Begin(j2d_render_target, true);
|
||||||
@@ -220,6 +221,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnRefresh(float elapsed) override {
|
void OnRefresh(float elapsed) override {
|
||||||
|
if (isKeyDown(Keys::RightArrow))
|
||||||
|
camera->angle.y += 45.f * elapsed;
|
||||||
|
if (isKeyDown(Keys::LeftArrow))
|
||||||
|
camera->angle.y -= 45.f * elapsed;
|
||||||
|
if (isKeyDown(Keys::UpArrow))
|
||||||
|
camera->angle.x -= 45.f * elapsed;
|
||||||
|
if (isKeyDown(Keys::DownArrow))
|
||||||
|
camera->angle.x += 45.f * elapsed;
|
||||||
|
if (isKeyDown(Keys::Space))
|
||||||
|
camera->position.y += 1.f * elapsed;
|
||||||
|
if (isKeyDown(Keys::LeftShift))
|
||||||
|
camera->position.y -= 1.f * elapsed;
|
||||||
|
|
||||||
auto mouse = GetMouseCoordinates();
|
auto mouse = GetMouseCoordinates();
|
||||||
a.Update(mouse);
|
a.Update(mouse);
|
||||||
b.Update(mouse);
|
b.Update(mouse);
|
||||||
|
116
src/JGL.cpp
116
src/JGL.cpp
@@ -6,6 +6,7 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <J3ML/Algorithm/Bezier.hpp>
|
#include <J3ML/Algorithm/Bezier.hpp>
|
||||||
#include <JGL/logger/logger.h>
|
#include <JGL/logger/logger.h>
|
||||||
|
#include "JGL/types/VRamList.h"
|
||||||
|
|
||||||
JGL::RenderTarget* render_target = nullptr;
|
JGL::RenderTarget* render_target = nullptr;
|
||||||
GLfloat oldColor[4] = {0, 0, 0, 1};
|
GLfloat oldColor[4] = {0, 0, 0, 1};
|
||||||
@@ -1061,15 +1062,15 @@ namespace JGL {
|
|||||||
glColor4fv(baseColor);
|
glColor4fv(baseColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void J3D::WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness, unsigned int subdivisions) {
|
void J3D::WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness, uint sectors, uint stacks) {
|
||||||
if (!inJ3D)
|
if (!inJ3D)
|
||||||
Logger::Error("Drawing J3D element before J3D begin.");
|
Logger::Error("Drawing J3D element before J3D begin.");
|
||||||
|
|
||||||
glLineWidth(thickness);
|
glLineWidth(thickness);
|
||||||
glColor4ubv(color.ptr());
|
glColor4ubv(color.ptr());
|
||||||
|
|
||||||
unsigned int lats = subdivisions;
|
unsigned int lats = sectors;
|
||||||
unsigned int longs = subdivisions;
|
unsigned int longs = stacks;
|
||||||
|
|
||||||
float r = radius;
|
float r = radius;
|
||||||
std::vector<Vector3> vertices((lats + 1) * (longs + 1));
|
std::vector<Vector3> vertices((lats + 1) * (longs + 1));
|
||||||
@@ -1099,19 +1100,118 @@ namespace JGL {
|
|||||||
|
|
||||||
glLineWidth(thickness);
|
glLineWidth(thickness);
|
||||||
glColor4ubv(color.ptr());
|
glColor4ubv(color.ptr());
|
||||||
|
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||||
glDrawArrays(GL_LINE_LOOP, 0, vertices.size());
|
glDrawArrays(GL_LINES, 0, vertices.size());
|
||||||
glColor4fv(baseColor);
|
glColor4fv(baseColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void J3D::WireframeIcosphere(const Color4 &color, const Vector3& position, float radius, float thickness,
|
void J3D::WireframeIcosphere(const Color4 &color, const Vector3& position, float radius, float thickness,
|
||||||
unsigned int subdivisions) {
|
unsigned int subdivisions) {
|
||||||
const float h_angle = Math::Pi / 180 * 72; // 72 degree = 360 / 5;
|
// TODO: Revise this once J3ML::Geometry::Icosahedron is implemented.
|
||||||
const float v_angle = Math::Atan(1.f / 2.f);
|
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;
|
||||||
|
|
||||||
std::vector<float> vertices(12*3);
|
std::vector<Vector3> vertices; // array of 12 vertices (x,y,z)
|
||||||
|
unsigned int index = 0; // indices
|
||||||
|
float z, xy; // coords
|
||||||
|
float hAngle1 = -Math::Pi / 2.f - h_angle / 2.f; // start from -126 at 1st row
|
||||||
|
float hAngle2 = -Math::Pi / 2.f; // start from -90 deg at 2nd row
|
||||||
|
|
||||||
|
// the first top vertex at (0,0,r)
|
||||||
|
vertices[0] = position + Vector3{0,0,radius};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// compute 10 vertices at 1st and 2nd rows
|
||||||
|
for (int i = 1; i <= 5; ++i)
|
||||||
|
{
|
||||||
|
|
||||||
|
z = radius * Math::Sin(v_angle); // elevation
|
||||||
|
xy = radius * Math::Cos(v_angle); // length on XY plane
|
||||||
|
|
||||||
|
vertices[index++] = position + Vector3{xy * Math::Cos(hAngle1), xy * Math::Sin(hAngle1), z} ;
|
||||||
|
vertices[index++] = position + Vector3{xy * Math::Cos(hAngle2), xy * Math::Sin(hAngle2), -z};
|
||||||
|
|
||||||
|
// next horizontal angles
|
||||||
|
hAngle1 += h_angle;
|
||||||
|
hAngle2 += h_angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the last bottom vertex at (0, 0, -r)
|
||||||
|
vertices[11] = position + Vector3{0,0, -radius};
|
||||||
|
|
||||||
|
//glLineWidth(thickness);
|
||||||
|
//glColor4ubv(color.ptr());
|
||||||
|
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||||
|
//glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||||
|
//glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
|
||||||
|
//glColor4fv(baseColor);
|
||||||
|
|
||||||
|
std::vector<Vector3> tmpVertices;
|
||||||
|
std::vector<Vector3> tmpIndices;
|
||||||
|
std::vector<Vector2> newVs((subdivisions+1) * (subdivisions+2) / 2 * 3);
|
||||||
|
const Vector3 v1, v2, v3;
|
||||||
|
Vector3 newV1, newV2, newV3;
|
||||||
|
|
||||||
|
int i, j, k;
|
||||||
|
index = 0; // unsigned int
|
||||||
|
float a; // lerp alpha
|
||||||
|
unsigned int i1, i2; // indices
|
||||||
|
|
||||||
|
// copy prev arrays
|
||||||
|
tmpVertices = vertices;
|
||||||
|
//tmpIndices = indices;
|
||||||
|
|
||||||
|
// iterate each triangle of icosahedron
|
||||||
|
for (i = 0; i < tmpIndices.size(); i++)
|
||||||
|
{
|
||||||
|
//v1 = tmpVertices[tmpIndices[i]];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
std::array<Vector3, 12> vertices; // array of 12 vertices (x,y,z)
|
||||||
|
int index = 0; // indices
|
||||||
|
float z, xy; // coords
|
||||||
|
float hAngle1 = -Math::Pi / 2.f - h_angle / 2.f; // start from -126 at 1st row
|
||||||
|
float hAngle2 = -Math::Pi / 2.f; // start from -90 deg at 2nd row
|
||||||
|
|
||||||
|
// the first top vertex at (0,0,r)
|
||||||
|
vertices[0] = position + Vector3{0,0,radius};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// compute 10 vertices at 1st and 2nd rows
|
||||||
|
for (int i = 1; i <= 5; ++i)
|
||||||
|
{
|
||||||
|
|
||||||
|
z = radius * Math::Sin(v_angle); // elevation
|
||||||
|
xy = radius * Math::Cos(v_angle); // length on XY plane
|
||||||
|
|
||||||
|
vertices[index++] = position + Vector3{xy * Math::Cos(hAngle1), xy * Math::Sin(hAngle1), z} ;
|
||||||
|
vertices[index++] = position + Vector3{xy * Math::Cos(hAngle2), xy * Math::Sin(hAngle2), -z};
|
||||||
|
|
||||||
|
// next horizontal angles
|
||||||
|
hAngle1 += h_angle;
|
||||||
|
hAngle2 += h_angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the last bottom vertex at (0, 0, -r)
|
||||||
|
vertices[11] = position + Vector3{0,0, -radius};
|
||||||
|
|
||||||
|
glLineWidth(thickness);
|
||||||
|
glColor4ubv(color.ptr());
|
||||||
|
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||||
|
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
|
||||||
|
glColor4fv(baseColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
Reference in New Issue
Block a user