Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo1301 committed Jul 29, 2024
1 parent 849a739 commit 5ec15bd
Show file tree
Hide file tree
Showing 69 changed files with 152 additions and 115 deletions.
2 changes: 1 addition & 1 deletion GiroflexVSL/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern RpClump* (*RpClumpForAllAtomics)(RpClump* clump, RpAtomicCallBack callbac
extern RpGeometry* (*RpGeometryForAllMaterials)(RpGeometry* geometry, RpMaterialCallBack fpCallBack, void* pData);
extern char* (*GetFrameNodeName)(RwFrame* frame);

const char* Mod::m_Version = "3.7.1";
const char* Mod::m_Version = "3.7.2";

bool canTurnSirenOn = true;
bool canTurnPanelOn = true;
Expand Down
36 changes: 4 additions & 32 deletions GiroflexVSL/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ extern IMenuVSL* menuVSL;
enum class eSirenDirection {
FRONT,
BOTH,
BACK
BACK,
SIDES
};

class Point {
Expand All @@ -36,6 +37,7 @@ class Point {
rotateObjectValue["speed"] = rotateObject.speed;
rotateObjectValue["object"] = rotateObject.object;
rotateObjectValue["axis"] = (int)rotateObject.axis;
rotateObjectValue["rotateAlways"] = rotateObject.rotateAlways;
value["rotateObject"] = rotateObjectValue;


Expand All @@ -55,6 +57,7 @@ class Point {
rotateObject.speed = ValidateValue(rotateObjectValue["speed"], rotateObject.speed).asInt();
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();
}
}

Expand All @@ -74,35 +77,4 @@ class Point {
}
return angle;
}

static double GetRadiusMultiplierByAngle(double currentDir, double startFadeDir, double offsetFadeDir) {
double end = startFadeDir + offsetFadeDir;

if (offsetFadeDir < 0) {
if (currentDir < startFadeDir + offsetFadeDir) currentDir = startFadeDir + offsetFadeDir;
if (currentDir > startFadeDir) currentDir = startFadeDir;
}
else {
if (currentDir < startFadeDir) currentDir = startFadeDir;
if (currentDir > startFadeDir + offsetFadeDir) currentDir = startFadeDir + offsetFadeDir;
}

return abs((currentDir - end) / offsetFadeDir);
}

float GetRadiusMultiplier(double angle, eSirenDirection direction, float positionY) {
if (direction == eSirenDirection::BOTH) return 1.0f;

eSirenDirection atDirection = positionY > 0 ? eSirenDirection::FRONT : eSirenDirection::BACK;

double start_fadeout = 1.0f;
double fadeout_offset = 0.6f;

if (atDirection != direction) {
start_fadeout += fadeout_offset;
fadeout_offset *= -1;
}

return (float)GetRadiusMultiplierByAngle(angle, start_fadeout, fadeout_offset);
}
};
170 changes: 97 additions & 73 deletions GiroflexVSL/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static std::list<std::pair<unsigned int *, unsigned int>> resetEntries;

int Vehicle::m_LightIdOffset = 1000;

int LightIdOffset = 10000;

Vehicle::Vehicle(int hVehicle, int modelId)
{
this->hVehicle = hVehicle;
Expand Down Expand Up @@ -269,6 +271,8 @@ void Vehicle::UpdateLightGroups(int dt)
y += std::cos(angle) * lightGroup->rotateDistance;
}

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

//color
CRGBA color = lightGroup->color1;
if((double)i < ((double)amountOfPoints)/(double)2)
Expand Down Expand Up @@ -309,25 +313,75 @@ void Vehicle::UpdateLightGroups(int dt)

auto radius = lightGroup->radius;

auto positionY = lightGroup->offset.y + point->customOffset.y;
auto angle = Point::GetAngle(pVehicle, lightGroup->offset + point->customOffset);
//auto positionY = lightGroup->offset.y + point->customOffset.y;

auto radiusMult = point->GetRadiusMultiplier(angle, lightGroup->direction, positionY);
//---------------------------------------
// get angle and direction
// and I hate this, cuz its hard, or im just too stupid for this, idk

radius = lightGroup->radius * radiusMult;

//menuVSL->debug->AddLine("vehicle: " + std::to_string(hVehicle));
//menuVSL->debug->AddLine("angle: " + std::to_string(angle));
//menuVSL->debug->AddLine("rad mul: " + std::to_string(radiusMult));
//menuVSL->debug->AddLine("radius: " + std::to_string(radius));
auto vehiclePos = pVehicle->m_matrix->pos;
CVector cameraPos = camera->m_matrix->pos;
float coronaOffsetX = coronaOffset.x;

auto vec1 = TransformFromObjectSpace(pVehicle, CVector(-coronaOffsetX, 0, 0));
vec1.z = vehiclePos.z;

