Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo1301 committed Dec 7, 2024
1 parent d8469fe commit d89df55
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 18 deletions.
5 changes: 4 additions & 1 deletion GiroflexVSL/LightGroupRotateObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ struct LightGroupRotateObject {
bool rotateAlways = false;
float speed = 5.0f;
eRotateObjectAxis axis = eRotateObjectAxis::Z;
bool flipForward = false;
std::string object = "[none]";
float directionFix = 0.0f;

RwMatrix* matrix = NULL;
float totalAngle = 0.0f;
float roll = 0.0f;
};
4 changes: 2 additions & 2 deletions GiroflexVSL/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Point {
rotateObjectValue["object"] = rotateObject.object;
rotateObjectValue["axis"] = (int)rotateObject.axis;
rotateObjectValue["rotateAlways"] = rotateObject.rotateAlways;
rotateObjectValue["flipForward"] = rotateObject.flipForward;
rotateObjectValue["directionFix"] = rotateObject.directionFix;
value["rotateObject"] = rotateObjectValue;


Expand All @@ -59,7 +59,7 @@ class Point {
rotateObject.object = ValidateValue(rotateObjectValue["object"], rotateObject.object).asString();
rotateObject.axis = (eRotateObjectAxis)ValidateValue(rotateObjectValue["axis"], (int)rotateObject.axis).asInt();
rotateObject.rotateAlways = ValidateValue(rotateObjectValue["rotateAlways"], rotateObject.rotateAlways).asBool();
rotateObject.flipForward = ValidateValue(rotateObjectValue["flipForward"], rotateObject.flipForward).asBool();
rotateObject.directionFix = ValidateValue(rotateObjectValue["directionFix"], rotateObject.directionFix).asFloat();
}
}

Expand Down
168 changes: 155 additions & 13 deletions GiroflexVSL/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ extern IMenuVSL* menuVSL;
extern void* (*GetVehicleFromRef)(int);
extern RwMatrix* (*RwMatrixRotate)(RwMatrix* matrix, const RwV3d* axis, RwReal angle, RwOpCombineType combineOp);
extern RwMatrix* (*RwMatrixTranslate)(RwMatrix* matrix, const RwV3d* translation, RwOpCombineType combineOp);
extern RwMatrix* (*RwMatrixMultiply)(RwMatrix* matrixOut, const RwMatrix* MatrixIn1, const RwMatrix* matrixIn2);

extern void (*RegisterCorona)(unsigned int id, void* attachTo, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, CVector const& posn, float radius, float farClip, int coronaType, int flaretype, bool enableReflection, bool checkObstacles, int _param_not_used, float angle, bool longDistance, float nearClip, unsigned char fadeState, float fadeSpeed, bool onlyFromBelow, bool reflectionDelay);

static std::list<std::pair<unsigned int *, unsigned int>> resetEntries;

int Vehicle::m_LightIdOffset = 1000;
bool Vehicle::m_ShowRotatePointDirection = false;

int LightIdOffset = 10000;

const double TO_RADIANS = M_PI / 180.0;

