forked from perilouswithadollarsign/cstrike15_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbumpvects.cpp
69 lines (57 loc) · 1.65 KB
/
bumpvects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#if !defined(_STATIC_LINKED) || defined(_SHARED_LIB)
#ifdef QUIVER
#include "r_local.h"
#endif
#include "mathlib/bumpvects.h"
#include "mathlib/vector.h"
#include <assert.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// z is coming out of the face.
void GetBumpNormals( const Vector& sVect, const Vector& tVect, const Vector& flatNormal,
const Vector& phongNormal, Vector bumpNormals[NUM_BUMP_VECTS] )
{
Vector tmpNormal;
bool leftHanded;
int i;
assert( NUM_BUMP_VECTS == 3 );
// Are we left or right handed?
CrossProduct( sVect, tVect, tmpNormal );
if( DotProduct( flatNormal, tmpNormal ) < 0.0f )
{
leftHanded = true;
}
else
{
leftHanded = false;
}
// Build a basis for the face around the phong normal
matrix3x4_t smoothBasis;
CrossProduct( phongNormal.Base(), sVect.Base(), smoothBasis[1] );
VectorNormalize( smoothBasis[1] );
CrossProduct( smoothBasis[1], phongNormal.Base(), smoothBasis[0] );
VectorNormalize( smoothBasis[0] );
VectorCopy( phongNormal.Base(), smoothBasis[2] );
if( leftHanded )
{
VectorNegate( smoothBasis[1] );
}
// move the g_localBumpBasis into world space to create bumpNormals
for( i = 0; i < 3; i++ )
{
VectorIRotate( g_localBumpBasis[i], smoothBasis, bumpNormals[i] );
}
}
#endif // !_STATIC_LINKED || _SHARED_LIB