Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Colshape polygon #424

Merged
merged 7 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/AltV.Net.Mock/MockServer.cs
Expand Up @@ -323,6 +323,11 @@ public IColShape CreateColShapeRectangle(Position pos, Position pos2)
throw new NotImplementedException();
}

public IColShape CreateColShapePolygon(float minZ, float maxZ, Vector2[] points)
{
throw new NotImplementedException();
}

public void RemoveColShape(IColShape colShape)
{
throw new NotImplementedException();
Expand Down
15 changes: 14 additions & 1 deletion api/AltV.Net/Alt.ColShape.cs
@@ -1,5 +1,6 @@
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
using System.Numerics;

namespace AltV.Net
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public static IColShape CreateColShapeCube(Position pos, Position pos2)
}

/// <summary>
/// Creates a alt:v cube colshape between two positions with no height (from vottom to top of the height of the map).
/// Creates a alt:v cube colshape between two positions with no height (from bottom to top of the height of the map).
/// </summary>
/// <param name="x1">The first position of the colshape.</param>
/// <param name="y1">The second position of the colshape.</param>
Expand All @@ -63,5 +64,17 @@ public static IColShape CreateColShapeRectangle(float x1, float y1, float x2, fl
{
return Module.Server.CreateColShapeRectangle(x1, y1, x2, y2, z);
}

/// <summary>
/// Creates a alt:v polygon colshape between given points from minmal z position to maximal z position.
/// </summary>
/// <param name="minZ">The minimal z-axis of the colshape.</param>
/// <param name="maxZ">The maximal z-axis of the colshape.</param>
/// <param name="points">The set of points of the polygon (only x and y axis)</param>
/// <returns>The created colshape.</returns>
public static IColShape CreateColShapePolygon(float minZ, float maxZ, Vector2[] points)
{
return Module.Server.CreateColShapePolygon(minZ, maxZ, points);
}
}
}
3 changes: 2 additions & 1 deletion api/AltV.Net/Elements/Entities/ColShapeType.cs
Expand Up @@ -7,6 +7,7 @@ public enum ColShapeType : byte
Circle,
Cube,
Rect,
CheckpointCylinder
CheckpointCylinder,
Polygon
}
}
2 changes: 2 additions & 0 deletions api/AltV.Net/IServer.cs
Expand Up @@ -127,6 +127,8 @@ public interface IServer

IColShape CreateColShapeRectangle(float x1, float y1, float x2, float y2, float z);

IColShape CreateColShapePolygon(float minZ, float maxZ, Vector2[] points);

void RemoveBlip(IBlip blip);

void RemoveCheckpoint(ICheckpoint checkpoint);
Expand Down
3 changes: 3 additions & 0 deletions api/AltV.Net/Native/Library.cs
Expand Up @@ -325,6 +325,7 @@ public unsafe interface ILibrary
public delegate* unmanaged[Cdecl]<nint, Position, Position, nint> Server_CreateColShapeCube { get; }
public delegate* unmanaged[Cdecl]<nint, Position, float, float, nint> Server_CreateColShapeCylinder { get; }
public delegate* unmanaged[Cdecl]<nint, float, float, float, float, float, nint> Server_CreateColShapeRectangle { get; }
public delegate* unmanaged[Cdecl]<nint, float, float, Vector2[], int, nint> Server_CreateColShapePolygon { get; }
public delegate* unmanaged[Cdecl]<nint, Position, float, nint> Server_CreateColShapeSphere { get; }
public delegate* unmanaged[Cdecl]<nint, uint, Position, Rotation, ushort*, nint> Server_CreateVehicle { get; }
public delegate* unmanaged[Cdecl]<nint, byte, float, nint> Server_CreateVoiceChannel { get; }
Expand Down Expand Up @@ -897,6 +898,7 @@ public unsafe class Library : ILibrary
public delegate* unmanaged[Cdecl]<nint, Position, Position, nint> Server_CreateColShapeCube { get; }
public delegate* unmanaged[Cdecl]<nint, Position, float, float, nint> Server_CreateColShapeCylinder { get; }
public delegate* unmanaged[Cdecl]<nint, float, float, float, float, float, nint> Server_CreateColShapeRectangle { get; }
public delegate* unmanaged[Cdecl]<nint, float, float, Vector2[], int, nint> Server_CreateColShapePolygon { get; }
public delegate* unmanaged[Cdecl]<nint, Position, float, nint> Server_CreateColShapeSphere { get; }
public delegate* unmanaged[Cdecl]<nint, uint, Position, Rotation, ushort*, nint> Server_CreateVehicle { get; }
public delegate* unmanaged[Cdecl]<nint, byte, float, nint> Server_CreateVoiceChannel { get; }
Expand Down Expand Up @@ -1473,6 +1475,7 @@ public Library()
Server_CreateColShapeCube = (delegate* unmanaged[Cdecl]<nint, Position, Position, nint>) NativeLibrary.GetExport(handle, "Server_CreateColShapeCube");
Server_CreateColShapeCylinder = (delegate* unmanaged[Cdecl]<nint, Position, float, float, nint>) NativeLibrary.GetExport(handle, "Server_CreateColShapeCylinder");
Server_CreateColShapeRectangle = (delegate* unmanaged[Cdecl]<nint, float, float, float, float, float, nint>) NativeLibrary.GetExport(handle, "Server_CreateColShapeRectangle");
Server_CreateColShapePolygon = (delegate* unmanaged[Cdecl]<nint, float, float, Vector2[], int, nint>) NativeLibrary.GetExport(handle, "Server_CreateColShapePolygon");
Server_CreateColShapeSphere = (delegate* unmanaged[Cdecl]<nint, Position, float, nint>) NativeLibrary.GetExport(handle, "Server_CreateColShapeSphere");
Server_CreateVehicle = (delegate* unmanaged[Cdecl]<nint, uint, Position, Rotation, ushort*, nint>) NativeLibrary.GetExport(handle, "Server_CreateVehicle");
Server_CreateVoiceChannel = (delegate* unmanaged[Cdecl]<nint, byte, float, nint>) NativeLibrary.GetExport(handle, "Server_CreateVoiceChannel");
Expand Down
13 changes: 13 additions & 0 deletions api/AltV.Net/Server.cs
Expand Up @@ -693,6 +693,19 @@ public IColShape CreateColShapeRectangle(float x1, float y1, float x2, float y2,
}
}

