Fix Rotator

This commit is contained in:
MegaMech
2025-03-28 19:58:35 -06:00
parent d760025358
commit a6d19eee1b
61 changed files with 277 additions and 206 deletions
+2
View File
@@ -1,6 +1,7 @@
#pragma once
#include <libultraship.h>
#include "CoreMath.h"
extern "C" {
#include "macros.h"
@@ -25,6 +26,7 @@ public:
/* 0x30 */ Collision Unk30;
uint8_t uuid[16];
const char* Name = "";
FVector Scale = {1, 1, 1};
Gfx* Model = NULL;
+51 -7
View File
@@ -112,25 +112,69 @@ typedef struct IVector2D {
#endif // __cplusplus
} IVector2D;
// IRot is an int16_t not a float.
/**
* This struct immediately converts float pitch/yaw/roll in degrees to n64 int16_t binary angles 0-0xFFFF == 0-360 degrees
* ToDegrees() Receive an FRotator of float degrees back.
* Set() Set an n64 int16_t binary angles 0-0xFFFF
*/
struct IRotator {
int16_t pitch, yaw, roll;
uint16_t pitch, yaw, roll;
#ifdef __cplusplus
IRotator& operator=(const IRotator& other) {
pitch = other.pitch;
yaw = other.yaw;
roll = other.roll;
yaw = other.yaw;
roll = other.roll;
return *this;
}
[[nodiscard]] IRotator Set(uint16_t p, uint16_t y, uint16_t r) {
pitch = p;
yaw = y;
roll = r;
}
IRotator() : pitch(0), yaw(0), roll(0) {}
IRotator(float p, float y, float r) {
pitch = p * (UINT16_MAX / 360);
yaw = y * (UINT16_MAX / 360);
roll = r * (UINT16_MAX / 360);
}
#endif // __cplusplus
};
/**
* Use IRotator unless you want to do some math in degrees.
* Always use ToBinary() or Rotator when sending into matrices or apply translation functions
* Convert from IRotator to FRotator float degrees by doing FRotator(myIRotator);
*/
struct FRotator {
float pitch, yaw, roll;
#ifdef __cplusplus
FRotator& operator=(const FRotator& other) {
pitch = other.pitch;
yaw = other.yaw;
roll = other.roll;
return *this;
}
// Convert to binary rotator 0 --> INT16_MAX
[[nodiscard]] IRotator ToBinary() const {
return IRotator(pitch * INT16_MAX / 180, yaw * INT16_MAX / 180, roll * INT16_MAX / 180);
return IRotator(
static_cast<uint16_t>(pitch * (UINT16_MAX / 360)),
static_cast<uint16_t>(yaw * (UINT16_MAX / 360)),
static_cast<uint16_t>(roll * (UINT16_MAX / 360))
);
}
IRotator() : pitch(0), yaw(0), roll(0) {}
IRotator(int16_t p, int16_t y, int16_t r) : pitch(p), yaw(y), roll(r) {}
FRotator() : pitch(0), yaw(0), roll(0) {}
FRotator(float p, float y, float r) : pitch(p), yaw(y), roll(r) {}
FRotator(IRotator rot) {
pitch = static_cast<float>(rot.pitch * (360 / UINT16_MAX));
yaw = static_cast<float>(rot.yaw * (360 / UINT16_MAX));
roll = static_cast<float>(rot.roll * (360 / UINT16_MAX));
}
#endif // __cplusplus
};
+19 -46
View File
@@ -40,8 +40,7 @@ void HarbourMastersIntro::HM_InitIntro() {
_pos = FVector(-1000, -205, -800); // -1000, -210, -800
_rot = IRotator(-5, 100, 0);
_scale = 0.7f;
_trackScale = 2.0f;
_scale = {0.7f, 0.7f, 0.7f};
_ship2Pos = FVector(300, -210, -1960);
_ship2Rot = IRotator(0, 45, 0);
@@ -53,7 +52,8 @@ void HarbourMastersIntro::HM_InitIntro() {
_rotHM64 = IRotator(0, -90, -4); // -0x2100
_hPos = FVector(-2000, 100, -4900);
_hRot = IRotator(0, 0, 0);
_hRot = IRotator(0, -45.0f, 0);
_hScale = {2.0f, 2.0f, 2.0f};
ground_f3d_material_013_lights = gdSPDefLights1(
0x7F, 0x30, 0x80,
@@ -61,15 +61,6 @@ void HarbourMastersIntro::HM_InitIntro() {
);
}
const float BOB_AMPLITUDE = 1.1f;
const float BOB_SPEED = 0.05f;
const float TILT_AMPLITUDE = 1.5f;
const float TILT_SPEED = 0.05f;
const float ROLL_AMPLITUDE = 1.0f;
const float ROLL_SPEED = 0.03f;
void HarbourMastersIntro::HM_TickIntro() {
_water += 1;
if (_water > 255) {
@@ -93,15 +84,14 @@ void HarbourMastersIntro::HM_TickIntro() {
find_and_set_tile_size((uintptr_t) ((void*)mat_water_water2), _water, 0);;
}
// @args amplitudes
void HarbourMastersIntro::Bob(FVector& pos, IRotator& rot, f32 bobAmp, f32 bobSpeed, f32 tiltAmp, f32 tiltSpeed, f32 rollAmp, f32 rollSpeed) {
float time = (float)gGlobalTimer;
pos.y = -210 + bobAmp * sin(time * bobSpeed);
rot.pitch = tiltAmp * sin(time * tiltSpeed);
rot.pitch = (tiltAmp * sin(time * tiltSpeed)) * (UINT16_MAX / 360);
rot.roll = rollAmp * sin(time * rollSpeed);
rot.roll = (rollAmp * sin(time * rollSpeed)) * (UINT16_MAX / 360);
}
void HarbourMastersIntro::SpagBob(FVector& pos, IRotator& rot, f32 bobAmp, f32 bobSpeed, f32 tiltAmp, f32 tiltSpeed, f32 rollAmp, f32 rollSpeed) {
@@ -109,54 +99,37 @@ void HarbourMastersIntro::SpagBob(FVector& pos, IRotator& rot, f32 bobAmp, f32 b
pos.y = -205 + bobAmp * sin(time * bobSpeed);
rot.pitch = -5 + tiltAmp * sin(time * tiltSpeed);
rot.pitch = (-5 + tiltAmp * sin(time * tiltSpeed)) * (UINT16_MAX / 360);
rot.roll = rollAmp * sin(time * rollSpeed);
rot.roll = (rollAmp * sin(time * rollSpeed)) * (UINT16_MAX / 360);
}
void HarbourMastersIntro::HM_DrawIntro() {
const f32 conv = 8192.0f / 45.0f; // Convert to hex degrees
Mtx* mtx = &gGfxPool->mtxObject[0];
HarbourMastersIntro::Setup();
Mat4 someMtx;
gSPMatrix(gDisplayListHead++, &gGfxPool->mtxScreen, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPMatrix(gDisplayListHead++, &gGfxPool->mtxLookAt[0], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
mtxf_identity(someMtx);
render_set_position(someMtx, 0);
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
gDPSetEnvColor(gDisplayListHead++, 0x00, 0x00, 0x00, 0x00);
Vec3f pos = {_pos.x, _pos.y, _pos.z};
Vec3s rot = {_rot.pitch * conv, _rot.yaw * conv, _rot.roll * conv};
Mat4 matrix;
mtxf_pos_rotation_xyz(matrix, pos, rot);
mtxf_scale(matrix, _scale);
render_set_position(matrix, 0);
Mat4 mtx_spaghettiShip;
ApplyMatrixTransformations(mtx_spaghettiShip, _pos, _rot, _scale);
render_set_position(mtx_spaghettiShip, 0);
gSPDisplayList(gDisplayListHead++, ship1_spag1_mesh);
Mat4 matrix2;
Vec3s rot2 = {_ship2Rot.pitch * conv, _ship2Rot.yaw * conv, _ship2Rot.roll * conv};
Vec3f pos2 = {_ship2Pos.x, _ship2Pos.y, _ship2Pos.z};
mtxf_pos_rotation_xyz(matrix2, pos2, rot2);
mtxf_scale(matrix2, _scale);
render_set_position(matrix2, 0);
Mat4 mtx_ship2;
ApplyMatrixTransformations(mtx_ship2, _ship2Pos, _ship2Rot, _scale);
render_set_position(mtx_ship2, 0);
gSPDisplayList(gDisplayListHead++, ship2_SoH_mesh);
Mat4 matrix3;
Vec3s rot3 = {_shipRot.pitch * conv, _shipRot.yaw * conv, _shipRot.roll * conv};
Vec3f pos3 = {_shipPos.x, _shipPos.y, _shipPos.z};
mtxf_pos_rotation_xyz(matrix3, pos3, rot3);
mtxf_scale(matrix3, _scale);
render_set_position(matrix3, 0);
Mat4 mtx_ship3;
ApplyMatrixTransformations(mtx_ship3, _shipPos, _shipRot, _scale);
render_set_position(mtx_ship3, 0);
gSPDisplayList(gDisplayListHead++, ship3_2Ship_mesh);
Mat4 hMatrix;
Vec3f hPos = {_hPos.x, _hPos.y, _hPos.z};
Vec3s hRot = {_hRot.pitch * conv, -0x2100, _hRot.roll * conv};
mtxf_pos_rotation_xyz(hMatrix, hPos, hRot);
mtxf_scale(hMatrix, _trackScale);
render_set_position(hMatrix, 0);
Mat4 mtx_geo;
ApplyMatrixTransformations(mtx_geo, _hPos, _hRot, _hScale);
render_set_position(mtx_geo, 0);
gSPDisplayList(gDisplayListHead++, ground_map_mesh);
gSPDisplayList(gDisplayListHead++, powered_Text_mesh);
+2 -2
View File
@@ -40,9 +40,8 @@ private:
f32 _cameraAcceleration;
FVector _pos;
f32 _scale;
f32 _trackScale;
IRotator _rot;
FVector _scale;
FVector _shipPos;
IRotator _shipRot;
@@ -57,6 +56,7 @@ private:
FVector _hPos;
IRotator _hRot;
FVector _hScale;
};
extern "C" {
+10 -6
View File
@@ -28,7 +28,7 @@ Mtx* GetMatrix(std::vector<Mtx>& stack) {
}
/**
* Use GetMatrix first
* Use GetMatrix() first
*/
void AddMatrixFixed(std::vector<Mtx>& stack, s32 flags) {
// Load the matrix
@@ -65,8 +65,6 @@ void ApplyMatrixTransformations(Mat4 mtx, FVector pos, IRotator rot, FVector sca
f32 sine2, cosine2;
f32 sine3, cosine3;
rot = rot.ToBinary();
// Compute the sine and cosine of the orientation (Euler angles)
sine1 = sins(rot.pitch);
cosine1 = coss(rot.pitch);
@@ -80,20 +78,26 @@ void ApplyMatrixTransformations(Mat4 mtx, FVector pos, IRotator rot, FVector sca
mtx[1][0] = (-cosine2 * sine3) + ((sine1 * sine2) * cosine3);
mtx[2][0] = cosine1 * sine2;
mtx[3][0] = pos.x;
mtx[0][1] = cosine1 * sine3;
mtx[1][1] = cosine1 * cosine3;
mtx[2][1] = -sine1;
mtx[3][1] = pos.y;
mtx[0][2] = (-sine2 * cosine3) + ((sine1 * cosine2) * sine3);
mtx[1][2] = (sine2 * sine3) + ((sine1 * cosine2) * cosine3);
mtx[2][2] = cosine1 * cosine2;
mtx[3][2] = pos.z;
// Apply scaling: modify the diagonal of the rotation matrix
// Apply scaling
mtx[0][0] *= scale.x;
mtx[1][0] *= scale.x;
mtx[2][0] *= scale.x;
mtx[0][1] *= scale.y;
mtx[1][1] *= scale.y;
mtx[2][1] *= scale.y;
mtx[0][2] *= scale.z;
mtx[1][2] *= scale.z;
mtx[2][2] *= scale.z;
// Set the last row and column for the homogeneous coordinate system
+1 -1
View File
@@ -40,7 +40,7 @@ public:
void from_json(const nlohmann::json& j) {
Name = j.at("Name").get<std::string>();
Pos = FVector(j.at("Position")[0].get<float>(), j.at("Position")[1].get<float>(), j.at("Position")[2].get<float>());
Rot = IRotator(j.at("Rotation")[0].get<float>(), j.at("Rotation")[1].get<float>(), j.at("Rotation")[2].get<float>());
Rot.Set(j.at("Rotation")[0].get<uint16_t>(), j.at("Rotation")[1].get<uint16_t>(), j.at("Rotation")[2].get<uint16_t>());
Scale = FVector(j.at("Scale")[0].get<float>(), j.at("Scale")[1].get<float>(), j.at("Scale")[2].get<float>());
// Deserialize the Model string
+9 -7
View File
@@ -119,9 +119,11 @@ AActor* World::AddActor(AActor* actor) {
Actors.push_back(actor);
if (actor->Model != NULL) {
gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, &actor->Rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->Model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0);
gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, (IRotator*)&actor->Rot, nullptr,
(Gfx*) LOAD_ASSET_RAW(actor->Model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT,
0.0f, (int32_t*) &actor->Type, 0);
} else {
gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, &actor->Rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0);
gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, (IRotator*)&actor->Rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0);
}
return Actors.back();
}
@@ -137,9 +139,9 @@ struct Actor* World::AddBaseActor() {
void World::AddEditorObject(Actor* actor, const char* name) {
if (actor->model != NULL) {
gEditor.AddObject(name, (FVector*) &actor->pos, &actor->rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
gEditor.AddObject(name, (FVector*) &actor->pos, (IRotator*)&actor->rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
} else {
gEditor.AddObject(name, (FVector*) &actor->pos, &actor->rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
gEditor.AddObject(name, (FVector*) &actor->pos, (IRotator*)&actor->rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0);
}
}
@@ -178,7 +180,7 @@ void World::TickActors() {
StaticMeshActor* World::AddStaticMeshActor(std::string name, FVector pos, IRotator rot, FVector scale, std::string model, int32_t* collision) {
StaticMeshActors.push_back(new StaticMeshActor(name, pos, rot, scale, model, collision));
auto actor = StaticMeshActors.back();
gEditor.AddObject(actor->Name.c_str(), &actor->Pos, (Vec3s*) &actor->Rot, &actor->Scale, (Gfx*) LOAD_ASSET_RAW(actor->Model.c_str()), 1.0f,
auto gameObj = gEditor.AddObject(actor->Name.c_str(), &actor->Pos, &actor->Rot, &actor->Scale, (Gfx*) LOAD_ASSET_RAW(actor->Model.c_str()), 1.0f,
Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*) &actor->bPendingDestroy, (int32_t) true);
return actor;
}
@@ -207,9 +209,9 @@ OObject* World::AddObject(OObject* object) {
Object* cObj = &gObjectList[object->_objectIndex];
if (cObj->model != NULL) {
gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (Vec3s*)&cObj->orientation, nullptr, (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (IRotator*)&cObj->orientation, nullptr, (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
} else {
gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (Vec3s*)&cObj->orientation, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (IRotator*)&cObj->orientation, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1);
}
}
+6 -5
View File
@@ -2,6 +2,7 @@
#include <libultra/gbi.h>
#include "CoreMath.h"
#include "Matrix.h"
extern "C" {
#include "common_structs.h"
@@ -15,6 +16,10 @@ extern "C" {
AShip::AShip(FVector pos, AShip::Skin skin) {
Spawn = pos;
Spawn.y += 10;
Pos[0] = pos.x;
Pos[1] = pos.y;
Pos[2] = pos.z;
Scale = FVector(0.4, 0.4, 0.4);
switch(skin) {
case GHOSTSHIP:
@@ -49,15 +54,11 @@ void AShip::Tick() {
void AShip::Draw(Camera *camera) {
Mat4 shipMtx;
Vec3f hullPos = {Pos.x, Pos.y, Pos.z};
//Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll};
gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
IRotator rot = Rot.ToBinary();
mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*) &Rot);
mtxf_scale(shipMtx, 0.4);
ApplyMatrixTransformations(shipMtx, *(FVector*)Pos, *(IRotator*)Rot, Scale);
if (render_set_position(shipMtx, 0) != 0) {
gSPDisplayList(gDisplayListHead++, _skin);
}
+3 -2
View File
@@ -27,8 +27,9 @@ public:
virtual bool IsMod() override;
FVector Spawn;
FVector Pos;
IRotator Rot = {0, 0, 0};
//FVector Pos;
///IRotator Rot = {0, 0, 0};
//FVector Scale = {0.4, 0.4, 0.4};
private:
Gfx* _skin;
};
+1 -3
View File
@@ -44,9 +44,7 @@ void ASpaghettiShip::Draw(Camera *camera) {
gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
// empty/null mtx as a base
IRotator iRot = Rot.ToBinary();
mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*)&iRot);
mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*)&Rot);
mtxf_scale(shipMtx, 0.4);
if (render_set_position(shipMtx, 0) != 0) {}
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "GameObject.h"
+3 -2
View File
@@ -1,4 +1,4 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "../CoreMath.h"
#include <libultra/types.h>
@@ -99,7 +99,7 @@ namespace Editor {
}
}
void Editor::AddObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) {
GameObject* Editor::AddObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) {
//printf("After AddObj: Pos(%f, %f, %f), Name: %s, Model: %s\n",
// pos->x, pos->y, pos->z, name, model);
if (model != nullptr) {
@@ -109,6 +109,7 @@ namespace Editor {
eGameObjects.push_back(new GameObject(name, pos, rot, scale, model, {}, GameObject::CollisionType::BOUNDING_BOX,
22.0f, despawnFlag, despawnValue));
}
return eGameObjects.back();
}
void Editor::AddLight(const char* name, FVector* pos, s8* rot) {
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef __EDITOR_H__
#define __EDITOR_H__
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "GameObject.h"
@@ -21,7 +21,7 @@ public:
void Tick();
void Draw();
void Load();
void AddObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
GameObject* AddObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
void AddLight(const char* name, FVector* pos, s8* rot);
void ClearObjects();
void RemoveObject();
+6 -4
View File
@@ -1,6 +1,6 @@
#include "EditorMath.h"
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include "port/Game.h"
#include "port/Engine.h"
#include <libultra/types.h>
@@ -323,9 +323,11 @@ float CalculateAngle(const FVector& start, const FVector& end) {
return acos(cosAngle);
}
void SetDirectionFromRotator(s16 rotator[3], s8 direction[3]) {
float yaw = rotator[1] * (M_PI / 32768.0f); // Convert from s16 (0 to 32767) to radians
float pitch = rotator[0] * (M_PI / 32768.0f);
// Used for gSPLights1
void SetDirectionFromRotator(IRotator rot, s8 direction[3]) {
// Subtract 0x4000 to lineup the rotator with the light direction
float yaw = (rot.yaw - 0x4000) * (M_PI / 32768.0f); // Convert from n64 binary angles 0-0xFFFF 0-360 degrees to radians
float pitch = rot.pitch * (M_PI / 32768.0f);
// Compute unit direction vector
float x = cosf(yaw) * cosf(pitch);
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include <libultra/types.h>
#include "../CoreMath.h"
@@ -44,5 +44,5 @@ bool IntersectRaySphere(const Ray& ray, const FVector& sphereCenter, float radiu
void Editor_AddMatrix(Mat4 mtx, int32_t flags);
float CalculateAngle(const FVector& start, const FVector& end);
void SetDirectionFromRotator(s16 rotator[3], s8 direction[3]);
void SetDirectionFromRotator(IRotator rot, s8 direction[3]);
FVector GetPositionAheadOfCamera(f32 dist);
+2 -2
View File
@@ -1,9 +1,9 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include "GameObject.h"
namespace Editor {
GameObject::GameObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, std::vector<Triangle> triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) {
GameObject::GameObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, std::vector<Triangle> triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) {
Name = name;
Pos = pos;
Rot = rot;
+3 -3
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include <libultra/types.h>
#include "../CoreMath.h"
@@ -22,7 +22,7 @@ public:
BOUNDING_SPHERE
};
GameObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, std::vector<Triangle> triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
GameObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, std::vector<Triangle> triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
GameObject(FVector* pos, Vec3s* rot);
GameObject();
virtual void Tick();
@@ -31,7 +31,7 @@ public:
const char* Name;
FVector* Pos;
Vec3s* Rot;
IRotator* Rot;
FVector* Scale;
Gfx* Model;
std::vector<Triangle> Triangles;
+7 -7
View File
@@ -1,4 +1,4 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "../CoreMath.h"
#include <libultra/types.h>
@@ -173,21 +173,21 @@ void Gizmo::Rotate() {
float angle = CalculateAngle(_cursorOffset, cameraPos) * 100;
// printf("start %f %f %f end %f %f %f angle %f\n", _cursorOffset.x, _cursorOffset.y, _cursorOffset.z, cameraPos.x, cameraPos.y, cameraPos.z, angle);
// printf("start %f %f %f end %f %f %f angle %f\n", _cursorOffset.x, _cursorOffset.y, _cursorOffset.z, cameraPos.x, cameraPos.y, cameraPos.z, angle);
// Depending on which axis or handle you want to rotate, apply rotation.
switch(SelectedHandle) {
case GizmoHandle::All_Axis:
(*_selected->Rot)[0] = static_cast<short>((s16)((*_selected->Rot)[0] + angle) & 0xFFFF); // Wrap to 0xFFFF
(*_selected->Rot)[1] = static_cast<short>((s16)((*_selected->Rot)[1] + angle) & 0xFFFF); // Wrap to 0xFFFF
_selected->Rot->pitch = _selected->Rot->pitch + angle;
_selected->Rot->yaw = _selected->Rot->yaw + angle;
break;
case GizmoHandle::X_Axis:
(*_selected->Rot)[0] = static_cast<short>((s16)((*_selected->Rot)[0] + angle) & 0xFFFF); // Wrap to 0xFFFF
_selected->Rot->pitch = _selected->Rot->pitch + angle;
break;
case GizmoHandle::Y_Axis:
(*_selected->Rot)[1] = static_cast<short>((s16)((*_selected->Rot)[1] + angle) & 0xFFFF); // Wrap to 0xFFFF
_selected->Rot->yaw = _selected->Rot->yaw + angle;
break;
case GizmoHandle::Z_Axis:
(*_selected->Rot)[2] = static_cast<short>((s16)((*_selected->Rot)[2] + angle) & 0xFFFF); // Wrap to 0xFFFF
_selected->Rot->roll = _selected->Rot->roll + angle;
break;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "Collision.h"
#include "GameObject.h"
+1 -1
View File
@@ -1,4 +1,4 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "Handle.h"
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
extern Gfx handle_Cylinder_mesh[];
+6 -16
View File
@@ -1,5 +1,5 @@
#include <iostream>
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "../CoreMath.h"
#include <libultra/types.h>
@@ -33,41 +33,31 @@ size_t LightObject::NumLights = 0;
LightObject::LightObject(const char* name, FVector* pos, s8* direction) : GameObject(nullptr, nullptr) {
Name = name;
// If pos is nullptr, allocate memory, otherwise assign pos
// if (pos != nullptr) {
// Pos = pos;
// }
Pos = &LightPos;
Rot = &LightRot;
Scale = &LightScale;
// Pos = &LightPos;
DespawnFlag = &_despawnFlag;
DespawnValue = -1;
Direction = direction;
Collision = CollisionType::BOUNDING_BOX;
BoundingBoxSize = 4.0f;
NumLights += 1;
}
void LightObject::Load() {
//Pos = &LightPos;
}
void LightObject::Tick() {
//Pos = &LightPos;
SetDirectionFromRotator(*Rot, Direction);
//Direction[0] = static_cast<char>(((*Rot)[0] / 256 - 128) & 0xFF);
//Direction[1] = static_cast<char>(((*Rot)[1] / 256 - 128) & 0xFF);
//Direction[2] = static_cast<char>(((*Rot)[2] / 256 - 128) & 0xFF);
//printf("Light rot %d %d %d %d %d %d\n", Direction[0], Direction[1], Direction[2], (*Rot)[0], (*Rot)[1], (*Rot)[2]);
}
void LightObject::Draw() {
Mat4 mtx;
Vec3f pos = {Pos->x, Pos->y, Pos->z};
Vec3s rot = {(*Rot)[0], (*Rot)[1] + 0x4000, (*Rot)[2]};
mtxf_pos_rotation_xyz(mtx, pos, rot);
mtxf_scale(mtx, 0.3);
ApplyMatrixTransformations(mtx, LightPos, LightRot, LightScale);
Editor_AddMatrix(mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(gDisplayListHead++, sun_LightModel_mesh);
gSPDisplayList(gDisplayListHead++, handle_Cylinder_mesh);
+3 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "Collision.h"
#include "Gizmo.h"
@@ -18,8 +18,9 @@ public:
static size_t NumLights;
FVector LightPos = FVector(0, 100, 0);
IRotator LightRot = IRotator(0, 0, 0);
FVector LightScale = FVector(0.1, 0.1, 0.1);
s8* Direction;
Vec3s LightRot = {0, 0, 0};
s32 _despawnFlag = 0;
u8 sun_sun_rgba32[16384] = {
+1 -1
View File
@@ -1,4 +1,4 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "../CoreMath.h"
#include <libultra/types.h>
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "Collision.h"
#include "Gizmo.h"
+4 -4
View File
@@ -95,10 +95,10 @@ namespace Editor {
gWorldInstance.StaticMeshActors.push_back(new StaticMeshActor("", FVector(0, 0, 0), IRotator(0, 0, 0), FVector(1, 1, 1), "", nullptr));
auto actor = gWorldInstance.StaticMeshActors.back();
actor->from_json(actorJson);
printf("After from_json: Pos(%f, %f, %f), Name: %s, Model: %s\n",
actor->Pos.x, actor->Pos.y, actor->Pos.z, actor->Name.c_str(), actor->Model.c_str());
gEditor.AddObject(actor->Name.c_str(), &actor->Pos, (Vec3s*)&actor->Rot, &actor->Scale, (Gfx*) nullptr, 1.0f,
printf("After from_json: Pos(%f, %f, %f), Name: %s, Model: %s\n",
actor->Pos.x, actor->Pos.y, actor->Pos.z, actor->Name.c_str(), actor->Model.c_str());
gEditor.AddObject(actor->Name.c_str(), &actor->Pos, &actor->Rot, &actor->Scale, (Gfx*) nullptr, 1.0f,
GameObject::CollisionType::BOUNDING_BOX, 20.0f, (int32_t*) &actor->bPendingDestroy, (int32_t) 1);
}
+1 -1
View File
@@ -1,4 +1,4 @@
#include <libultraship.h>
#include <libultraship/libultraship.h>
#include "Course.h"
namespace Editor {
+8 -3
View File
@@ -256,7 +256,6 @@ void GameEngine::StartFrame() const {
default:
break;
}
this->context->GetWindow()->StartFrame();
}
// void GameEngine::ProcessFrame(void (*run_one_game_iter)()) const {
@@ -265,13 +264,19 @@ void GameEngine::StartFrame() const {
// }
void GameEngine::RunCommands(Gfx* Commands) {
gfx_run(Commands, {});
gfx_end_frame();
auto wnd = std::dynamic_pointer_cast<Fast::Fast3dWindow>(Ship::Context::GetInstance()->GetWindow());
if (ShouldClearTextureCacheAtEndOfFrame) {
gfx_texture_cache_clear();
ShouldClearTextureCacheAtEndOfFrame = false;
}
if (nullptr == wnd) {
return;
}
wnd->HandleEvents();
wnd->DrawAndRunGraphicsCommands(Commands, {});
}
void GameEngine::ProcessGfxCommands(Gfx* commands) {
+1
View File
@@ -17,6 +17,7 @@ extern s32 gTrophyIndex;
#ifdef __cplusplus
extern Editor::Editor gEditor;
extern HarbourMastersIntro gMenuIntro;
#endif
Properties* CM_GetProps();
+5 -1
View File
@@ -82,6 +82,9 @@ namespace Ship {
ImGuiID bottomId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Down, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f));
ImGuiID bottomLeftId = ImGui::DockBuilderSplitNode(bottomId, ImGuiDir_Left, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f));
ImGuiID rightId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Right, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(rightId, ImVec2(viewport->Size.x * 0.15f, viewport->Size.y));
@@ -91,10 +94,11 @@ namespace Ship {
ImGuiID rightBottomId = ImGui::DockBuilderSplitNode(rightId, ImGuiDir_Down, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(rightBottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.25));
ImGui::DockBuilderDockWindow("Properties", rightBottomId);
ImGui::DockBuilderDockWindow("Tools", topId);
ImGui::DockBuilderDockWindow("Content Browser", bottomId);
ImGui::DockBuilderDockWindow("File Explorer", bottomLeftId);
ImGui::DockBuilderFinish(dockId);
}
@@ -5,12 +5,14 @@
#include <common_structs.h>
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryActorSpawnDataV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryActorSpawnDataV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto section = std::make_shared<ActorSpawn>(file->InitData);
auto section = std::make_shared<ActorSpawn>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryActorSpawnDataV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
+3 -3
View File
@@ -4,12 +4,12 @@
#include "graphic/Fast3D/lus_gbi.h"
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file, std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto array = std::make_shared<Array>(file->InitData);
auto array = std::make_shared<Array>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
array->ArrayType = (ArrayResourceType) reader->ReadUInt32();
+1 -1
View File
@@ -6,6 +6,6 @@
namespace MK64 {
class ResourceFactoryBinaryArrayV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file, std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
@@ -4,12 +4,14 @@
#include "resourcebridge.h"
#include "ResourceUtil.h"
std::shared_ptr<Ship::IResource> SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
std::shared_ptr<AudioBank> bank = std::make_shared<AudioBank>(file->InitData);
std::shared_ptr<AudioBank> bank = std::make_shared<AudioBank>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint8_t bankId = reader->ReadUInt32();
@@ -6,6 +6,7 @@
namespace SM64 {
class AudioBankFactoryV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}
@@ -3,12 +3,14 @@
#include "../type/AudioSample.h"
#include "spdlog/spdlog.h"
std::shared_ptr<Ship::IResource> SM64::AudioSampleFactoryV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
SM64::AudioSampleFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
std::shared_ptr<AudioSample> bank = std::make_shared<AudioSample>(file->InitData);
std::shared_ptr<AudioSample> bank = std::make_shared<AudioSample>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
bank->loop.start = reader->ReadUInt32();
@@ -6,6 +6,7 @@
namespace SM64 {
class AudioSampleFactoryV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}
@@ -4,12 +4,14 @@
#include "spdlog/spdlog.h"
#include "port/Engine.h"
std::shared_ptr<Ship::IResource> SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
std::shared_ptr<AudioSequence> bank = std::make_shared<AudioSequence>(file->InitData);
std::shared_ptr<AudioSequence> bank = std::make_shared<AudioSequence>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint8_t id = reader->ReadUInt32();
@@ -7,6 +7,7 @@
namespace SM64 {
class AudioSequenceFactoryV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}
@@ -4,12 +4,14 @@
#include "libultraship/libultra/gbi.h"
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryCourseVtxV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryCourseVtxV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto cvtx = std::make_shared<CourseVtxClass>(file->InitData);
auto cvtx = std::make_shared<CourseVtxClass>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryCourseVtxV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
@@ -3,12 +3,14 @@
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryGenericArrayV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryGenericArrayV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto arr = std::make_shared<GenericArray>(file->InitData);
auto arr = std::make_shared<GenericArray>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
auto type = reader->ReadUInt32();
@@ -6,6 +6,7 @@
namespace SF64 {
class ResourceFactoryBinaryGenericArrayV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}; // namespace SF64
@@ -4,12 +4,14 @@
#include "libultraship/libultra/gbi.h"
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryKartAIV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryKartAIV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto ai = std::make_shared<KartAI>(file->InitData);
auto ai = std::make_shared<KartAI>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
+2 -1
View File
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryKartAIV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
@@ -9,12 +9,14 @@ void* segmented_uintptr_t_to_virtual(uintptr_t);
}
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryTrackSectionsV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryTrackSectionsV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto section = std::make_shared<TrackSectionsClass>(file->InitData);
auto section = std::make_shared<TrackSectionsClass>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryTrackSectionsV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
@@ -4,12 +4,14 @@
#include "libultraship/libultra/gbi.h"
namespace MK64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto section = std::make_shared<TrackWaypoints>(file->InitData);
auto section = std::make_shared<TrackWaypoints>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryTrackWaypointsV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
@@ -6,12 +6,13 @@
namespace MK64 {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryUnkActorSpawnDataV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
ResourceFactoryBinaryUnkActorSpawnDataV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto section = std::make_shared<UnkActorSpawn>(file->InitData);
auto section = std::make_shared<UnkActorSpawn>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
@@ -6,7 +6,8 @@
namespace MK64 {
class ResourceFactoryBinaryUnkActorSpawnDataV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
+5 -3
View File
@@ -3,12 +3,14 @@
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryVec3fV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryVec3fV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto vec = std::make_shared<Vec3fArray>(file->InitData);
auto vec = std::make_shared<Vec3fArray>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
auto vecCount = reader->ReadUInt32();
+2 -1
View File
@@ -6,6 +6,7 @@
namespace SF64 {
class ResourceFactoryBinaryVec3fV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}; // namespace SF64
+5 -3
View File
@@ -3,12 +3,14 @@
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryVec3sV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryVec3sV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
auto vec = std::make_shared<Vec3sArray>(file->InitData);
auto vec = std::make_shared<Vec3sArray>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
auto vecCount = reader->ReadUInt32();
+2 -1
View File
@@ -6,6 +6,7 @@
namespace SF64 {
class ResourceFactoryBinaryVec3sV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
}; // namespace SF64
+20 -16
View File
@@ -26,13 +26,6 @@ namespace Editor {
}
void ContentBrowserWindow::DrawElement() {
static bool actorContent = false;
static bool objectContent = false;
static bool customContent = false;
static bool trackContent = false;
if (ImGui::Button(ICON_FA_REFRESH)) {
Refresh = true;
}
@@ -49,31 +42,40 @@ namespace Editor {
return;
}
ContentBrowserWindow::FolderButton("Tracks", trackContent);
ContentBrowserWindow::FolderButton("Actors", actorContent);
ContentBrowserWindow::FolderButton("Objects", objectContent);
ContentBrowserWindow::FolderButton("Custom", customContent);
ImGui::BeginChild("LeftPanel", ImVec2(120, 0), true, ImGuiWindowFlags_None);
if (trackContent) {
ContentBrowserWindow::FolderButton("Tracks", TrackContent);
ContentBrowserWindow::FolderButton("Actors", ActorContent);
ContentBrowserWindow::FolderButton("Objects", ObjectContent);
ContentBrowserWindow::FolderButton("Custom", CustomContent);
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("RightPanel", ImVec2(0, 0), true, ImGuiWindowFlags_None);
if (TrackContent) {
AddTrackContent();
}
if (actorContent) {
if (ActorContent) {
AddActorContent();
}
if (objectContent) {
if (ObjectContent) {
AddObjectContent();
}
if (customContent) {
if (CustomContent) {
AddCustomContent();
}
ImGui::EndChild();
}
void ContentBrowserWindow::FolderButton(const char* label, bool& contentFlag, const ImVec2& size) {
std::string buttonText = fmt::format("{0} {1}", contentFlag ? ICON_FA_FOLDER_OPEN_O : ICON_FA_FOLDER_O, label);
if (ImGui::Button(buttonText.c_str(), size)) {
TrackContent = false;
ActorContent = false;
ObjectContent = false;
CustomContent = false;
contentFlag = !contentFlag;
}
}
@@ -189,6 +191,8 @@ namespace Editor {
}
void ContentBrowserWindow::AddCustomContent() {
FVector pos = GetPositionAheadOfCamera(300.0f);
size_t i_custom = 0;
for (const auto& file : Content) {
if ((i_custom != 0) && (i_custom % 10 == 0)) {
@@ -201,7 +205,7 @@ namespace Editor {
int coll;
//printf("ContentBrowser.cpp: name: %s\n", test.c_str());
std::string name = file.substr(file.find_last_of('/') + 1);
auto actor = gWorldInstance.AddStaticMeshActor(name, FVector(50, 100, 0), IRotator(0, 90, 0), FVector(1, 1, 1), "__OTR__" + file, &coll);
auto actor = gWorldInstance.AddStaticMeshActor(name, FVector(pos), IRotator(0, 0, 0), FVector(1, 1, 1), "__OTR__" + file, &coll);
// This is required because ptr gets cleaned up.
actor->Model = "__OTR__" + file;
+5
View File
@@ -14,6 +14,11 @@ public:
std::unordered_map<std::string, std::string> TrackPath;
bool Refresh = true;
bool ActorContent = false;
bool ObjectContent = false;
bool CustomContent = false;
bool TrackContent = false;
protected:
void InitElement() override {};
void DrawElement() override;
+1
View File
@@ -13,6 +13,7 @@
#include "engine/editor/Editor.h"
#include "port/Game.h"
#include "src/engine/World.h"
namespace Editor {
+1 -1
View File
@@ -263,7 +263,7 @@ bool Checkbox(const char* _label, bool* value, const CheckboxOptions& options) {
: ImGuiCol_FrameBg),
true, style.FrameRounding);
ImU32 check_col = ImGui::GetColorU32(ImGuiCol_CheckMark);
bool mixed_value = (g.LastItemData.InFlags & ImGuiItemFlags_MixedValue) != 0;
bool mixed_value = (g.LastItemData.ItemFlags & ImGuiItemFlags_MixedValue) != 0;
if (mixed_value) {
// Undocumented tristate/mixed/indeterminate checkbox (#2644)
// This may seem awkwardly designed because the aim is to make ImGuiItemFlags_MixedValue supported by all
-3
View File
@@ -96,9 +96,6 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name
return PFS_NO_ERROR;
}
void osSetTime(OSTime time) {
}
s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern) {
}