somewhat corrected movements(?) and texcoord caching

This commit is contained in:
Safariminer 2025-07-26 19:13:56 -04:00
parent 8e9a80caf0
commit 7d8b306daa
3 changed files with 41 additions and 120 deletions

View File

@ -408,21 +408,12 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path)
cface.glTextureHeight = data.textures[data.texInfo[data.faces[i].texinfoId].textureId].height;
for (int j = cface.vertices.size() - 1; j > 0; j--) {
for (int j = 0; j < cface.vertices.size(); j++) {
cface.texCoords.push_back(Vector2(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[0]), data.texInfo[data.faces[i].texinfoId].vectorS) + data.texInfo[data.faces[i].texinfoId].distS) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[0]), data.texInfo[data.faces[i].texinfoId].vectorT) + data.texInfo[data.faces[i].texinfoId].distT) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].height
));
cface.texCoords.push_back(Vector2(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[j]), data.texInfo[data.faces[i].texinfoId].vectorS) + data.texInfo[data.faces[i].texinfoId].distS) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[j]), data.texInfo[data.faces[i].texinfoId].vectorT) + data.texInfo[data.faces[i].texinfoId].distT) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].height
));
cface.texCoords.push_back(Vector2(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[j - 1]), data.texInfo[data.faces[i].texinfoId].vectorS) + data.texInfo[data.faces[i].texinfoId].distS) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(cface.vertices[j - 1]), data.texInfo[data.faces[i].texinfoId].vectorT) + data.texInfo[data.faces[i].texinfoId].distT) / data.textures[data.texInfo[data.faces[i].texinfoId].textureId].height
));
}

View File

@ -1,5 +1,15 @@
#pragma once
namespace MPFW {
namespace UI {
// main class that does the rendering of the UI y'know
class UIRenderer {
};
}
}

View File

