Make it go faster
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2024-10-22 19:00:14 -04:00
parent 686a4be0c9
commit 4d97c6dead
3 changed files with 38 additions and 37 deletions

View File

@@ -322,7 +322,7 @@ namespace JGL {
void DrawLine(const Color4& color, const Vector3& A, const Vector3& B, float thickness = 1.f);
void WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f);
void WireframeSphere(const Color4& color, const Vector3& position, float radius, unsigned int lats, unsigned int longs, float thickness = 1.f);
void WireframeSphere(const Color4& color, const Sphere& sphere, float thickness = 1.f);
void WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f);
void WireframeIcosphere(const Color4& color, const Sphere& sphere, float thickness = 1.f);

View File

@@ -150,7 +150,6 @@ public:
fov_increasing = false;
else if (fov <= 75)
fov_increasing = true;
J3D::ChangeFOV(fov);
sprite_radians += 0.005;
textAngle.y += .05f;
@@ -166,7 +165,7 @@ public:
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::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
J3D::WireframeSphere(Colors::Green, {0,0,0.05f}, 0.01f, 0.5f);
J3D::WireframeSphere(Colors::Green, {0,0,1.f}, 0.25f, 25, 25, 1.f);
J3D::End();
J2D::Begin(j2d_render_target, true);
@@ -220,6 +219,18 @@ public:
}
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();
a.Update(mouse);
b.Update(mouse);

View File

@@ -1061,54 +1061,44 @@ namespace JGL {
glColor4fv(baseColor);
}
void J3D::WireframeSphere(const Color4 &color, const Vector3 &position, float radius, float thickness) {
void J3D::WireframeSphere(const Color4& color, const Vector3& position, float radius, unsigned int lats, unsigned int longs, float thickness) {
if (!inJ3D)
Logger::Error("Drawing J3D element before J3D begin.");
glLineWidth(thickness);
glColor4ubv(color.ptr());
float r = radius;
int lats = 50;
int longs = 50;
std::vector<Vector3> vertices(2 + (lats + 1) * (longs + 1));
int i, j;
for(i = 0; i <= lats; i++) {
double lat0 = M_PI * (-0.5 + (double) (i - 1) / lats);
double z0 = sin(lat0);
double zr0 = cos(lat0);
int index = 0;
for (int i = 0; i <= lats; i++) {
float lat = M_PI * (-0.5 + (float) i / lats);
float z = J3ML::Math::Sin(lat);
float zr = J3ML::Math::Cos(lat);
double lat1 = M_PI * (-0.5 + (double) i / lats);
double z1 = sin(lat1);
double zr1 = cos(lat1);
for (int j = 0; j <= longs; j++) {
float lng = 2 * J3ML::Math::Pi * (float) (j - 1) / longs;
float x = J3ML::Math::Cos(lng);
float y = J3ML::Math::Sin(lng);
glLineWidth(thickness);
glBegin(GL_LINE_LOOP);
for(j = 0; j <= longs; j++) {
double lng = 2 * M_PI * (double) (j - 1) / longs;
double x = cos(lng);
double y = sin(lng);
float pos_x = r * x * zr0;
float pos_y = r * y * zr0;
float pos_z = r * z0;
float pos_x = r * x * zr;
float pos_y = r * y * zr;
float pos_z = r * z;
pos_x += position.x;
pos_y += position.y;
pos_z += position.z;
//glNormal3f(x * zr0, y * zr0, z0);
glVertex3f(pos_x, pos_y, pos_z);
float pos2_x = r * x * zr1;
float pos2_y = r * y * zr1;
float pos2_z = r * z1;
pos2_x += position.x;
pos2_y += position.y;
pos2_z += position.z;
//glNormal3f(x * zr1, y * zr1, z1);
glVertex3f(pos2_x, pos2_y, pos2_z);
vertices[index++] = Vector3(pos_x, pos_y, pos_z);
}
glEnd();
}
glLineWidth(thickness);
glColor4ubv(color.ptr());
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
glDrawArrays(GL_LINE_LOOP, 0, vertices.size() -1);
glColor4fv(baseColor);
}
#pragma endregion