float GetIntensityFromAngle(float angle)
{
if (angle > M_PI/2)
Expand Down Expand Up @@ -410,30 +414,49 @@ void Vehicle::UpdateLightGroups(int dt)

//RegisterTestCorona2(lightId++, coronaOffset, CRGBA(0, 255, 0), 2.0f);

auto coronaWorldPosition = TransformFromObjectSpace(pVehicle, coronaOffset);

auto carForward = CMatrixGetForward(pVehicle->m_matrix);

//roll

auto roll = point->rotateObject.roll + point->rotateObject.directionFix;

//

auto newDir = RotateVectorAroundZ(carForward, roll);

auto objectMatPos = point->rotateObject.matrix->pos;
auto objectPosition = CVector(objectMatPos.x, objectMatPos.y, objectMatPos.z);
auto objectWorldPosition = TransformFromObjectSpace(pVehicle, objectPosition);
auto coronaForwardedPosition = coronaWorldPosition + newDir;

auto flipForward = point->rotateObject.flipForward;
// ------------------

auto forwardPosition = objectWorldPosition + TransformFromMatrixSpace(point->rotateObject.matrix, CVector(0, flipForward ? -1 : 1, 0));
auto cameraPosition = camera->m_matrix->pos;

auto vec1 = forwardPosition;
auto vec1 = coronaForwardedPosition;
vec1.z = coronaWorldPosition.z;

auto vec2 = objectWorldPosition;
auto vec2 = coronaWorldPosition;

auto vec3 = cameraPosition;
vec3.z = coronaWorldPosition.z;

// pos Z is ignored :)
auto angle = GetAngleBetweenVectors(vec1, vec2, vec3);

float intensity = GetIntensityFromAngle(angle);

if(hVehicle == Globals::hPlayerVehicle)
//if vehicle is the player's
{
// menuVSL->debug->visible = true;
//menuVSL->debug->visible = true;
//menuVSL->debug->AddLine("roll: " + std::to_string(point->rotateObject.roll));

//RegisterDebugCorona(lightId++, vec1, CRGBA(255, 0, 0));
//RegisterDebugCorona(lightId++, vec2, CRGBA(0, 255, 0));
//RegisterDebugCorona(lightId++, vec3, CRGBA(0, 0, 255));

//menuVSL->debug->AddLine("forward: " + CVectorToString(newDir));


// menuVSL->debug->AddLine("angle: " + std::to_string(angle));
// menuVSL->debug->AddLine("forward: " + CVectorToString(vec1));
// menuVSL->debug->AddLine("objectPos: " + CVectorToString(objectWorldPosition));
Expand Down Expand Up @@ -514,9 +537,123 @@ void Vehicle::UpdateLightGroups(int dt)
}
}

/*
doest work
*/
void Vehicle::RegisterDebugCorona(int lightId, CVector worldPostion, CRGBA color)
{
RenderCorona corona2;
corona2.car = 0;
corona2.pVehicle = NULL;
corona2.id = lightId;
corona2.color = color;
corona2.offset = worldPostion;
corona2.radius = 1.0f;
corona2.nearClip = 0.1f;
corona2.coronaTexture = 0;
Vehicles::AddCoronaToRender(corona2);
}

void Vehicle::OnUpdateGameLogic()
{

auto lightId = hVehicle + 5000;

auto testpos = TransformFromObjectSpace(pVehicle, CVector(0, 0, 3));

//RegisterTestCorona(lightId++, testpos, CRGBA(0, 255, 0), 2.0f);

if (!ModelInfos::HasModelInfo(modelId)) return;

auto modelInfo = ModelInfos::GetModelInfo(modelId);

for (auto lightGroup : modelInfo->lightGroups)
{
LightGroupData* lightGroupData = LightGroupDatas::GetLightGroupData(lightGroup, hVehicle);

if (!lightGroupData)
{
continue;
}

for (int i = 0; i < (int)lightGroup->points.size(); i++)
{
auto point = lightGroup->points[i];

auto amountOfPoints = lightGroup->points.size();
auto distance = lightGroup->distance;
auto curve = lightGroup->curve;

//position
float x = (i * distance) - ((amountOfPoints - 1) * distance / 2);
float y = (float)arch_fn_parabola((float)i, curve, (float)(amountOfPoints - 1));

//rotate position
if(lightGroup->rotate)
{
auto angle = lightGroup->rotateAngle;

x += std::sin(angle) * lightGroup->rotateDistance * (lightGroup->rotateInverse ? -1 : 1);
y += std::cos(angle) * lightGroup->rotateDistance;
}

auto coronaOffset = CVector(x, y, 0) + lightGroup->offset + point->customOffset;

auto radius = lightGroup->radius;

if(hVehicle == Globals::hPlayerVehicle)
{
//menuVSL->debug->m_Visible = true;
//menuVSL->debug->AddLine("angle: " + std::to_string(angle));
//menuVSL->debug->AddLine("x: " + std::to_string(coronaOffsetX));
}

if(point->rotateObject.rotate && point->rotateObject.matrix != NULL)
{
auto coronaWorldPosition = TransformFromObjectSpace(pVehicle, coronaOffset);

auto carForward = CMatrixGetForward(pVehicle->m_matrix);

//roll

auto roll = point->rotateObject.roll + point->rotateObject.directionFix;

//

auto newDir = RotateVectorAroundZ(carForward, roll);

auto coronaForwardedPosition = coronaWorldPosition + newDir;

// ------------------

auto cameraPosition = camera->m_matrix->pos;

auto vec1 = coronaForwardedPosition;
vec1.z = coronaWorldPosition.z;

auto vec2 = coronaWorldPosition;

auto vec3 = cameraPosition;
vec3.z = coronaWorldPosition.z;

// pos Z is ignored :)
auto angle = GetAngleBetweenVectors(vec1, vec2, vec3);

float intensity = GetIntensityFromAngle(angle);

if(m_ShowRotatePointDirection)
{
//menuVSL->debug->visible = true;
//menuVSL->debug->AddLine("roll: " + std::to_string(point->rotateObject.roll));

RegisterTestCorona(lightId++, vec1, CRGBA(255, 0, 0), 1.0f);
//RegisterTestCorona(lightId++, vec2, CRGBA(0, 255, 0), 1.0f);
RegisterTestCorona(lightId++, vec3, CRGBA(0, 0, 255), 1.0f);
}

radius *= intensity;
}
}
}
}