auto vec2 = vehiclePos;

auto vec3 = cameraPos;
vec3.z = vehiclePos.z;

auto vec1_2d = CVector2D(vec1.x, vec1.y);
auto vec2_2d = CVector2D(vec2.x, vec2.y);
auto vec3_2d = CVector2D(vec3.x, vec3.y);

auto angle = calculateAngleVec2D(vec1_2d, vec2_2d, vec3_2d);

//menuVSL->debug->m_Visible = true;
//menuVSL->debug->AddLine("angle: " + std::to_string(angle));
//menuVSL->debug->AddLine("x: " + std::to_string(coronaOffsetX));

eSirenDirection direction = lightGroup->direction;

float radiusMult = 1.0f;
bool isCoronaAtLeft = coronaOffsetX < 0;
bool isCoronaAtRight = !isCoronaAtLeft;

if(direction == eSirenDirection::SIDES)
{
bool isHidden = (angle < 270.0f && angle > 90.0f);

radiusMult = isHidden ? 0.0f : 1.0f;
}

if(direction == eSirenDirection::FRONT || direction == eSirenDirection::BACK)
{
auto newAngle = angle;
if(isCoronaAtRight) newAngle -= 180;
if (newAngle < 0) newAngle += 360.0f;

bool visibleBack = (newAngle >= 0 && newAngle < 180.0f);
bool visibleFront = !visibleBack;

if(direction == eSirenDirection::FRONT)
radiusMult = visibleFront ? 1.0f : 0.0f;

if(direction == eSirenDirection::BACK)
radiusMult = visibleBack ? 1.0f : 0.0f;
}

radius = lightGroup->radius * radiusMult;

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

if(color.a == 0) enabled = false;

RenderCorona corona;
corona.car = hVehicle;
corona.pVehicle = pVehicle;
corona.id = lightId++;
corona.color = color;
corona.offset = CVector(x, y, 0) + lightGroup->offset + point->customOffset;
corona.offset = coronaOffset;
corona.radius = enabled ? radius : 0.0f;
corona.renderShadow = enabled ? lightGroup->renderShadow : false;
corona.renderPointLight = enabled ? lightGroup->renderPointLight : false;
Expand All @@ -337,14 +391,14 @@ void Vehicle::UpdateLightGroups(int dt)

//shadow offset X
//corona.shadowOffsetX = lightGroup->shadowPositionX;
auto dir = (corona.offset.x > 0) ? 1 : -1;
auto dir = (coronaOffset.x > 0) ? 1 : -1;
float margin = 0.15f;
float sdistance = abs(corona.offset.x);
float sdistance = abs(coronaOffset.x);

corona.shadowOffsetX = corona.offset.x + (dir * lightGroup->shadowPositionX);
corona.shadowOffsetX = coronaOffset.x + (dir * lightGroup->shadowPositionX);
if (sdistance > margin)
{
corona.shadowOffsetX += (dir * lightGroup->shadowSize / 2);
//corona.shadowOffsetX += (dir * lightGroup->shadowSize / 2);
}

if(lightGroup->rotate) corona.shadowOffsetX = lightGroup->shadowPositionX;
Expand Down Expand Up @@ -390,65 +444,8 @@ void Vehicle::UpdateLightGroups(int dt)
}

void Vehicle::OnUpdateGameLogic()
{
return;

auto lightId = hVehicle + Vehicle::m_LightIdOffset + 100;

auto position = pVehicle->m_matrix->pos;

//menuVSL->debug->AddLine("Register at "+ CVectorToString(position));
//Log::Level(LOG_LEVEL::LOG_BOTH) << "Register corona at " << CVectorToString(position) << std::endl;

RegisterCorona(
lightId++,
NULL,
255,
0,
0,
255,
{ position.x, position.y, position.z },
2.0f,
1000.0f,
0,
0,
true,
false,
0,
0.0f,
false,
0.0f,
0,
10000.0f,
false,
false
);

auto position2 = TransformFromObjectSpace(pVehicle, CVector(10, 0, 0));

RegisterCorona(
lightId++,
NULL,
0,
255,
0,
255,
{ position2.x, position2.y, position2.z },
2.0f,
1000.0f,
0,
0,
true,
false,
0,
0.0f,
false,
0.0f,
0,
10000.0f,
false,
false
);
{

}

void Vehicle::RenderBefore()
Expand Down Expand Up @@ -672,4 +669,31 @@ void Vehicle::ResetObjectRotation(std::string object)

RwMatrixRotate(&frame->modelling, &axis, angle, rwCOMBINEREPLACE);
RwMatrixTranslate(&frame->modelling, &pos, rwCOMBINEREPLACE);
}

