Blixibon c5f3fa0778 Mapbase v3.0
- Overhauled matcher system and added expanded wildcard support, meaning "text", "te?t", "blah_test", etc. are now supported instead of only trailing *
- Added support for regular expression matching
- Added the missing matrixinvert.h file, which prevented programmers from compiling vbsp
- Fixed env_global_light brightness
- Added info_player_view_proxy, an entity which mimics a player's view (created for script_intro)
- New UnZoomWithRate and SetZoomRate inputs on env_zoom
- New "Don't change target's angles" flag on logic_measure_movement
- Fixed logic_measure_movement not using ignore origin flags correctly
- Fixed filter_damage_mod secondary filter not recognizing mode correctly
- Fixed DisableGeigerCounter causing NPCs to ignore player, and possibly fixed other adverse effects in similar code
- Added SetEntityName input for setting an entity's targetname
- Added "SetTarget" support to point_posecontroller
- Added "sk_alyx_health" convar for adjustable npc_alyx health, restored/fixed "sk_barney_health" for adjustable npc_barney health
- Added ignore flags and several direction-related inputs to math_vector
- Added pose parameter stuff to logic_modelinfo
- Fixed ChangeWeapon not changing during combat
- Fixed holster/unholster on NPCs without holster/unholster animations
- Fixed func_tank and other "player in the way" code ignoring notarget
- Added SetPoseParameter input to animating entities
- Introduced an experimental chapter system which allows for custom chapter title/restriction management
- Added SetChapterTitle input to worldspawn for dynamic title changing
- Fixed func_tankairboatgun damage credit, added ability to use its damage keyvalues
- Fixed mapbase_rpc_enabled not actually affecting RPC
- Moved some newly found Combine soldier grenade code to ai_grenade for other grenade users
- Fixed some problems with the new shared activities
- Restored an old Mapbase entity as "prop_interactable", an entity which contains all of the functionality of a func_button/func_door in a prop entity
- Added env_microphone pitch scale for scaling the pitch of transmitted sounds
- Added experimental, long-overdue code for scenes to be able to access !target#'s and other scene-related names through AI_INPUT
- Added "mat_specular_disable_on_missing", which "disables" specular reflections when the cubemap texture is missing
- Fixed $envmapmasktransform and $bumptransform on VertexLitGeneric and related shaders
- Areaportal leaks now stop compilation in leaktest
- Replaced "-nodefaultcubemap" with "-defaultcubemap" as the shader changes allow maps to compile without default cubemaps by default with little effect
2020-02-05 19:08:49 +00:00

117 lines
2.5 KiB
C

// By Jason Yu-Tseh Chi
// From http://chi3x10.wordpress.com/2008/05/28/calculate-matrix-inversion-in-c/
// Modified to work with valve's matrix_3x4_t
#include "mathlib\mathlib.h"
// Calculate the cofactor of element (row,col)
int GetMatrixMinor(float **src, float **dest, int row, int col, int order)
{
// Indicate which col and row is being copied to dest
int colCount = 0, rowCount = 0;
for (int i = 0; i < order; i++)
{
if (i != row)
{
colCount = 0;
for (int j = 0; j < order; j++)
{
// When j is not the element
if (j != col)
{
dest[rowCount][colCount] = src[i][j];
colCount++;
}
}
rowCount++;
}
}
return 1;
}
// Calculate the determinant recursively.
double CalcMatrixDeterminant(float **mat, int order)
{
// Order must be >= 0
// Stop the recursion when matrix is a single element
if (order == 1)
return mat[0][0];
// The determinant value
float det = 0;
// Allocate the cofactor matrix
float **minor;
minor = new float*[order - 1];
for (int i = 0; i<order - 1; i++)
minor[i] = new float[order - 1];
for (int i = 0; i < order; i++)
{
// Get minor of element (0,i)
GetMatrixMinor(mat, minor, 0, i, order);
// The recusion is here!
det += (i % 2 == 1 ? -1.0 : 1.0) * mat[0][i] * CalcMatrixDeterminant(minor, order - 1);
//det += pow( -1.0, i ) * mat[0][i] * CalcMatrixDeterminant( minor,order-1 );
}
// Release memory
for (int i = 0; i<order - 1; i++)
delete[] minor[i];
delete[] minor;
return det;
}
// Matrix inversion
void MatrixInversion(matrix3x4_t &in, matrix3x4_t &out)
{
float **A;
A = new float*[4];
for (int i = 0; i < 4; i++)
A[i] = new float[4];
int order = 4;
// Load in into A
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
A[i][j] = in[i][j];
}
}
A[3][0] = A[3][1] = A[3][2] = 0;
A[3][3] = 1;
// Get the determinant of a
double det = 1.0 / CalcMatrixDeterminant((float**)A, order);
// Memory allocation
float *temp = new float[(order - 1)*(order - 1)];
float **minor = new float*[order - 1];
for (int i = 0; i<order - 1; i++)
minor[i] = temp + (i*(order - 1));
for (int j = 0; j<order; j++)
{
for (int i = 0; i<order; i++)
{
// Get the co-factor (matrix) of A(j,i)
GetMatrixMinor((float**)A, minor, j, i, order);
out[i][j] = det*CalcMatrixDeterminant(minor, order - 1);
if ((i + j) % 2 == 1)
out[i][j] = -out[i][j];
}
}
// Release memory
for (int i = 0; i < 4; i++)
delete A[i];
delete A;
//delete [] minor[0];
delete[] temp;
delete[] minor;
}