void Vehicle::RenderBefore()
Expand Down Expand Up @@ -588,8 +725,11 @@ void Vehicle::RenderBefore()
};
RwReal angle = point->rotateObject.speed;


RwMatrixRotate(&frameAtomic->modelling, &axis, angle, rwCOMBINEPRECONCAT);

point->rotateObject.totalAngle += angle;

//by chatGPT

float yaw, pitch, roll;
Expand All @@ -609,13 +749,15 @@ void Vehicle::RenderBefore()
roll = atan2f(-frameAtomic->modelling.up.y, frameAtomic->modelling.right.y);
}

point->rotateObject.roll = roll;

point->rotateObject.matrix = &frameAtomic->modelling;

if(hVehicle == Globals::hPlayerVehicle)
{
// menuVSL->debug->visible = true;
// menuVSL->debug->AddLine("roll: " + std::to_string(roll));
// menuVSL->debug->AddLine("matrix: " + std::to_string((int)point->rotateObject.matrix));
//menuVSL->debug->visible = true;
//menuVSL->debug->AddLine("roll: " + std::to_string(roll));
//menuVSL->debug->AddLine("matrix: " + std::to_string((int)point->rotateObject.matrix));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions GiroflexVSL/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Vehicle {
public:
static int m_LightIdOffset;
static bool m_ShowRotatePointDirection;

int hVehicle;
int modelId;
Expand Down Expand Up @@ -36,6 +37,9 @@ class Vehicle {
void Destroy();
void Update(int dt);
void UpdateLightGroups(int dt);

void RegisterDebugCorona(int lightId, CVector worldPostion, CRGBA color);

void OnUpdateGameLogic();

void RenderBefore();
Expand Down
4 changes: 3 additions & 1 deletion GiroflexVSL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ RwReal (*RwV3dNormalize)(RwV3d* out, const RwV3d* in);
void (*CMatrix_CopyToRwMatrix)(CMatrix*, RwMatrix *matrix);
RwMatrix* (*RwMatrixCreate)(void);
RwBool (*RwMatrixDestroy)(RwMatrix* mpMat);
RwMatrix* (*RwMatrixMultiply)(RwMatrix* matrixOut, const RwMatrix* MatrixIn1, const RwMatrix* matrixIn2);

void (*CFont_PrintString)(float x, float y, unsigned short* text);
void (*AsciiToGxtChar)(const char* txt, unsigned short* ret);
Expand Down Expand Up @@ -332,7 +333,8 @@ void LoadSymbols()
SET_TO(CMatrix_CopyToRwMatrix, aml->GetSym(hGTASA, "_ZNK7CMatrix14CopyToRwMatrixEP11RwMatrixTag"));
SET_TO(RwMatrixCreate, aml->GetSym(hGTASA, "_Z14RwMatrixCreatev"));
SET_TO(RwMatrixDestroy, aml->GetSym(hGTASA, "_Z15RwMatrixDestroyP11RwMatrixTag"));

SET_TO(RwMatrixMultiply, aml->GetSym(hGTASA, "_Z16RwMatrixMultiplyP11RwMatrixTagPKS_S2_"));

SET_TO(CFont_PrintString, aml->GetSym(hGTASA, "_ZN5CFont11PrintStringEffPt"));
SET_TO(AsciiToGxtChar, aml->GetSym(hGTASA, "_Z14AsciiToGxtCharPKcPt"));
SET_TO(RenderFontBuffer, aml->GetSym(hGTASA, "_ZN5CFont16RenderFontBufferEv"));
Expand Down
38 changes: 38 additions & 0 deletions GiroflexVSL/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ static double GetAngleBetweenVectors(CVector v1, CVector v2, CVector v3)
return acos((pow(v12, 2) + pow(v13, 2) - pow(v23, 2)) / (2 * (v12 * v13)));
}

static CVector RotateVectorAroundZ(CVector vector, float angleRadians) {

//float angleRadians = angleDegrees * (3.14159265f / 180.0f);

// Calcula o cosseno e o seno do ângulo
float cosTheta = cosf(angleRadians);
float sinTheta = sinf(angleRadians);

// Aplica a rotação no plano XY
CVector rotatedVector = CVector(0, 0, 0);
rotatedVector.x = vector.x * cosTheta - vector.y * sinTheta;
rotatedVector.y = vector.x * sinTheta + vector.y * cosTheta;
rotatedVector.z = vector.z; // A componente Z não muda

return rotatedVector;
}

static RwMatrix* CloneRwMatrix(const RwMatrix* originalMatrix)
{
// Cria uma nova matriz
Expand All @@ -162,6 +179,27 @@ static RwMatrix* CloneRwMatrix(const RwMatrix* originalMatrix)
return clonedMatrix;
}

static CVector CMatrixGetForward(CMatrix* cmatrix)
{
RwMatrix* matrix = RwMatrixCreate();

//entity->m_matrix->CopyToRwMatrix(matrix);
CMatrix_CopyToRwMatrix(cmatrix, matrix);

RwV3d forward = { matrix->up.x, matrix->up.y, matrix->up.z };

RwMatrixDestroy(matrix);

return CVector(forward.x, forward.y, forward.z);
}

static CVector MatrixGetForward(RwMatrix* matrix)
{
RwV3d forward = { matrix->up.x, matrix->up.y, matrix->up.z };

return CVector(forward.x, forward.y, forward.z);
}

static CVector TransformFromMatrixSpace(RwMatrix* originalMatrix, CVector pos)
{
RwMatrix* matrix = CloneRwMatrix(originalMatrix);
Expand Down
4 changes: 3 additions & 1 deletion GiroflexVSL/windows/WindowRotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ void WindowRotate::CreatePointRotate(Window* parent, LightGroup* lightGroup, Poi

window->AddCheckbox("Rotate always", &point->rotateObject.rotateAlways);

window->AddCheckbox("Flip forward dir", &point->rotateObject.flipForward);
auto showRotation = window->AddCheckbox("Show direction", &Vehicle::m_ShowRotatePointDirection);

auto rotationFix = window->AddFloatRange("Direction fix", &point->rotateObject.directionFix, -3.14f, 3.14f, 0.1f);

auto close = window->AddButton("> ~r~Close");
close->onClick = [window]() {
Expand Down
Binary file modified files/versions/3.9.0/GiroflexVSL-3.9.0__en.zip
Binary file not shown.
Binary file modified files/versions/3.9.0/GiroflexVSL-3.9.0__pt-br.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ OBS: I also found a bug that detects a lightpanel button press before the panel
[3.9.0]
[X] ADD: lights rotate with object

[ ] BUG: delay nas luzes q giram, acho q to pegando posição errada do objectWorldPosition

-----------------------
NOTES:

Expand Down

0 comments on commit d89df55

Please sign in to comment.