void Vehicle::RegisterTestCorona(int lightId, CVector position, CRGBA color, float radius)
{
RegisterCorona(
lightId++,
NULL,
color.r,
color.g,
color.b,
255,
{ position.x, position.y, position.z },
radius,
1000.0f,
0,
0,
true,
false,
0,
0.0f,
false,
0.0f,
0,
10000.0f,
false,
false
);
}
2 changes: 2 additions & 0 deletions GiroflexVSL/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ class Vehicle {

void SetGiroflexEnabled(bool enabled, bool forceOn = false);
void ResetObjectRotation(std::string object);

void RegisterTestCorona(int lightId, CVector position, CRGBA color, float radius);
};
4 changes: 2 additions & 2 deletions GiroflexVSL/Vehicles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void Vehicles::RenderAfter(CVehicle* pVehicle)

void Vehicles::AddCoronaToRender(RenderCorona corona)
{
if (corona.color.a == 0) return;
if (corona.radius <= 0.0f) return;
//if (corona.color.a == 0) return;
//if (corona.radius <= 0.0f) return;

m_CoronasToRender.push_back(corona);
}
Expand Down
4 changes: 3 additions & 1 deletion GiroflexVSL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ---------------------------------------

//MYMODCFG(net.danilo1301.giroflexVSL, GiroflexVSL, Mod::m_Version, Danilo1301) //whoops
MYMODCFG(net.danilo1301.giroflexVSL, GiroflexVSL, 3.7.1, Danilo1301)
MYMODCFG(net.danilo1301.giroflexVSL, GiroflexVSL, 3.7.2, Danilo1301)

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

Expand Down Expand Up @@ -71,6 +71,7 @@ RwMatrix* (*RwMatrixTranslate)(RwMatrix* matrix, const RwV3d* translation, RwOpC
RwReal (*RwV3dNormalize)(RwV3d* out, const RwV3d* in);
void (*CMatrix_CopyToRwMatrix)(CMatrix*, RwMatrix *matrix);
RwMatrix* (*RwMatrixCreate)(void);
RwBool (*RwMatrixDestroy)(RwMatrix* mpMat);

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

SET_TO(CFont_PrintString, aml->GetSym(hGTASA, "_ZN5CFont11PrintStringEffPt"));
SET_TO(AsciiToGxtChar, aml->GetSym(hGTASA, "_Z14AsciiToGxtCharPKcPt"));
Expand Down
2 changes: 1 addition & 1 deletion GiroflexVSL/ndkpath.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\android-ndk-r26c
C:\android-ndk
26 changes: 25 additions & 1 deletion GiroflexVSL/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern RwMatrix* (*RwMatrixTranslate)(RwMatrix* matrix, const RwV3d* translation
extern RwReal (*RwV3dNormalize)(RwV3d* out, const RwV3d* in);
extern void (*CMatrix_CopyToRwMatrix)(CMatrix*, RwMatrix *matrix);
extern RwMatrix* (*RwMatrixCreate)(void);
extern RwBool (*RwMatrixDestroy)(RwMatrix* mpMat);

/*
static unsigned char ucharIntensity(unsigned char uc, float intensity) {
Expand Down Expand Up @@ -177,7 +178,30 @@ static CVector TransformFromObjectSpace(CEntity* entity, CVector pos)

auto finalPos = CVector(matrix->pos.x, matrix->pos.y, matrix->pos.z);

//RwMatrixDestroy(matrix);
RwMatrixDestroy(matrix);

return finalPos;
}

static float calculateAngleVec2D(const CVector2D& A, const CVector2D& B, const CVector2D& C) {
// Vetores AB e BC
CVector2D AB(B.x - A.x, B.y - A.y);
CVector2D BC(C.x - B.x, C.y - B.y);

// Ângulos em relação ao eixo x usando atan2
float angleAB = std::atan2(AB.y, AB.x);
float angleBC = std::atan2(BC.y, BC.x);

// Diferença entre os ângulos
float angle = angleBC - angleAB;

// Converte de radianos para graus, se necessário
angle = angle * 180.0f / M_PI;

// Garantir que o ângulo esteja no intervalo [0, 360)
if (angle < 0) {
angle += 360.0f;
}

return angle;
}
1 change: 1 addition & 0 deletions GiroflexVSL/windows/WindowLightGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void WindowLightGroups::CreateEditLightGroup(Window* parent, LightGroup* lightGr
lights_direction->AddOption(111, 0, 0);
lights_direction->AddOption(112, 0, 0);
lights_direction->AddOption(113, 0, 0);
lights_direction->AddOption(114, 0, 0);
lights_direction->onValueChange = [lights_direction, lightGroup]() {
lightGroup->direction = (eSirenDirection)lights_direction->optionsValue;
};
Expand Down
Binary file modified cleo/giroflex v3/GiroflexVSL.csa
Binary file not shown.
Loading

0 comments on commit 5ec15bd

Please sign in to comment.