@ -82,7 +82,7 @@ void Look() {
void AirAccelerate(bool inAir) {
if (IsKeyDown(KEY_W)) {
velocity += hRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 2 : 1);
velocity += hRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 4 : 2);
}
if (IsKeyDown(KEY_S)) {
velocity -= hRotation * GetFrameTime() * accelFactor;
@ -91,23 +91,20 @@ void AirAccelerate(bool inAir) {
Vector3 sideRotation = Vector3RotateByAxisAngle(hRotation, { 0,1,0 }, DEG2RAD * 90);
if (IsKeyDown(KEY_A)) {
velocity += sideRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 2 : 1);
velocity += sideRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 4 : 2);
}
if (IsKeyDown(KEY_D)) {
velocity -= sideRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 2 : 1);
velocity -= sideRotation * GetFrameTime() * accelFactor * (IsKeyDown(KEY_LEFT_SHIFT) ? 4 : 2);
}
if (inAir)velocity.y -= GetFrameTime();
velocity.x *= 16 * GetFrameTime();
velocity.z *= 16 * GetFrameTime();
if (inAir)velocity.y -= GetFrameTime() * 2.5;
velocity.x *= 80 * GetFrameTime();
velocity.z *= 80 * GetFrameTime();
}
void Accelerate() {
if (IsKeyDown(KEY_SPACE))velocity.y += accelFactor*0.01;
if (IsKeyDown(KEY_SPACE)) velocity.y += accelFactor * 0.0025;
AirAccelerate(false);
AirAccelerate(false);
if (velocity.y < 0) velocity.y = 0;
velocity *= 16*GetFrameTime();
}
@ -196,7 +193,7 @@ int main() {
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(1280, 720, TextFormat("mpfw"));
SetTargetFPS(60);
// SetTargetFPS(60);
SetExitKey(0);
DisableCursor();
@ -231,9 +228,9 @@ int main() {
}
if(!consoleOn){
Look();
if (camera.position.y > 6) AirAccelerate(true);
if (camera.position.y > 5) AirAccelerate(true);
else Accelerate();
if (camera.position.y < 5) camera.position.y = 5;
if (IsKeyPressed(KEY_LEFT) && indivFace > 0) indivFace--;
if (IsKeyPressed(KEY_RIGHT) && indivFace < map.data.faces.size() - 1) indivFace++;
@ -250,114 +247,37 @@ int main() {
BeginMode3D(camera);
// DrawGrid(1000, 10);
if (!indivFaceMode) {
for (int i = 0; i < map.data.vertices.size(); i++) {
// DrawPoint3D(MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[i]), BLACK);
// if (i != 0) DrawLine3D(MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[i]), MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[i - 1]), PURPLE);
}
for (int i = 0; i < map.data.edges.size(); i++) {
// DrawLine3D(MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[map.data.edges[i].vertex0]), MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[map.data.edges[i].vertex1]), PURPLE);
}
for (int i = 0; i < map.data.renderFaces.size(); i++) {
rlColor4ub(255, 255, 255, 255);
rlSetTexture(map.data.renderFaces[i].glTextureId);
for (int i = 0; i < map.data.faces.size(); i++) {
std::vector<Vector3> vertices;
for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) {
rlBegin(RL_QUADS); // for texturing reasons because rlgl
Vector3 a = map.data.renderFaces[i].vertices[0],
b = map.data.renderFaces[i].vertices[j],
c = map.data.renderFaces[i].vertices[j - 1];
Vector2 at = map.data.renderFaces[i].texCoords[0],
bt = map.data.renderFaces[i].texCoords[j],
ct = map.data.renderFaces[i].texCoords[j - 1];
// Vector3 a = MPFW::Quake::Maps::qVec2RLVec(map.data.vertices[map.data.edges[abs(map.data.ledges[map.data.faces[i].ledgeId])].vertex0]);
rlTexCoord2f(at.x, at.y);
rlVertex3f(a.x, a.y, a.z);
rlTexCoord2f(bt.x, bt.y);
rlVertex3f(b.x, b.y, b.z);
rlTexCoord2f(ct.x, ct.y);
rlVertex3f(c.x, c.y, c.z);
rlVertex3f(c.x, c.y, c.z);
for (int k = 0; k < map.data.faces[i].ledgeNum; k++) {
if (map.data.ledges[(unsigned int)(map.data.faces[i].ledgeId) + k] < 0) {
vertices.push_back(MPFW::Quake::Maps::qVec2RLVec(
map.data.vertices[
map.data.edges[
abs(
map.data.ledges[
map.data.faces[i].ledgeId + k
]
)
].vertex0
]
));
}
else {
vertices.push_back(MPFW::Quake::Maps::qVec2RLVec(
map.data.vertices[
map.data.edges[
abs(
map.data.ledges[
map.data.faces[i].ledgeId + k
]
)
].vertex1
]
));
}
/*DrawLine3D(MPFW::Quake::Maps::qVec2RLVec(
map.data.vertices[
map.data.edges[
abs(
map.data.ledges[
map.data.faces[i].ledgeId + k
]
)
].vertex0
]
),
MPFW::Quake::Maps::qVec2RLVec(
map.data.vertices[
map.data.edges[
abs(
map.data.ledges[
map.data.faces[i].ledgeId + k
]
)
].vertex1
]
), RED);*/
}
for(int j = vertices.size() - 1; j > 0; j--){
// rlColor4ub(colors[i].r, colors[i].g, colors[i].b, colors[i].a);
rlColor4ub(255, 255, 255, 255);
rlSetTexture(map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].glTextureID);
rlBegin(RL_QUADS); // textures don't work well with triangles in rlgl for some reason
// rlTexCoord2f(0, 0);
rlTexCoord2f(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[0]), map.data.texInfo[map.data.faces[i].texinfoId].vectorS) + map.data.texInfo[map.data.faces[i].texinfoId].distS) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[0]), map.data.texInfo[map.data.faces[i].texinfoId].vectorT) + map.data.texInfo[map.data.faces[i].texinfoId].distT) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].height
);
rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
// rlTexCoord2f(0, 1);
rlTexCoord2f(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[j]), map.data.texInfo[map.data.faces[i].texinfoId].vectorS) + map.data.texInfo[map.data.faces[i].texinfoId].distS) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[j]), map.data.texInfo[map.data.faces[i].texinfoId].vectorT) + map.data.texInfo[map.data.faces[i].texinfoId].distT) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].height
);
rlVertex3f(vertices[j].x, vertices[j].y, vertices[j].z);
// rlTexCoord2f(1, 1);
rlTexCoord2f(
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[j - 1]), map.data.texInfo[map.data.faces[i].texinfoId].vectorS) + map.data.texInfo[map.data.faces[i].texinfoId].distS) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].width,
(Vector3DotProduct(MPFW::Quake::Maps::RLVec2qVec(vertices[j - 1]), map.data.texInfo[map.data.faces[i].texinfoId].vectorT) + map.data.texInfo[map.data.faces[i].texinfoId].distT) / map.data.textures[map.data.texInfo[map.data.faces[i].texinfoId].textureId].height
);
rlVertex3f(vertices[j - 1].x, vertices[j - 1].y, vertices[j - 1].z);
rlVertex3f(vertices[j - 1].x, vertices[j - 1].y, vertices[j - 1].z);
rlEnd();
// rlColor4ub(255, 255, 255, 255);
}
}
}
else {