This commit is contained in:
Nishi 2026-01-11 20:26:15 +09:00
commit dd544c245e
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 81 additions and 68 deletions

View file

@ -2,6 +2,7 @@
#include <GearBox/Log.h>
#include <GearBox/GL.h>
#include <GearBox/Math.h>
GBClient GBClientCreate(GBEngine engine) {
GBClient client = malloc(sizeof(*client));
@ -10,9 +11,9 @@ GBClient GBClientCreate(GBEngine engine) {
client->engine = engine;
client->camera[0] = 2;
client->camera[1] = 1.5;
client->camera[2] = 2;
client->camera[0] = 5;
client->camera[1] = 5;
client->camera[2] = 5;
client->look_at[0] = 0;
client->look_at[1] = 0;
@ -38,62 +39,50 @@ void GBClientDestroy(GBClient client) {
GBLog(GBLogInfo, "Destroyed client");
}
static double r = 0;
static void scene(void) {
glColor3f(1, 1, 1);
int i;
double u = 1;
glPushMatrix();
glTranslatef(0, fabs(sin(r)), 1);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 0, -1);
glVertex3f(-1, 0, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 0, -1);
glEnd();
int i;
glColor3f(1, 0, 0);
for(i = 0; i < 2; i++) {
glPushMatrix();
glRotatef(180 * i, 0, 1, 0);
glBegin(GL_QUADS);
glNormal3f(-1, 0, 0);
glVertex3f(-1, 0.5, 0.25);
glVertex3f(-1, 0, 0.25);
glVertex3f(1, 0, 0.25);
glVertex3f(1, 0.5, 0.25);
glEnd();
glPopMatrix();
glNormal3f(0, -1, 0);
for(i = 0; i < 4; i++) {
glVertex3f(cos(90 * i / 180.0 * GBMathPi), u, sin(90 * i / 180.0 * GBMathPi));
}
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 0.5, -0.25);
glVertex3f(-1, 0.5, 0.25);
glVertex3f(1, 0.5, 0.25);
glVertex3f(1, 0.5, -0.25);
glEnd();
for(i = 0; i < 4; i++) {
double n[3];
double v0[3];
double v1[3];
double v2[3];
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, -0.5, 0.25);
glVertex3f(-1, -0.5, -0.25);
glVertex3f(1, -0.5, -0.25);
glVertex3f(1, -0.5, 0.25);
glEnd();
v0[0] = 0;
v0[1] = 1 + u;
v0[2] = 0;
glBegin(GL_QUADS);
glNormal3f(-1, 0, 0);
glVertex3f(-1, 0.5, 0.25);
glVertex3f(-1, 0.5, -0.25);
glVertex3f(-1, 0, -0.25);
glVertex3f(-1, 0, 0.25);
glEnd();
v1[0] = cos(90 * (i + 1) / 180.0 * GBMathPi);
v1[1] = u;
v1[2] = sin(90 * (i + 1) / 180.0 * GBMathPi);
glBegin(GL_QUADS);
glNormal3f(1, 0, 0);
glVertex3f(1, 0.5, -0.25);
glVertex3f(1, 0.5, 0.25);
glVertex3f(1, 0, 0.25);
glVertex3f(1, 0, -0.25);
glEnd();
v2[0] = cos(90 * i / 180.0 * GBMathPi);
v2[1] = u;
v2[2] = sin(90 * i / 180.0 * GBMathPi);
GBMathNormal3x3(n, v0, v1, v2);
glBegin(GL_TRIANGLES);
glNormal3f(n[0], n[1], n[2]);
glVertex3f(v0[0], v0[1], v0[2]);
glVertex3f(v1[0], v1[1], v1[2]);
glVertex3f(v2[0], v2[1], v2[2]);
glEnd();
}
glPopMatrix();
}
void GBClientStep(GBClient client) {
@ -118,18 +107,24 @@ void GBClientStep(GBClient client) {
scene();
GBGLShadowAfterMapping(client->gl);
}
glDisable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-10, -0, -10);
glVertex3f(-10, -0, 10);
glVertex3f(10, -0, 10);
glVertex3f(10, -0, -10);
glEnd();
glEnable(GL_DEPTH_TEST);
scene();
GBGLShadowEnd(client->gl);
client->engine->param->gl_swapbuffer();
static double r = 0;
client->camera[0] = cos(r) * 2;
client->camera[2] = sin(r) * 2;
client->light0[0] = -cos(r) * 5;
client->light0[2] = -sin(r) * 5;
client->light0[0] = cos(r) * 5;
client->light0[2] = sin(r) * 5;
r += 0.1;
}

View file

@ -9,7 +9,7 @@ void GBGLPerspective(GBGL gl, double width, double height) {
int i;
double fovy = 60.0;
double znear = 0.01;
double zfar = 10.0;
double zfar = 100.0;
aspect = width / height;
f = GBMathCot(fovy / 180 * GBMathPi / 2);

View file

@ -2,8 +2,8 @@
#include <GearBox/Math.h>
#define SHADOW_WIDTH 1024
#define SHADOW_HEIGHT 1024
#define SHADOW_WIDTH 512
#define SHADOW_HEIGHT 512
#define SHADOW_CULL
void GBGLShadowInit(GBGL gl) {

View file

@ -46,7 +46,7 @@ void GBMathNormal3x3(GBVector3 r, GBVector3 v0, GBVector3 v1, GBVector3 v2) {
GBVector3 t0, t1;
GBMathSubtract3(t0, v1, v0);
GBMathSubtract3(t0, v2, v0);
GBMathSubtract3(t1, v2, v0);
GBMathCross3(r, t0, t1);