This commit is contained in:
MegaMech
2025-03-04 11:39:53 -07:00
parent 3d8367068e
commit 0d02f8c3af
10 changed files with 42 additions and 23 deletions
+5
View File
@@ -25,6 +25,11 @@ struct FVector {
return FVector(x - other.x, y - other.y, z - other.z);
}
// Operator to multiply a FVector by a scalar (float)
FVector operator*(float scalar) const {
return FVector(x * scalar, y * scalar, z * scalar);
}
float Dot(const FVector& other) const {
return x * other.x + y * other.y + z * other.z;
}
+4 -7
View File
@@ -116,8 +116,6 @@ void World::PreviousCourse() {
AActor* World::AddActor(AActor* actor) {
Actors.push_back(actor);
gEditor.AddObject((FVector*) &actor->Pos, actor->Model, 1.0f, CollisionType::VTX_INTERSECT, 0.0f);
return Actors.back();
}
@@ -132,9 +130,9 @@ struct Actor* World::AddBaseActor() {
void World::AddEditorObject(Actor* actor) {
if (actor->model != NULL) {
gEditor.AddObject((FVector*) &actor->pos, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, CollisionType::VTX_INTERSECT, 0.0f);
gEditor.AddObject((FVector*) &actor->pos, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
} else {
gEditor.AddObject((FVector*) &actor->pos, NULL, 1.0f, CollisionType::VTX_INTERSECT, 0.0f);
gEditor.AddObject((FVector*) &actor->pos, NULL, 1.0f, CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
}
}
@@ -175,12 +173,11 @@ OObject* World::AddObject(OObject* object) {
if (object->_objectIndex != -1) {
Object* cObj = &gObjectList[object->_objectIndex];
printf("model 0x%llX\n", cObj->model);
if (cObj->model != NULL) {
gEditor.AddObject((FVector*) &cObj->origin_pos[0], (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, CollisionType::VTX_INTERSECT, 0.0f);
gEditor.AddObject((FVector*) &cObj->origin_pos[0], (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
} else {
gEditor.AddObject((FVector*) &cObj->origin_pos[0], NULL, 1.0f, CollisionType::VTX_INTERSECT, 0.0f);
gEditor.AddObject((FVector*) &cObj->origin_pos[0], NULL, 1.0f, CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
}
}
-1
View File
@@ -15,7 +15,6 @@ void GenerateCollisionMesh(GameObject& object, Gfx* model, float scale) {
lo = ptr->words.w0;
hi = ptr->words.w1;
printf("w0 0x%llX 0x%llX\n", lo, hi);
opcode = (EDITOR_GFX_GET_OPCODE(lo) >> 24);
switch(opcode) {
+15 -5
View File
@@ -31,10 +31,12 @@ Editor::Editor() {
}
void Editor::Load() {
eObjectPicker.Load();
printf("Editor: Loading Editor...\n");
eObjectPicker.Load();;
for (auto& object : eGameObjects) {
GenerateCollisionMesh(object, object.Model, 1.0f);
}
printf("Editor: Loading Complete!\n");
}
void Editor::Tick() {
@@ -47,6 +49,11 @@ void Editor::Tick() {
Ship::Coords mousePos = wnd->GetMousePos();
bool isMouseDown = wnd->GetMouseState(Ship::LUS_MOUSE_BTN_LEFT);
eGameObjects.erase(
std::remove_if(eGameObjects.begin(), eGameObjects.end(),
[](const auto& object) { return (*object.DespawnFlag) == object.DespawnValue; printf("DELETED OBJ\n"); }),
eGameObjects.end());
if (isMouseDown && !wasMouseDown) {
// Mouse just pressed (Pressed state)
mouseStartPos = mousePos;
@@ -84,12 +91,15 @@ void Editor::Draw() {
eObjectPicker.Draw();
}
void Editor::AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize) {
void Editor::AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) {
if (model != NULL) {
eGameObjects.push_back({pos, model, {}, collision, boundingBoxSize});
eGameObjects.push_back({pos, model, {}, collision, boundingBoxSize, despawnFlag, despawnValue});
GenerateCollisionMesh(eGameObjects.back(), model, scale);
} else { // to bounding box or sphere collision
eGameObjects.push_back({pos, model, {}, CollisionType::BOUNDING_BOX, 22.0f});
eGameObjects.push_back({pos, model, {}, CollisionType::BOUNDING_BOX, 22.0f, despawnFlag, despawnValue});
}
}
void Editor::ClearObjects() {
eGameObjects.clear();
}
+4 -1
View File
@@ -19,7 +19,9 @@ public:
void Draw();
void MouseClick();
void Load();
void AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize);
void AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
void ClearObjects();
void RemoveObject();
private:
bool _draw = false;
Vec3f _ray;
@@ -27,4 +29,5 @@ private:
s32 Inverse(MtxF* src, MtxF* dest);
void Copy(MtxF* src, MtxF* dest);
void Clear(MtxF* mf);
};
+2
View File
@@ -28,6 +28,8 @@ struct GameObject {
std::vector<Triangle> Triangles;
CollisionType Collision;
float BoundingBoxSize;
int32_t* DespawnFlag;
int32_t DespawnValue;
};
/**
+3 -3
View File
@@ -130,13 +130,13 @@ void Gizmo::Translate() {
switch(SelectedHandle) {
case GizmoHandle::X_Axis:
_selected->Pos->x = cameras[0].pos[0] + _ray.x * length;
_selected->Pos->x = (cameras[0].pos[0] + _ray.x * length) + _cursorOffset.x;
break;
case GizmoHandle::Y_Axis:
_selected->Pos->y = cameras[0].pos[1] + _ray.y * length;
_selected->Pos->y = (cameras[0].pos[1] + _ray.y * length) + _cursorOffset.y;
break;
case GizmoHandle::Z_Axis:
_selected->Pos->z = cameras[0].pos[2] + _ray.z * length;
_selected->Pos->z = (cameras[0].pos[2] + _ray.z * length) + _cursorOffset.z;
break;
}
+3 -2
View File
@@ -39,6 +39,7 @@ public:
FVector Pos; // Global scene view
float _gizmoOffset = 5.0f;
FVector _cursorOffset;
FVector RedPos = {0, 0, -_gizmoOffset}; // Local model view
FVector GreenPos = {-_gizmoOffset, 0, 0}; // Local model view
FVector BluePos = {0, _gizmoOffset, 0}; // Local model view
@@ -514,7 +515,7 @@ Gfx handle_Cylinder_mesh_tri_0[106] = {
};
Gfx mat_handle_f3dlite_material[9] = {
gsSPClearGeometryMode(G_CLIPPING),
gsSPClearGeometryMode(G_CLIPPING | G_ZBUFFER),
gsSPSetLights1(handle_f3dlite_material_lights),
gsDPPipeSync(),
gsDPSetCombineLERP(0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT, 0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT),
@@ -524,7 +525,7 @@ Gfx mat_handle_f3dlite_material[9] = {
};
Gfx mat_revert_handle_f3dlite_material[4] = {
gsSPSetGeometryMode(G_CLIPPING),
gsSPSetGeometryMode(G_CLIPPING | G_ZBUFFER),
gsDPPipeSync(),
gsDPSetAlphaDither(G_AD_DISABLE),
gsSPEndDisplayList(),
+3 -1
View File
@@ -74,6 +74,9 @@ void ObjectPicker::DragHandle() {
//eGizmo.StartManipulation(Gizmo::GizmoHandle::X_Axis);
eGizmo.SelectedHandle = Gizmo::GizmoHandle::Z_Axis;
eGizmo._ray = ray.Direction;
FVector clickPosition = ray.Origin + ray.Direction * t;
eGizmo._cursorOffset = eGizmo.Pos - clickPosition;
return; // Stop checking objects if we selected a Gizmo handle
}
}
@@ -117,7 +120,6 @@ void ObjectPicker::FindObject(Ray ray, std::vector<GameObject>& objects) {
switch(object.Collision) {
case CollisionType::VTX_INTERSECT:
printf("vtx object\n");
for (const auto& tri : object.Triangles) {
float t;
if (IntersectRayTriangle(ray, tri, *object.Pos, t)) {
+3 -3
View File
@@ -20,15 +20,15 @@ s32 buf = -1;
void FB_CreateFramebuffers(void) {
if (gReusableFrameBuffer == -1) {
gReusableFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, true, true, true, NULL);
gReusableFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, true, true, true);
}
if (gN64ResFrameBuffer == -1) {
gN64ResFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, false, true, true, NULL);
gN64ResFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, false, true, true);
}
if (buf == -1) {
gN64ResFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, false, true, true, NULL);
gN64ResFrameBuffer = gfx_create_framebuffer(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, false, true, true);
}
}