New naming rules
This commit is contained in:
parent
7f95e119c6
commit
db9f65bc92
|
|
@ -226,13 +226,13 @@ void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *e
|
||||||
static float fractionSpeed = 0.8f;
|
static float fractionSpeed = 0.8f;
|
||||||
|
|
||||||
camera->offset = (Vector2){ width/2, height/2 };
|
camera->offset = (Vector2){ width/2, height/2 };
|
||||||
Vector2 diff = Vector2SubtractV(player->position, camera->target);
|
Vector2 diff = Vector2Subtract(player->position, camera->target);
|
||||||
float length = Vector2Length(diff);
|
float length = Vector2Length(diff);
|
||||||
|
|
||||||
if (length > minEffectLength)
|
if (length > minEffectLength)
|
||||||
{
|
{
|
||||||
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
||||||
camera->target = Vector2AddV(camera->target, Vector2Scale(diff, speed*delta/length));
|
camera->target = Vector2Add(camera->target, Vector2Scale(diff, speed*delta/length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,12 +245,12 @@ void ResetStar(Star *s)
|
||||||
|
|
||||||
} while (!(fabs(s->vel.x) + fabs(s->vel.y) > 1));
|
} while (!(fabs(s->vel.x) + fabs(s->vel.y) > 1));
|
||||||
|
|
||||||
s->pos = Vector2AddV(s->pos, Vector2MultiplyV(s->vel, (Vector2){ 8, 8 }));
|
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8, 8 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateStar(Star *s)
|
void UpdateStar(Star *s)
|
||||||
{
|
{
|
||||||
s->pos = Vector2AddV(s->pos, s->vel);
|
s->pos = Vector2Add(s->pos, s->vel);
|
||||||
|
|
||||||
if (s->pos.x < 0 || s->pos.x > GetScreenWidth() ||
|
if (s->pos.x < 0 || s->pos.x > GetScreenWidth() ||
|
||||||
s->pos.y < 0 || s->pos.y > GetScreenHeight())
|
s->pos.y < 0 || s->pos.y > GetScreenHeight())
|
||||||
|
|
|
||||||
|
|
@ -1511,7 +1511,7 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
|
||||||
Vector3 cameraPlanePointerPos = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView);
|
Vector3 cameraPlanePointerPos = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView);
|
||||||
|
|
||||||
// Calculate normalized direction vector
|
// Calculate normalized direction vector
|
||||||
Vector3 direction = Vector3Normalize(Vector3SubtractV(farPoint, nearPoint));
|
Vector3 direction = Vector3Normalize(Vector3Subtract(farPoint, nearPoint));
|
||||||
|
|
||||||
if (camera.type == CAMERA_PERSPECTIVE) ray.position = camera.position;
|
if (camera.type == CAMERA_PERSPECTIVE) ray.position = camera.position;
|
||||||
else if (camera.type == CAMERA_ORTHOGRAPHIC) ray.position = cameraPlanePointerPos;
|
else if (camera.type == CAMERA_ORTHOGRAPHIC) ray.position = cameraPlanePointerPos;
|
||||||
|
|
|
||||||
46
src/models.c
46
src/models.c
|
|
@ -1111,8 +1111,8 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
|
||||||
{
|
{
|
||||||
animations[a].framePoses[frame][i].rotation = QuaternionMultiplyQ(animations[a].framePoses[frame][animations[a].bones[i].parent].rotation, animations[a].framePoses[frame][i].rotation);
|
animations[a].framePoses[frame][i].rotation = QuaternionMultiplyQ(animations[a].framePoses[frame][animations[a].bones[i].parent].rotation, animations[a].framePoses[frame][i].rotation);
|
||||||
animations[a].framePoses[frame][i].translation = Vector3RotateByQuaternion(animations[a].framePoses[frame][i].translation, animations[a].framePoses[frame][animations[a].bones[i].parent].rotation);
|
animations[a].framePoses[frame][i].translation = Vector3RotateByQuaternion(animations[a].framePoses[frame][i].translation, animations[a].framePoses[frame][animations[a].bones[i].parent].rotation);
|
||||||
animations[a].framePoses[frame][i].translation = Vector3AddV(animations[a].framePoses[frame][i].translation, animations[a].framePoses[frame][animations[a].bones[i].parent].translation);
|
animations[a].framePoses[frame][i].translation = Vector3Add(animations[a].framePoses[frame][i].translation, animations[a].framePoses[frame][animations[a].bones[i].parent].translation);
|
||||||
animations[a].framePoses[frame][i].scale = Vector3MultiplyV(animations[a].framePoses[frame][i].scale, animations[a].framePoses[frame][animations[a].bones[i].parent].scale);
|
animations[a].framePoses[frame][i].scale = Vector3Multiply(animations[a].framePoses[frame][i].scale, animations[a].framePoses[frame][animations[a].bones[i].parent].scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1165,10 +1165,10 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
// Vertices processing
|
// Vertices processing
|
||||||
// NOTE: We use meshes.vertices (default vertex position) to calculate meshes.animVertices (animated vertex position)
|
// NOTE: We use meshes.vertices (default vertex position) to calculate meshes.animVertices (animated vertex position)
|
||||||
animVertex = (Vector3){ model.meshes[m].vertices[vCounter], model.meshes[m].vertices[vCounter + 1], model.meshes[m].vertices[vCounter + 2] };
|
animVertex = (Vector3){ model.meshes[m].vertices[vCounter], model.meshes[m].vertices[vCounter + 1], model.meshes[m].vertices[vCounter + 2] };
|
||||||
animVertex = Vector3MultiplyV(animVertex, outScale);
|
animVertex = Vector3Multiply(animVertex, outScale);
|
||||||
animVertex = Vector3SubtractV(animVertex, inTranslation);
|
animVertex = Vector3Subtract(animVertex, inTranslation);
|
||||||
animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiplyQ(outRotation, QuaternionInvert(inRotation)));
|
animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiplyQ(outRotation, QuaternionInvert(inRotation)));
|
||||||
animVertex = Vector3AddV(animVertex, outTranslation);
|
animVertex = Vector3Add(animVertex, outTranslation);
|
||||||
model.meshes[m].animVertices[vCounter] = animVertex.x;
|
model.meshes[m].animVertices[vCounter] = animVertex.x;
|
||||||
model.meshes[m].animVertices[vCounter + 1] = animVertex.y;
|
model.meshes[m].animVertices[vCounter + 1] = animVertex.y;
|
||||||
model.meshes[m].animVertices[vCounter + 2] = animVertex.z;
|
model.meshes[m].animVertices[vCounter + 2] = animVertex.z;
|
||||||
|
|
@ -1914,7 +1914,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
||||||
vC.y = mesh.vertices[nCounter + i + 7];
|
vC.y = mesh.vertices[nCounter + i + 7];
|
||||||
vC.z = mesh.vertices[nCounter + i + 8];
|
vC.z = mesh.vertices[nCounter + i + 8];
|
||||||
|
|
||||||
vN = Vector3Normalize(Vector3CrossProduct(Vector3SubtractV(vB, vA), Vector3SubtractV(vC, vA)));
|
vN = Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA)));
|
||||||
|
|
||||||
mesh.normals[nCounter + i] = vN.x;
|
mesh.normals[nCounter + i] = vN.x;
|
||||||
mesh.normals[nCounter + i + 1] = vN.y;
|
mesh.normals[nCounter + i + 1] = vN.y;
|
||||||
|
|
@ -2518,13 +2518,13 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vec
|
||||||
right = Vector3Scale(right, sizeRatio.x/2);
|
right = Vector3Scale(right, sizeRatio.x/2);
|
||||||
up = Vector3Scale(up, sizeRatio.y/2);
|
up = Vector3Scale(up, sizeRatio.y/2);
|
||||||
|
|
||||||
Vector3 p1 = Vector3AddV(right, up);
|
Vector3 p1 = Vector3Add(right, up);
|
||||||
Vector3 p2 = Vector3SubtractV(right, up);
|
Vector3 p2 = Vector3Subtract(right, up);
|
||||||
|
|
||||||
Vector3 a = Vector3SubtractV(center, p2);
|
Vector3 a = Vector3Subtract(center, p2);
|
||||||
Vector3 b = Vector3AddV(center, p1);
|
Vector3 b = Vector3Add(center, p1);
|
||||||
Vector3 c = Vector3AddV(center, p2);
|
Vector3 c = Vector3Add(center, p2);
|
||||||
Vector3 d = Vector3SubtractV(center, p1);
|
Vector3 d = Vector3Subtract(center, p1);
|
||||||
|
|
||||||
if (rlCheckBufferLimit(4)) rlglDraw();
|
if (rlCheckBufferLimit(4)) rlglDraw();
|
||||||
|
|
||||||
|
|
@ -2585,7 +2585,7 @@ bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, floa
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Check for distances squared to avoid sqrtf()
|
// Check for distances squared to avoid sqrtf()
|
||||||
if (Vector3DotProduct(Vector3SubtractV(centerB, centerA), Vector3SubtractV(centerB, centerA)) <= (radiusA + radiusB)*(radiusA + radiusB)) collision = true;
|
if (Vector3DotProduct(Vector3Subtract(centerB, centerA), Vector3Subtract(centerB, centerA)) <= (radiusA + radiusB)*(radiusA + radiusB)) collision = true;
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
}
|
}
|
||||||
|
|
@ -2632,7 +2632,7 @@ bool CheckCollisionRaySphere(Ray ray, Vector3 center, float radius)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
Vector3 raySpherePos = Vector3SubtractV(center, ray.position);
|
Vector3 raySpherePos = Vector3Subtract(center, ray.position);
|
||||||
float distance = Vector3Length(raySpherePos);
|
float distance = Vector3Length(raySpherePos);
|
||||||
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
||||||
float d = radius*radius - (distance*distance - vector*vector);
|
float d = radius*radius - (distance*distance - vector*vector);
|
||||||
|
|
@ -2647,7 +2647,7 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 center, float radius, Vector3 *c
|
||||||
{
|
{
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
Vector3 raySpherePos = Vector3SubtractV(center, ray.position);
|
Vector3 raySpherePos = Vector3Subtract(center, ray.position);
|
||||||
float distance = Vector3Length(raySpherePos);
|
float distance = Vector3Length(raySpherePos);
|
||||||
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
||||||
float d = radius*radius - (distance*distance - vector*vector);
|
float d = radius*radius - (distance*distance - vector*vector);
|
||||||
|
|
@ -2661,7 +2661,7 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 center, float radius, Vector3 *c
|
||||||
else collisionDistance = vector - sqrtf(d);
|
else collisionDistance = vector - sqrtf(d);
|
||||||
|
|
||||||
// Calculate collision point
|
// Calculate collision point
|
||||||
Vector3 cPoint = Vector3AddV(ray.position, Vector3Scale(ray.direction, collisionDistance));
|
Vector3 cPoint = Vector3Add(ray.position, Vector3Scale(ray.direction, collisionDistance));
|
||||||
|
|
||||||
collisionPoint->x = cPoint.x;
|
collisionPoint->x = cPoint.x;
|
||||||
collisionPoint->y = cPoint.y;
|
collisionPoint->y = cPoint.y;
|
||||||
|
|
@ -2752,8 +2752,8 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
|
||||||
RayHitInfo result = {0};
|
RayHitInfo result = {0};
|
||||||
|
|
||||||
// Find vectors for two edges sharing V1
|
// Find vectors for two edges sharing V1
|
||||||
edge1 = Vector3SubtractV(p2, p1);
|
edge1 = Vector3Subtract(p2, p1);
|
||||||
edge2 = Vector3SubtractV(p3, p1);
|
edge2 = Vector3Subtract(p3, p1);
|
||||||
|
|
||||||
// Begin calculating determinant - also used to calculate u parameter
|
// Begin calculating determinant - also used to calculate u parameter
|
||||||
p = Vector3CrossProduct(ray.direction, edge2);
|
p = Vector3CrossProduct(ray.direction, edge2);
|
||||||
|
|
@ -2767,7 +2767,7 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
|
||||||
invDet = 1.0f/det;
|
invDet = 1.0f/det;
|
||||||
|
|
||||||
// Calculate distance from V1 to ray origin
|
// Calculate distance from V1 to ray origin
|
||||||
tv = Vector3SubtractV(ray.position, p1);
|
tv = Vector3Subtract(ray.position, p1);
|
||||||
|
|
||||||
// Calculate u parameter and test bound
|
// Calculate u parameter and test bound
|
||||||
u = Vector3DotProduct(tv, p)*invDet;
|
u = Vector3DotProduct(tv, p)*invDet;
|
||||||
|
|
@ -2793,7 +2793,7 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
|
||||||
result.distance = t;
|
result.distance = t;
|
||||||
result.hit = true;
|
result.hit = true;
|
||||||
result.normal = Vector3Normalize(Vector3CrossProduct(edge1, edge2));
|
result.normal = Vector3Normalize(Vector3CrossProduct(edge1, edge2));
|
||||||
result.position = Vector3AddV(ray.position, Vector3Scale(ray.direction, t));
|
result.position = Vector3Add(ray.position, Vector3Scale(ray.direction, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -2815,7 +2815,7 @@ RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight)
|
||||||
result.hit = true;
|
result.hit = true;
|
||||||
result.distance = distance;
|
result.distance = distance;
|
||||||
result.normal = (Vector3){ 0.0, 1.0, 0.0 };
|
result.normal = (Vector3){ 0.0, 1.0, 0.0 };
|
||||||
result.position = Vector3AddV(ray.position, Vector3Scale(ray.direction, distance));
|
result.position = Vector3Add(ray.position, Vector3Scale(ray.direction, distance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3315,8 +3315,8 @@ static Model LoadIQM(const char *fileName)
|
||||||
{
|
{
|
||||||
model.bindPose[i].rotation = QuaternionMultiplyQ(model.bindPose[model.bones[i].parent].rotation, model.bindPose[i].rotation);
|
model.bindPose[i].rotation = QuaternionMultiplyQ(model.bindPose[model.bones[i].parent].rotation, model.bindPose[i].rotation);
|
||||||
model.bindPose[i].translation = Vector3RotateByQuaternion(model.bindPose[i].translation, model.bindPose[model.bones[i].parent].rotation);
|
model.bindPose[i].translation = Vector3RotateByQuaternion(model.bindPose[i].translation, model.bindPose[model.bones[i].parent].rotation);
|
||||||
model.bindPose[i].translation = Vector3AddV(model.bindPose[i].translation, model.bindPose[model.bones[i].parent].translation);
|
model.bindPose[i].translation = Vector3Add(model.bindPose[i].translation, model.bindPose[model.bones[i].parent].translation);
|
||||||
model.bindPose[i].scale = Vector3MultiplyV(model.bindPose[i].scale, model.bindPose[model.bones[i].parent].scale);
|
model.bindPose[i].scale = Vector3Multiply(model.bindPose[i].scale, model.bindPose[model.bones[i].parent].scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
88
src/physac.h
88
src/physac.h
|
|
@ -192,7 +192,7 @@ PHYSACDEF void ClosePhysics(void);
|
||||||
#include <math.h> // Required for: cosf(), sinf(), fabs(), sqrtf()
|
#include <math.h> // Required for: cosf(), sinf(), fabs(), sqrtf()
|
||||||
|
|
||||||
#if !defined(PHYSAC_STANDALONE)
|
#if !defined(PHYSAC_STANDALONE)
|
||||||
#include "raymath.h" // Required for: Vector2AddV(), Vector2SubtractV()
|
#include "raymath.h" // Required for: Vector2Add(), Vector2Subtract()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Time management functionality
|
// Time management functionality
|
||||||
|
|
@ -343,8 +343,8 @@ static float MathDot(Vector2 v1, Vector2 v2);
|
||||||
static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors
|
static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors
|
||||||
static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector
|
static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector
|
||||||
#if defined(PHYSAC_STANDALONE)
|
#if defined(PHYSAC_STANDALONE)
|
||||||
static Vector2 Vector2AddV(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors
|
static Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors
|
||||||
static Vector2 Vector2SubtractV(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors
|
static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Matrix2x2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value
|
static Matrix2x2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value
|
||||||
|
|
@ -570,7 +570,7 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int si
|
||||||
// Adds a force to a physics body
|
// Adds a force to a physics body
|
||||||
PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force)
|
PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force)
|
||||||
{
|
{
|
||||||
if (body != NULL) body->force = Vector2AddV(body->force, force);
|
if (body != NULL) body->force = Vector2Add(body->force, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an angular force to a physics body
|
// Adds an angular force to a physics body
|
||||||
|
|
@ -592,9 +592,9 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
|
||||||
for (int i = 0; i < vertexData.vertexCount; i++)
|
for (int i = 0; i < vertexData.vertexCount; i++)
|
||||||
{
|
{
|
||||||
Vector2 positionA = body->position;
|
Vector2 positionA = body->position;
|
||||||
Vector2 positionB = Mat2MultiplyVector2(body->shape.transform, Vector2AddV(body->position, vertexData.positions[i]));
|
Vector2 positionB = Mat2MultiplyVector2(body->shape.transform, Vector2Add(body->position, vertexData.positions[i]));
|
||||||
int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0);
|
int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0);
|
||||||
Vector2 positionC = Mat2MultiplyVector2(body->shape.transform, Vector2AddV(body->position, vertexData.positions[nextIndex]));
|
Vector2 positionC = Mat2MultiplyVector2(body->shape.transform, Vector2Add(body->position, vertexData.positions[nextIndex]));
|
||||||
|
|
||||||
// Check collision between each triangle
|
// Check collision between each triangle
|
||||||
float alpha = ((positionB.y - positionC.y)*(position.x - positionC.x) + (positionC.x - positionB.x)*(position.y - positionC.y))/
|
float alpha = ((positionB.y - positionC.y)*(position.x - positionC.x) + (positionC.x - positionB.x)*(position.y - positionC.y))/
|
||||||
|
|
@ -627,17 +627,17 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
|
||||||
{
|
{
|
||||||
int nextIndex = (((i + 1) < count) ? (i + 1) : 0);
|
int nextIndex = (((i + 1) < count) ? (i + 1) : 0);
|
||||||
Vector2 center = TriangleBarycenter(vertices[i], vertices[nextIndex], PHYSAC_VECTOR_ZERO);
|
Vector2 center = TriangleBarycenter(vertices[i], vertices[nextIndex], PHYSAC_VECTOR_ZERO);
|
||||||
center = Vector2AddV(bodyPos, center);
|
center = Vector2Add(bodyPos, center);
|
||||||
Vector2 offset = Vector2SubtractV(center, bodyPos);
|
Vector2 offset = Vector2Subtract(center, bodyPos);
|
||||||
|
|
||||||
PhysicsBody newBody = CreatePhysicsBodyPolygon(center, 10, 3, 10); // Create polygon physics body with relevant values
|
PhysicsBody newBody = CreatePhysicsBodyPolygon(center, 10, 3, 10); // Create polygon physics body with relevant values
|
||||||
|
|
||||||
PolygonData newData = { 0 };
|
PolygonData newData = { 0 };
|
||||||
newData.vertexCount = 3;
|
newData.vertexCount = 3;
|
||||||
|
|
||||||
newData.positions[0] = Vector2SubtractV(vertices[i], offset);
|
newData.positions[0] = Vector2Subtract(vertices[i], offset);
|
||||||
newData.positions[1] = Vector2SubtractV(vertices[nextIndex], offset);
|
newData.positions[1] = Vector2Subtract(vertices[nextIndex], offset);
|
||||||
newData.positions[2] = Vector2SubtractV(position, center);
|
newData.positions[2] = Vector2Subtract(position, center);
|
||||||
|
|
||||||
// Separate vertices to avoid unnecessary physics collisions
|
// Separate vertices to avoid unnecessary physics collisions
|
||||||
newData.positions[0].x *= 0.95f;
|
newData.positions[0].x *= 0.95f;
|
||||||
|
|
@ -651,7 +651,7 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
|
||||||
for (int j = 0; j < newData.vertexCount; j++)
|
for (int j = 0; j < newData.vertexCount; j++)
|
||||||
{
|
{
|
||||||
int nextVertex = (((j + 1) < newData.vertexCount) ? (j + 1) : 0);
|
int nextVertex = (((j + 1) < newData.vertexCount) ? (j + 1) : 0);
|
||||||
Vector2 face = Vector2SubtractV(newData.positions[nextVertex], newData.positions[j]);
|
Vector2 face = Vector2Subtract(newData.positions[nextVertex], newData.positions[j]);
|
||||||
|
|
||||||
newData.normals[j] = (Vector2){ face.y, -face.x };
|
newData.normals[j] = (Vector2){ face.y, -face.x };
|
||||||
MathNormalize(&newData.normals[j]);
|
MathNormalize(&newData.normals[j]);
|
||||||
|
|
@ -697,10 +697,10 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
|
||||||
|
|
||||||
// Calculate explosion force direction
|
// Calculate explosion force direction
|
||||||
Vector2 pointA = newBody->position;
|
Vector2 pointA = newBody->position;
|
||||||
Vector2 pointB = Vector2SubtractV(newData.positions[1], newData.positions[0]);
|
Vector2 pointB = Vector2Subtract(newData.positions[1], newData.positions[0]);
|
||||||
pointB.x /= 2.0f;
|
pointB.x /= 2.0f;
|
||||||
pointB.y /= 2.0f;
|
pointB.y /= 2.0f;
|
||||||
Vector2 forceDirection = Vector2SubtractV(Vector2AddV(pointA, Vector2AddV(newData.positions[0], pointB)), newBody->position);
|
Vector2 forceDirection = Vector2Subtract(Vector2Add(pointA, Vector2Add(newData.positions[0], pointB)), newBody->position);
|
||||||
MathNormalize(&forceDirection);
|
MathNormalize(&forceDirection);
|
||||||
forceDirection.x *= force;
|
forceDirection.x *= force;
|
||||||
forceDirection.y *= force;
|
forceDirection.y *= force;
|
||||||
|
|
@ -814,7 +814,7 @@ PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex)
|
||||||
case PHYSICS_POLYGON:
|
case PHYSICS_POLYGON:
|
||||||
{
|
{
|
||||||
PolygonData vertexData = body->shape.vertexData;
|
PolygonData vertexData = body->shape.vertexData;
|
||||||
position = Vector2AddV(body->position, Mat2MultiplyVector2(body->shape.transform, vertexData.positions[vertex]));
|
position = Vector2Add(body->position, Mat2MultiplyVector2(body->shape.transform, vertexData.positions[vertex]));
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
@ -995,7 +995,7 @@ static PolygonData CreateRandomPolygon(float radius, int sides)
|
||||||
for (int i = 0; i < data.vertexCount; i++)
|
for (int i = 0; i < data.vertexCount; i++)
|
||||||
{
|
{
|
||||||
int nextIndex = (((i + 1) < sides) ? (i + 1) : 0);
|
int nextIndex = (((i + 1) < sides) ? (i + 1) : 0);
|
||||||
Vector2 face = Vector2SubtractV(data.positions[nextIndex], data.positions[i]);
|
Vector2 face = Vector2Subtract(data.positions[nextIndex], data.positions[i]);
|
||||||
|
|
||||||
data.normals[i] = (Vector2){ face.y, -face.x };
|
data.normals[i] = (Vector2){ face.y, -face.x };
|
||||||
MathNormalize(&data.normals[i]);
|
MathNormalize(&data.normals[i]);
|
||||||
|
|
@ -1020,7 +1020,7 @@ static PolygonData CreateRectanglePolygon(Vector2 pos, Vector2 size)
|
||||||
for (int i = 0; i < data.vertexCount; i++)
|
for (int i = 0; i < data.vertexCount; i++)
|
||||||
{
|
{
|
||||||
int nextIndex = (((i + 1) < data.vertexCount) ? (i + 1) : 0);
|
int nextIndex = (((i + 1) < data.vertexCount) ? (i + 1) : 0);
|
||||||
Vector2 face = Vector2SubtractV(data.positions[nextIndex], data.positions[i]);
|
Vector2 face = Vector2Subtract(data.positions[nextIndex], data.positions[i]);
|
||||||
|
|
||||||
data.normals[i] = (Vector2){ face.y, -face.x };
|
data.normals[i] = (Vector2){ face.y, -face.x };
|
||||||
MathNormalize(&data.normals[i]);
|
MathNormalize(&data.normals[i]);
|
||||||
|
|
@ -1333,7 +1333,7 @@ static void SolveCircleToCircle(PhysicsManifold manifold)
|
||||||
if ((bodyA == NULL) || (bodyB == NULL)) return;
|
if ((bodyA == NULL) || (bodyB == NULL)) return;
|
||||||
|
|
||||||
// Calculate translational vector, which is normal
|
// Calculate translational vector, which is normal
|
||||||
Vector2 normal = Vector2SubtractV(bodyB->position, bodyA->position);
|
Vector2 normal = Vector2Subtract(bodyB->position, bodyA->position);
|
||||||
|
|
||||||
float distSqr = MathLenSqr(normal);
|
float distSqr = MathLenSqr(normal);
|
||||||
float radius = bodyA->shape.radius + bodyB->shape.radius;
|
float radius = bodyA->shape.radius + bodyB->shape.radius;
|
||||||
|
|
@ -1377,7 +1377,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
|
|
||||||
// Transform circle center to polygon transform space
|
// Transform circle center to polygon transform space
|
||||||
Vector2 center = bodyA->position;
|
Vector2 center = bodyA->position;
|
||||||
center = Mat2MultiplyVector2(Mat2Transpose(bodyB->shape.transform), Vector2SubtractV(center, bodyB->position));
|
center = Mat2MultiplyVector2(Mat2Transpose(bodyB->shape.transform), Vector2Subtract(center, bodyB->position));
|
||||||
|
|
||||||
// Find edge with minimum penetration
|
// Find edge with minimum penetration
|
||||||
// It is the same concept as using support points in SolvePolygonToPolygon
|
// It is the same concept as using support points in SolvePolygonToPolygon
|
||||||
|
|
@ -1387,7 +1387,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
|
|
||||||
for (int i = 0; i < vertexData.vertexCount; i++)
|
for (int i = 0; i < vertexData.vertexCount; i++)
|
||||||
{
|
{
|
||||||
float currentSeparation = MathDot(vertexData.normals[i], Vector2SubtractV(center, vertexData.positions[i]));
|
float currentSeparation = MathDot(vertexData.normals[i], Vector2Subtract(center, vertexData.positions[i]));
|
||||||
|
|
||||||
if (currentSeparation > bodyA->shape.radius) return;
|
if (currentSeparation > bodyA->shape.radius) return;
|
||||||
|
|
||||||
|
|
@ -1415,8 +1415,8 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine which voronoi region of the edge center of circle lies within
|
// Determine which voronoi region of the edge center of circle lies within
|
||||||
float dot1 = MathDot(Vector2SubtractV(center, v1), Vector2SubtractV(v2, v1));
|
float dot1 = MathDot(Vector2Subtract(center, v1), Vector2Subtract(v2, v1));
|
||||||
float dot2 = MathDot(Vector2SubtractV(center, v2), Vector2SubtractV(v1, v2));
|
float dot2 = MathDot(Vector2Subtract(center, v2), Vector2Subtract(v1, v2));
|
||||||
manifold->penetration = bodyA->shape.radius - separation;
|
manifold->penetration = bodyA->shape.radius - separation;
|
||||||
|
|
||||||
if (dot1 <= 0.0f) // Closest to v1
|
if (dot1 <= 0.0f) // Closest to v1
|
||||||
|
|
@ -1424,12 +1424,12 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
if (DistSqr(center, v1) > bodyA->shape.radius*bodyA->shape.radius) return;
|
if (DistSqr(center, v1) > bodyA->shape.radius*bodyA->shape.radius) return;
|
||||||
|
|
||||||
manifold->contactsCount = 1;
|
manifold->contactsCount = 1;
|
||||||
Vector2 normal = Vector2SubtractV(v1, center);
|
Vector2 normal = Vector2Subtract(v1, center);
|
||||||
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
||||||
MathNormalize(&normal);
|
MathNormalize(&normal);
|
||||||
manifold->normal = normal;
|
manifold->normal = normal;
|
||||||
v1 = Mat2MultiplyVector2(bodyB->shape.transform, v1);
|
v1 = Mat2MultiplyVector2(bodyB->shape.transform, v1);
|
||||||
v1 = Vector2AddV(v1, bodyB->position);
|
v1 = Vector2Add(v1, bodyB->position);
|
||||||
manifold->contacts[0] = v1;
|
manifold->contacts[0] = v1;
|
||||||
}
|
}
|
||||||
else if (dot2 <= 0.0f) // Closest to v2
|
else if (dot2 <= 0.0f) // Closest to v2
|
||||||
|
|
@ -1437,9 +1437,9 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
if (DistSqr(center, v2) > bodyA->shape.radius*bodyA->shape.radius) return;
|
if (DistSqr(center, v2) > bodyA->shape.radius*bodyA->shape.radius) return;
|
||||||
|
|
||||||
manifold->contactsCount = 1;
|
manifold->contactsCount = 1;
|
||||||
Vector2 normal = Vector2SubtractV(v2, center);
|
Vector2 normal = Vector2Subtract(v2, center);
|
||||||
v2 = Mat2MultiplyVector2(bodyB->shape.transform, v2);
|
v2 = Mat2MultiplyVector2(bodyB->shape.transform, v2);
|
||||||
v2 = Vector2AddV(v2, bodyB->position);
|
v2 = Vector2Add(v2, bodyB->position);
|
||||||
manifold->contacts[0] = v2;
|
manifold->contacts[0] = v2;
|
||||||
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
||||||
MathNormalize(&normal);
|
MathNormalize(&normal);
|
||||||
|
|
@ -1449,7 +1449,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold)
|
||||||
{
|
{
|
||||||
Vector2 normal = vertexData.normals[faceNormal];
|
Vector2 normal = vertexData.normals[faceNormal];
|
||||||
|
|
||||||
if (MathDot(Vector2SubtractV(center, v1), normal) > bodyA->shape.radius) return;
|
if (MathDot(Vector2Subtract(center, v1), normal) > bodyA->shape.radius) return;
|
||||||
|
|
||||||
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
|
||||||
manifold->normal = (Vector2){ -normal.x, -normal.y };
|
manifold->normal = (Vector2){ -normal.x, -normal.y };
|
||||||
|
|
@ -1526,12 +1526,12 @@ static void SolvePolygonToPolygon(PhysicsManifold manifold)
|
||||||
|
|
||||||
// Transform vertices to world space
|
// Transform vertices to world space
|
||||||
v1 = Mat2MultiplyVector2(refPoly.transform, v1);
|
v1 = Mat2MultiplyVector2(refPoly.transform, v1);
|
||||||
v1 = Vector2AddV(v1, refPoly.body->position);
|
v1 = Vector2Add(v1, refPoly.body->position);
|
||||||
v2 = Mat2MultiplyVector2(refPoly.transform, v2);
|
v2 = Mat2MultiplyVector2(refPoly.transform, v2);
|
||||||
v2 = Vector2AddV(v2, refPoly.body->position);
|
v2 = Vector2Add(v2, refPoly.body->position);
|
||||||
|
|
||||||
// Calculate reference face side normal in world space
|
// Calculate reference face side normal in world space
|
||||||
Vector2 sidePlaneNormal = Vector2SubtractV(v2, v1);
|
Vector2 sidePlaneNormal = Vector2Subtract(v2, v1);
|
||||||
MathNormalize(&sidePlaneNormal);
|
MathNormalize(&sidePlaneNormal);
|
||||||
|
|
||||||
// Orthogonalize
|
// Orthogonalize
|
||||||
|
|
@ -1606,8 +1606,8 @@ static void InitializePhysicsManifolds(PhysicsManifold manifold)
|
||||||
for (int i = 0; i < manifold->contactsCount; i++)
|
for (int i = 0; i < manifold->contactsCount; i++)
|
||||||
{
|
{
|
||||||
// Caculate radius from center of mass to contact
|
// Caculate radius from center of mass to contact
|
||||||
Vector2 radiusA = Vector2SubtractV(manifold->contacts[i], bodyA->position);
|
Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position);
|
||||||
Vector2 radiusB = Vector2SubtractV(manifold->contacts[i], bodyB->position);
|
Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position);
|
||||||
|
|
||||||
Vector2 crossA = MathCross(bodyA->angularVelocity, radiusA);
|
Vector2 crossA = MathCross(bodyA->angularVelocity, radiusA);
|
||||||
Vector2 crossB = MathCross(bodyB->angularVelocity, radiusB);
|
Vector2 crossB = MathCross(bodyB->angularVelocity, radiusB);
|
||||||
|
|
@ -1641,8 +1641,8 @@ static void IntegratePhysicsImpulses(PhysicsManifold manifold)
|
||||||
for (int i = 0; i < manifold->contactsCount; i++)
|
for (int i = 0; i < manifold->contactsCount; i++)
|
||||||
{
|
{
|
||||||
// Calculate radius from center of mass to contact
|
// Calculate radius from center of mass to contact
|
||||||
Vector2 radiusA = Vector2SubtractV(manifold->contacts[i], bodyA->position);
|
Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position);
|
||||||
Vector2 radiusB = Vector2SubtractV(manifold->contacts[i], bodyB->position);
|
Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position);
|
||||||
|
|
||||||
// Calculate relative velocity
|
// Calculate relative velocity
|
||||||
Vector2 radiusV = { 0.0f, 0.0f };
|
Vector2 radiusV = { 0.0f, 0.0f };
|
||||||
|
|
@ -1809,12 +1809,12 @@ static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, Physi
|
||||||
// Retrieve vertex on face from A shape, transform into B shape's model space
|
// Retrieve vertex on face from A shape, transform into B shape's model space
|
||||||
Vector2 vertex = dataA.positions[i];
|
Vector2 vertex = dataA.positions[i];
|
||||||
vertex = Mat2MultiplyVector2(shapeA.transform, vertex);
|
vertex = Mat2MultiplyVector2(shapeA.transform, vertex);
|
||||||
vertex = Vector2AddV(vertex, shapeA.body->position);
|
vertex = Vector2Add(vertex, shapeA.body->position);
|
||||||
vertex = Vector2SubtractV(vertex, shapeB.body->position);
|
vertex = Vector2Subtract(vertex, shapeB.body->position);
|
||||||
vertex = Mat2MultiplyVector2(buT, vertex);
|
vertex = Mat2MultiplyVector2(buT, vertex);
|
||||||
|
|
||||||
// Compute penetration distance in B shape's model space
|
// Compute penetration distance in B shape's model space
|
||||||
float distance = MathDot(normal, Vector2SubtractV(support, vertex));
|
float distance = MathDot(normal, Vector2Subtract(support, vertex));
|
||||||
|
|
||||||
// Store greatest distance
|
// Store greatest distance
|
||||||
if (distance > bestDistance)
|
if (distance > bestDistance)
|
||||||
|
|
@ -1857,10 +1857,10 @@ static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, Physics
|
||||||
|
|
||||||
// Assign face vertices for incident face
|
// Assign face vertices for incident face
|
||||||
*v0 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
|
*v0 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
|
||||||
*v0 = Vector2AddV(*v0, inc.body->position);
|
*v0 = Vector2Add(*v0, inc.body->position);
|
||||||
incidentFace = (((incidentFace + 1) < incData.vertexCount) ? (incidentFace + 1) : 0);
|
incidentFace = (((incidentFace + 1) < incData.vertexCount) ? (incidentFace + 1) : 0);
|
||||||
*v1 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
|
*v1 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
|
||||||
*v1 = Vector2AddV(*v1, inc.body->position);
|
*v1 = Vector2Add(*v1, inc.body->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculates clipping based on a normal and two faces
|
// Calculates clipping based on a normal and two faces
|
||||||
|
|
@ -1883,10 +1883,10 @@ static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB)
|
||||||
// Push intersection point
|
// Push intersection point
|
||||||
float alpha = distanceA/(distanceA - distanceB);
|
float alpha = distanceA/(distanceA - distanceB);
|
||||||
out[sp] = *faceA;
|
out[sp] = *faceA;
|
||||||
Vector2 delta = Vector2SubtractV(*faceB, *faceA);
|
Vector2 delta = Vector2Subtract(*faceB, *faceA);
|
||||||
delta.x *= alpha;
|
delta.x *= alpha;
|
||||||
delta.y *= alpha;
|
delta.y *= alpha;
|
||||||
out[sp] = Vector2AddV(out[sp], delta);
|
out[sp] = Vector2Add(out[sp], delta);
|
||||||
sp++;
|
sp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1993,7 +1993,7 @@ static inline float MathDot(Vector2 v1, Vector2 v2)
|
||||||
// Returns the square root of distance between two vectors
|
// Returns the square root of distance between two vectors
|
||||||
static inline float DistSqr(Vector2 v1, Vector2 v2)
|
static inline float DistSqr(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
Vector2 dir = Vector2SubtractV(v1, v2);
|
Vector2 dir = Vector2Subtract(v1, v2);
|
||||||
return MathDot(dir, dir);
|
return MathDot(dir, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2015,13 +2015,13 @@ static void MathNormalize(Vector2 *vector)
|
||||||
|
|
||||||
#if defined(PHYSAC_STANDALONE)
|
#if defined(PHYSAC_STANDALONE)
|
||||||
// Returns the sum of two given vectors
|
// Returns the sum of two given vectors
|
||||||
static inline Vector2 Vector2AddV(Vector2 v1, Vector2 v2)
|
static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
return (Vector2){ v1.x + v2.x, v1.y + v2.y };
|
return (Vector2){ v1.x + v2.x, v1.y + v2.y };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the subtract of two given vectors
|
// Returns the subtract of two given vectors
|
||||||
static inline Vector2 Vector2SubtractV(Vector2 v1, Vector2 v2)
|
static inline Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
return (Vector2){ v1.x - v2.x, v1.y - v2.y };
|
return (Vector2){ v1.x - v2.x, v1.y - v2.y };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,28 +173,28 @@ RMDEF Vector2 Vector2One(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add two vectors (v1 + v2)
|
// Add two vectors (v1 + v2)
|
||||||
RMDEF Vector2 Vector2AddV(Vector2 v1, Vector2 v2)
|
RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
Vector2 result = { v1.x + v2.x, v1.y + v2.y };
|
Vector2 result = { v1.x + v2.x, v1.y + v2.y };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add vector and float value
|
// Add vector and float value
|
||||||
RMDEF Vector2 Vector2Add(Vector2 v, float add)
|
RMDEF Vector2 Vector2AddValue(Vector2 v, float add)
|
||||||
{
|
{
|
||||||
Vector2 result = { v.x + add, v.y + add };
|
Vector2 result = { v.x + add, v.y + add };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract two vectors (v1 - v2)
|
// Subtract two vectors (v1 - v2)
|
||||||
RMDEF Vector2 Vector2SubtractV(Vector2 v1, Vector2 v2)
|
RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
Vector2 result = { v1.x - v2.x, v1.y - v2.y };
|
Vector2 result = { v1.x - v2.x, v1.y - v2.y };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract vector by float value
|
// Subtract vector by float value
|
||||||
RMDEF Vector2 Vector2Subtract(Vector2 v, float sub)
|
RMDEF Vector2 Vector2SubtractValue(Vector2 v, float sub)
|
||||||
{
|
{
|
||||||
Vector2 result = { v.x - sub, v.y - sub };
|
Vector2 result = { v.x - sub, v.y - sub };
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -237,19 +237,12 @@ RMDEF Vector2 Vector2Scale(Vector2 v, float scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply vector by vector
|
// Multiply vector by vector
|
||||||
RMDEF Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2)
|
RMDEF Vector2 Vector2Multiply(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
Vector2 result = { v1.x*v2.x, v1.y*v2.y };
|
Vector2 result = { v1.x*v2.x, v1.y*v2.y };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply vector by float value
|
|
||||||
RMDEF Vector2 Vector2Multiply(Vector2 v, float mul)
|
|
||||||
{
|
|
||||||
Vector2 result = { v.x*mul, v.y*mul };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Negate vector
|
// Negate vector
|
||||||
RMDEF Vector2 Vector2Negate(Vector2 v)
|
RMDEF Vector2 Vector2Negate(Vector2 v)
|
||||||
{
|
{
|
||||||
|
|
@ -258,14 +251,14 @@ RMDEF Vector2 Vector2Negate(Vector2 v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide vector by a float value
|
// Divide vector by a float value
|
||||||
RMDEF Vector2 Vector2Divide(Vector2 v, float div)
|
RMDEF Vector2 Vector2DivideValue(Vector2 v, float div)
|
||||||
{
|
{
|
||||||
Vector2 result = { v.x/div, v.y/div };
|
Vector2 result = { v.x/div, v.y/div };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide vector by vector
|
// Divide vector by vector
|
||||||
RMDEF Vector2 Vector2DivideV(Vector2 v1, Vector2 v2)
|
RMDEF Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
|
||||||
{
|
{
|
||||||
Vector2 result = { v1.x/v2.x, v1.y/v2.y };
|
Vector2 result = { v1.x/v2.x, v1.y/v2.y };
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -274,7 +267,7 @@ RMDEF Vector2 Vector2DivideV(Vector2 v1, Vector2 v2)
|
||||||
// Normalize provided vector
|
// Normalize provided vector
|
||||||
RMDEF Vector2 Vector2Normalize(Vector2 v)
|
RMDEF Vector2 Vector2Normalize(Vector2 v)
|
||||||
{
|
{
|
||||||
Vector2 result = Vector2Divide(v, Vector2Length(v));
|
Vector2 result = Vector2DivideValue(v, Vector2Length(v));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,28 +309,28 @@ RMDEF Vector3 Vector3One(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add two vectors
|
// Add two vectors
|
||||||
RMDEF Vector3 Vector3AddV(Vector3 v1, Vector3 v2)
|
RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
Vector3 result = { v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
|
Vector3 result = { v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add vector and float value
|
// Add vector and float value
|
||||||
RMDEF Vector3 Vector3Add(Vector3 v, float add)
|
RMDEF Vector3 Vector3AddValue(Vector3 v, float add)
|
||||||
{
|
{
|
||||||
Vector3 result = { v.x + add, v.y + add, v.z + add };
|
Vector3 result = { v.x + add, v.y + add, v.z + add };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract two vectors
|
// Subtract two vectors
|
||||||
RMDEF Vector3 Vector3SubtractV(Vector3 v1, Vector3 v2)
|
RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
Vector3 result = { v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
|
Vector3 result = { v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract vector by float value
|
// Subtract vector by float value
|
||||||
RMDEF Vector3 Vector3Subtract(Vector3 v, float sub)
|
RMDEF Vector3 Vector3SubtractValue(Vector3 v, float sub)
|
||||||
{
|
{
|
||||||
Vector3 result = { v.x - sub, v.y - sub, v.z - sub };
|
Vector3 result = { v.x - sub, v.y - sub, v.z - sub };
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -351,19 +344,12 @@ RMDEF Vector3 Vector3Scale(Vector3 v, float scalar)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply vector by vector
|
// Multiply vector by vector
|
||||||
RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2)
|
RMDEF Vector3 Vector3Multiply(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
Vector3 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z };
|
Vector3 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply vector by float value
|
|
||||||
RMDEF Vector3 Vector3Multiply(Vector3 v, float mul)
|
|
||||||
{
|
|
||||||
Vector3 result = { v.x*mul, v.y*mul, v.z*mul };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate two vectors cross product
|
// Calculate two vectors cross product
|
||||||
RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
|
RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
|
|
@ -429,14 +415,14 @@ RMDEF Vector3 Vector3Negate(Vector3 v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide vector by a float value
|
// Divide vector by a float value
|
||||||
RMDEF Vector3 Vector3Divide(Vector3 v, float div)
|
RMDEF Vector3 Vector3DivideValue(Vector3 v, float div)
|
||||||
{
|
{
|
||||||
Vector3 result = { v.x / div, v.y / div, v.z / div };
|
Vector3 result = { v.x / div, v.y / div, v.z / div };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide vector by vector
|
// Divide vector by vector
|
||||||
RMDEF Vector3 Vector3DivideV(Vector3 v1, Vector3 v2)
|
RMDEF Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
|
Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -557,9 +543,9 @@ RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
|
||||||
{
|
{
|
||||||
//Vector v0 = b - a, v1 = c - a, v2 = p - a;
|
//Vector v0 = b - a, v1 = c - a, v2 = p - a;
|
||||||
|
|
||||||
Vector3 v0 = Vector3SubtractV(b, a);
|
Vector3 v0 = Vector3Subtract(b, a);
|
||||||
Vector3 v1 = Vector3SubtractV(c, a);
|
Vector3 v1 = Vector3Subtract(c, a);
|
||||||
Vector3 v2 = Vector3SubtractV(p, a);
|
Vector3 v2 = Vector3Subtract(p, a);
|
||||||
float d00 = Vector3DotProduct(v0, v0);
|
float d00 = Vector3DotProduct(v0, v0);
|
||||||
float d01 = Vector3DotProduct(v0, v1);
|
float d01 = Vector3DotProduct(v0, v1);
|
||||||
float d11 = Vector3DotProduct(v1, v1);
|
float d11 = Vector3DotProduct(v1, v1);
|
||||||
|
|
@ -1024,7 +1010,7 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
|
||||||
{
|
{
|
||||||
Matrix result = { 0 };
|
Matrix result = { 0 };
|
||||||
|
|
||||||
Vector3 z = Vector3SubtractV(eye, target);
|
Vector3 z = Vector3Subtract(eye, target);
|
||||||
z = Vector3Normalize(z);
|
z = Vector3Normalize(z);
|
||||||
Vector3 x = Vector3CrossProduct(up, z);
|
Vector3 x = Vector3CrossProduct(up, z);
|
||||||
x = Vector3Normalize(x);
|
x = Vector3Normalize(x);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user