-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathOrientedSprite.cpp
66 lines (57 loc) · 1.82 KB
/
OrientedSprite.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
#include "Object.h"
#include "OrientedSprite.h"
#include "../render/IDriver3D.h"
OrientedSprite::OrientedSprite() : RenderComponent()
{
m_hTex = XL_INVALID_TEXTURE;
m_aFlip[0] = 0;
m_aFlip[1] = 0;
m_aFlip[2] = 0;
m_fBaseItens = 1.0f;
m_fAlpha = 1.0f;
}
void OrientedSprite::Render(Object *pObj, IDriver3D *pDriver, float fIntensity, const Vector3& vOffset)
{
pDriver->SetTexture(0, m_hTex, IDriver3D::FILTER_NORMAL_NO_MIP, false);
ObjectPhysicsData *pData = pObj->GetPhysicsData();
Vector3 vRight;
vRight.CrossAndNormalize(pData->m_Dir, pData->m_Up);
Vector3 A, B;
A = pData->m_Loc - vRight*pData->m_Scale - pData->m_Up*pData->m_Scale + vOffset;
B = pData->m_Loc + vRight*pData->m_Scale + pData->m_Up*pData->m_Scale + vOffset;
Vector3 posList[4];
Vector2 uvList[4];
if ( pData->m_Up.z > 0.7071f )
{
posList[0].Set(A.x, A.y, A.z);
posList[1].Set(B.x, B.y, A.z);
posList[2].Set(B.x, B.y, B.z);
posList[3].Set(A.x, A.y, B.z);
}
else
{
posList[0].Set(A.x, A.y, A.z);
posList[1].Set(B.x, A.y, A.z);
posList[2].Set(B.x, B.y, B.z);
posList[3].Set(A.x, B.y, B.z);
}
Vector2 uv0(m_aFlip[0]?1.0f:0.0f, m_aFlip[1]?0.0f:1.0f);
Vector2 uv1(m_aFlip[0]?0.0f:1.0f, m_aFlip[1]?1.0f:0.0f);
if ( m_aFlip[2] )
{
uvList[0].Set( uv0.y, uv0.x );
uvList[1].Set( uv0.y, uv1.x );
uvList[2].Set( uv1.y, uv1.x );
uvList[3].Set( uv1.y, uv0.x );
}
else
{
uvList[0].Set( uv0.x, uv0.y );
uvList[1].Set( uv1.x, uv0.y );
uvList[2].Set( uv1.x, uv1.y );
uvList[3].Set( uv0.x, uv1.y );
}
fIntensity *= m_fBaseItens;
Vector4 color(fIntensity, fIntensity, fIntensity, m_fAlpha);
pDriver->RenderWorldQuad( posList, uvList, color );
}