public IColShape CreateColShapePolygon(float minZ, float maxZ, Vector2[] points)
{
unsafe
{
CheckIfCallIsValid();
int size = points.Count();
var ptr = Library.Server_CreateColShapePolygon(NativePointer, minZ, maxZ, points, size);
if (ptr == IntPtr.Zero) return null;
colShapePool.Create(this, ptr, out var colShape);
return colShape;
}
}

public void RemoveBlip(IBlip blip)
{
CheckIfCallIsValid();
Expand Down
13 changes: 13 additions & 0 deletions docs/articles/colshapes-example.md
Expand Up @@ -78,3 +78,16 @@ ColShape in a Rectangle form.
//Parameter : (float x1, float y1, float x2, float y2, float height)
Alt.CreateColShapeRectangle(0.0f, 0.0f, 0.0f, 0.0f, 10f); // Creates a colshape in a form of a rectangle.
```

ColShape in a Polygon form.
```csharp
//polygon points
Vector2[] points = new Vector2[]{
new Vector2(0, 0),
new Vector2(0, 1),
new Vector2(1, 0),
new Vector2(1, 1)
}
//Parameter : (float minZ, float maxZ, Vector2[] points)
Alt.CreateColShapePolygon(0.0f, 2.0f, points); // Creates a colshape in a form of a polygon.
```
14 changes: 14 additions & 0 deletions runtime/src/altv-c-api/server.cpp
@@ -1,5 +1,6 @@
#include "server.h"
#include "mvalue.h"
#include <vector>

void Server_LogInfo(alt::ICore* server, const char* str) {
server->LogInfo(str);
Expand Down Expand Up @@ -180,6 +181,19 @@ alt::IColShape* Server_CreateColShapeRectangle(alt::ICore* server, float x1, flo
return server->CreateColShapeRectangle(x1, y1, x2, y2, z).Get();
}

alt::IColShape* Server_CreateColShapePolygon(alt::ICore* server, float minZ, float maxZ, vector2_t points[], int pointSize) {
std::vector<alt::Vector2f> convertedPoints(pointSize);
for (int i = 0; i < pointSize; i++)
{
alt::Vector2f point;
point[0] = points[i].x;
point[1] = points[i].y;
convertedPoints[i] = point;
}

return server->CreateColShapePolygon(minZ, maxZ, convertedPoints).Get();
}

/*void Server_DestroyBaseObject(alt::ICore* server, alt::IBaseObject* baseObject) {
return server->DestroyBaseObject(baseObject);
}*/
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/altv-c-api/server.h
Expand Up @@ -10,6 +10,7 @@
#include <CSharpResourceImpl.h>
#include "rotation.h"
#include "position.h"
#include "vector2.h"

#ifdef __clang__
#pragma clang diagnostic pop
Expand Down Expand Up @@ -54,6 +55,7 @@ EXPORT alt::IColShape* Server_CreateColShapeSphere(alt::ICore* server, position_
EXPORT alt::IColShape* Server_CreateColShapeCircle(alt::ICore* server, position_t pos, float radius);
EXPORT alt::IColShape* Server_CreateColShapeCube(alt::ICore* server, position_t pos, position_t pos2);
EXPORT alt::IColShape* Server_CreateColShapeRectangle(alt::ICore* server, float x1, float y1, float x2, float y2, float z);
EXPORT alt::IColShape* Server_CreateColShapePolygon(alt::ICore* server, float minZ, float maxZ, vector2_t points[], int pointSize);
//EXPORT void Server_DestroyBaseObject(alt::ICore* server, alt::IBaseObject* baseObject);
EXPORT void Server_DestroyVehicle(alt::ICore* server, alt::IVehicle* baseObject);
EXPORT void Server_DestroyBlip(alt::ICore* server, alt::IBlip* baseObject);
Expand Down