mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
simplify vector3 code a bit for C client
This commit is contained in:
parent
e54475e09f
commit
c92b53bc79
@ -97,7 +97,7 @@ void Block_SetDrawType(BlockID block, UInt8 draw) {
|
||||
Block_Draw[block] = draw;
|
||||
Block_RecalcIsLiquid(block);
|
||||
|
||||
Vector3 zero = Vector3_Zero, one = Vector3_One;
|
||||
Vector3 zero = Vector3_Zero; Vector3 one = Vector3_One;
|
||||
Block_FullOpaque[block] = draw == DRAW_OPAQUE
|
||||
&& Vector3_Equals(&Block_MinBB[block], &zero)
|
||||
&& Vector3_Equals(&Block_MaxBB[block], &one);
|
||||
@ -160,9 +160,9 @@ void Block_ResetProps(BlockID block) {
|
||||
if (Block_Draw[block] == DRAW_SPRITE) {
|
||||
Block_MinBB[block] = Vector3_Create3(2.50f / 16.0f, 0.0f, 2.50f / 16.0f);
|
||||
Block_MaxBB[block] = Vector3_Create3(13.5f / 16.0f, 1.0f, 13.5f / 16.0f);
|
||||
} else {
|
||||
Block_MinBB[block] = Vector3_Zero;
|
||||
Block_MaxBB[block] = Vector3_One;
|
||||
} else {
|
||||
Vector3 zero = Vector3_Zero; Block_MinBB[block] = zero;
|
||||
Vector3 one = Vector3_One; Block_MaxBB[block] = one;
|
||||
Block_MaxBB[block].Y = DefaultSet_Height(block);
|
||||
}
|
||||
|
||||
|
@ -134,10 +134,10 @@ void PerspectiveCamera_Init(Camera* cam) {
|
||||
void FirstPersonCamera_GetView(Matrix* mat) {
|
||||
Vector3 camPos = Game_CurrentCameraPos;
|
||||
Vector3 dir = PerspectiveCamera_GetDirVector();
|
||||
Vector3 targetPos;
|
||||
Vector3_Add(&targetPos, &camPos, &dir);
|
||||
Vector3 targetPos; Vector3_Add(&targetPos, &camPos, &dir);
|
||||
|
||||
Matrix_LookAt(mat, camPos, targetPos, Vector3_UnitY);
|
||||
Vector3 up = Vector3_UnitY;
|
||||
Matrix_LookAt(mat, camPos, targetPos, up);
|
||||
Matrix_MulBy(mat, &Camera_TiltM);
|
||||
}
|
||||
|
||||
@ -177,7 +177,8 @@ void ThirdPersonCamera_GetView(Matrix* mat) {
|
||||
Vector3 targetPos = Entity_GetEyePosition(p);
|
||||
targetPos.Y += Camera_BobbingVer;
|
||||
|
||||
Matrix_LookAt(mat, cameraPos, targetPos, Vector3_UnitY);
|
||||
Vector3 up = Vector3_UnitY;
|
||||
Matrix_LookAt(mat, cameraPos, targetPos, up);
|
||||
Matrix_MulBy(mat, &Camera_TiltM);
|
||||
}
|
||||
|
||||
|
@ -534,7 +534,7 @@ void ShadowComponent_CalcAlpha(Real32 playerY, ShadowData* data) {
|
||||
|
||||
bool ShadowComponent_GetBlocks(Entity* entity, Vector3I* coords, Real32 x, Real32 z, Int32 posY, ShadowData* data) {
|
||||
Int32 blockX = Math_Floor(x), blockZ = Math_Floor(z);
|
||||
Vector3I p = Vector3I_Create3(blockX, 0, blockZ);
|
||||
Vector3I p = VECTOR3I_CONST(blockX, 0, blockZ);
|
||||
|
||||
/* Check we have not processed this particular block already */
|
||||
UInt32 i, posCount = 0;
|
||||
|
@ -1136,8 +1136,8 @@ void BlockModel_RecalcProperties(Entity* p) {
|
||||
Real32 height;
|
||||
|
||||
if (Block_Draw[block] == DRAW_GAS) {
|
||||
BlockModel_minBB = Vector3_Zero;
|
||||
BlockModel_maxBB = Vector3_One;
|
||||
Vector3 zero = Vector3_Zero; BlockModel_minBB = zero;
|
||||
Vector3 one = Vector3_One; BlockModel_maxBB = one;
|
||||
height = 1.0f;
|
||||
} else {
|
||||
BlockModel_minBB = Block_MinBB[block];
|
||||
|
@ -66,7 +66,7 @@ BlockID Particle_GetBlock(Int32 x, Int32 y, Int32 z) {
|
||||
bool Particle_TestY(Particle* p, Int32 y, bool topFace, bool throughLiquids) {
|
||||
if (y < 0) {
|
||||
p->NextPos.Y = ENTITY_ADJUSTMENT; p->LastPos.Y = ENTITY_ADJUSTMENT;
|
||||
p->Velocity = Vector3_Zero;
|
||||
Vector3 zero = Vector3_Zero; p->Velocity = zero;
|
||||
p->HitTerrain = true;
|
||||
return false;
|
||||
}
|
||||
@ -82,7 +82,7 @@ bool Particle_TestY(Particle* p, Int32 y, bool topFace, bool throughLiquids) {
|
||||
Real32 adjust = topFace ? ENTITY_ADJUSTMENT : -ENTITY_ADJUSTMENT;
|
||||
p->LastPos.Y = collideY + adjust;
|
||||
p->NextPos.Y = p->LastPos.Y;
|
||||
p->Velocity = Vector3_Zero;
|
||||
Vector3 zero = Vector3_Zero; p->Velocity = zero;
|
||||
p->HitTerrain = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
#include "Funcs.h"
|
||||
#include "Platform.h"
|
||||
|
||||
Real32 PickedPos_dist;
|
||||
void PickedPos_TestAxis(PickedPos* pos, Real32 dAxis, Face fAxis) {
|
||||
@ -16,11 +17,12 @@ void PickedPos_TestAxis(PickedPos* pos, Real32 dAxis, Face fAxis) {
|
||||
}
|
||||
|
||||
void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) {
|
||||
Vector3I blockPos = VECTOR3I_CONST(t->X, t->Y, t->Z);
|
||||
pos->Valid = true;
|
||||
pos->BlockPos = blockPos;
|
||||
pos->Block = t->Block;
|
||||
pos->Intersect = intersect;
|
||||
pos->Min = t->Min; pos->Max = t->Max;
|
||||
pos->BlockPos = Vector3I_Create3(t->X, t->Y, t->Z);
|
||||
pos->Valid = true;
|
||||
pos->Block = t->Block;
|
||||
pos->Intersect = intersect;
|
||||
|
||||
PickedPos_dist = MATH_LARGENUM;
|
||||
PickedPos_TestAxis(pos, intersect.X - t->Min.X, FACE_XMIN);
|
||||
@ -30,22 +32,24 @@ void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) {
|
||||
PickedPos_TestAxis(pos, intersect.Z - t->Min.Z, FACE_ZMIN);
|
||||
PickedPos_TestAxis(pos, intersect.Z - t->Max.Z, FACE_ZMAX);
|
||||
|
||||
Vector3I offsets[FACE_COUNT];
|
||||
offsets[FACE_XMIN] = Vector3I_Create3(-1, 0, 0);
|
||||
offsets[FACE_XMAX] = Vector3I_Create3(+1, 0, 0);
|
||||
offsets[FACE_ZMIN] = Vector3I_Create3(0, 0, -1);
|
||||
offsets[FACE_ZMAX] = Vector3I_Create3(0, 0, +1);
|
||||
offsets[FACE_YMIN] = Vector3I_Create3(0, -1, 0);
|
||||
offsets[FACE_YMAX] = Vector3I_Create3(0, +1, 0);
|
||||
Vector3I_Add(&pos->TranslatedPos, &pos->BlockPos, &offsets[pos->ClosestFace]);
|
||||
switch (pos->ClosestFace) {
|
||||
case FACE_XMIN: blockPos.X--; break;
|
||||
case FACE_XMAX: blockPos.X++; break;
|
||||
case FACE_ZMIN: blockPos.Z--; break;
|
||||
case FACE_ZMAX: blockPos.Z++; break;
|
||||
case FACE_YMIN: blockPos.Y--; break;
|
||||
case FACE_YMAX: blockPos.Y++; break;
|
||||
}
|
||||
pos->TranslatedPos = blockPos;
|
||||
}
|
||||
|
||||
void PickedPos_SetAsInvalid(PickedPos* pos) {
|
||||
pos->Valid = false;
|
||||
pos->BlockPos = Vector3I_MinusOne;
|
||||
pos->TranslatedPos = Vector3I_MinusOne;
|
||||
pos->ClosestFace = (Face)FACE_COUNT;
|
||||
pos->Block = BLOCK_AIR;
|
||||
Vector3I blockPos = VECTOR3I_CONST(-1, -1, -1);
|
||||
pos->Valid = false;
|
||||
pos->BlockPos = blockPos;
|
||||
pos->Block = BLOCK_AIR;
|
||||
pos->ClosestFace = (Face)FACE_COUNT;
|
||||
pos->TranslatedPos = blockPos;
|
||||
}
|
||||
|
||||
Real32 RayTracer_Div(Real32 a, Real32 b) {
|
||||
|
@ -21,23 +21,12 @@ Real32 Vector3_Length(Vector3* v);
|
||||
Real32 Vector3_LengthSquared(Vector3* v);
|
||||
|
||||
#define VECTOR3_CONST(x, y, z) { x, y, z };
|
||||
#define Vector2_UnitX Vector2_Create2(1.0f, 0.0f)
|
||||
#define Vector2_UnitY Vector2_Create2(0.0f, 1.0f)
|
||||
#define Vector2_Zero Vector2_Create2(0.0f, 0.0f)
|
||||
#define Vector2_One Vector2_Create2(1.0f, 1.0f)
|
||||
|
||||
#define Vector3_UnitX Vector3_Create3(1.0f, 0.0f, 0.0f)
|
||||
#define Vector3_UnitY Vector3_Create3(0.0f, 1.0f, 0.0f)
|
||||
#define Vector3_UnitZ Vector3_Create3(0.0f, 0.0f, 1.0f)
|
||||
#define Vector3_Zero Vector3_Create3(0.0f, 0.0f, 0.0f)
|
||||
#define Vector3_One Vector3_Create3(1.0f, 1.0f, 1.0f)
|
||||
|
||||
#define Vector3I_UnitX Vector3I_Create3(1, 0, 0)
|
||||
#define Vector3I_UnitY Vector3I_Create3(0, 1, 0)
|
||||
#define Vector3I_UnitZ Vector3I_Create3(0, 0, 1)
|
||||
#define Vector3I_Zero Vector3I_Create3(0, 0, 0)
|
||||
#define Vector3I_One Vector3I_Create3(1, 1, 1)
|
||||
#define Vector3I_MinusOne Vector3I_Create3(-1, -1, -1)
|
||||
#define VECTOR3I_CONST(x, y, z) { x, y, z };
|
||||
#define Vector3_UnitX VECTOR3_CONST(1.0f, 0.0f, 0.0f)
|
||||
#define Vector3_UnitY VECTOR3_CONST(0.0f, 1.0f, 0.0f)
|
||||
#define Vector3_UnitZ VECTOR3_CONST(0.0f, 0.0f, 1.0f)
|
||||
#define Vector3_Zero VECTOR3_CONST(0.0f, 0.0f, 0.0f)
|
||||
#define Vector3_One VECTOR3_CONST(1.0f, 1.0f, 1.0f)
|
||||
|
||||
void Vector3_Add(Vector3* result, Vector3* a, Vector3* b);
|
||||
void Vector3I_Add(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
|
Loading…
x
Reference in New Issue
Block a user