Skip to content

Commit

Permalink
Cubic interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
BSVino committed Feb 21, 2016
1 parent 49196d4 commit d2b7f5c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions common/strutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,17 @@ inline std::string sprintf(std::string s, ...)
if(iCharacters >= (int)q.length())
{
q.resize(iCharacters*2);

va_start(arguments, s);
iCharacters = VSNPRINTF8(&q[0], q.size()-1, s.c_str(), arguments);
}
else if(iCharacters < 0)
{
while (iCharacters < 0)
{
q.resize(q.size()*2);

va_start(arguments, s);
iCharacters = VSNPRINTF8(&q[0], q.size()-1, s.c_str(), arguments);
}
}
Expand Down
2 changes: 1 addition & 1 deletion content/shaders/model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void main()

// Add in a diffuse if there is one. http://youtu.be/aw6Vi-_hwy0
if (bDiffuse)
vecDiffuse *= texture(iDiffuse, vecFragmentTexCoord0);
vecDiffuse = vecColor * texture(iDiffuse, vecFragmentTexCoord0);

// Add in some fog. http://youtu.be/YpKVXNPOXg8
float flDistance = flToCameraLength;
Expand Down
2 changes: 1 addition & 1 deletion game/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void CCharacter::BuildTransform()
// Produce a transformation matrix from our three TRS matrices.
// Order matters! http://youtu.be/7pe1xYzFCvA
Matrix4x4 mScaling, mRotation, mTranslation;
mScaling.SetScale(m_vecScaling);
//mScaling.SetScale(m_vecScaling);
mRotation.SetRotation(m_flRotationTheta, m_vecRotationAxis);
mTranslation.SetTranslation(m_vecTranslation);
SetGlobalTransform(mTranslation * mRotation * mScaling);
Expand Down
30 changes: 26 additions & 4 deletions game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ bool CGame::TraceLine(const Vector& v0, const Vector& v1, Vector& vecIntersectio

Matrix4x4 mInverse = pCharacter->GetGlobalTransform().InvertedTR();

Matrix4x4 scale;
scale.SetScale(1/pCharacter->m_vecScaling);

mInverse = scale*mInverse;

// The v0 and v1 are in the global coordinate system and we need to transform it to the target's
// local coordinate system to use axis-aligned intersection. We do so using the inverse transform matrix.
// http://youtu.be/-Fn4atv2NsQ
Expand Down Expand Up @@ -360,6 +365,19 @@ void CGame::Update(float dt)
pCharacter->m_vecVelocity = (m_hPlayer->GetGlobalOrigin() - pCharacter->GetGlobalOrigin()).Normalized() * flMonsterSpeed;

pCharacter->SetTranslation(pCharacter->GetGlobalOrigin() + pCharacter->m_vecVelocity * dt);

if (pCharacter->m_flShotTime >= 0)
{
float lerp = RemapClamp(Game()->GetTime(),
pCharacter->m_flShotTime, pCharacter->m_flShotTime + 2,
0, 1);

lerp = CubicInterpolation(lerp);

float size = RemapClamp(lerp, 0, 1, 2, 5);

pCharacter->m_vecScaling = Vector(size, size, size);
}
}

/*
Expand Down Expand Up @@ -606,7 +624,11 @@ void CGame::DrawCharacters(const std::vector<CCharacter*>& apRenderList, bool bT
c.SetBlend(BLEND_ALPHA);
}

c.LoadTransform(pCharacter->GetGlobalTransform());
Matrix4x4 transform = pCharacter->GetGlobalTransform();
Matrix4x4 scale;
scale.SetScale(pCharacter->m_vecScaling);
transform *= scale;
c.LoadTransform(transform);
c.Translate(Vector(0, pCharacter->m_aabbSize.GetHeight()/2, 0)); // Move the character up so his feet don't stick in the ground.
pCharacter->ShotEffect(&c);
c.RenderBillboard(pCharacter->m_iBillboardTexture, pCharacter->m_aabbSize.vecMax.x, vecUp, vecRight);
Expand Down Expand Up @@ -729,7 +751,7 @@ void CGame::GameLoop()
Vector vecMonsterMin = Vector(-1, 0, -1);
Vector vecMonsterMax = Vector(1, 2, 1);

/*CCharacter* pTarget1 = CreateCharacter();
CCharacter* pTarget1 = CreateCharacter();
pTarget1->SetTransform(Vector(2, 2, 2), 0, Vector(0, 1, 0), Vector(6, 0, 6));
pTarget1->m_aabbSize.vecMin = vecMonsterMin;
pTarget1->m_aabbSize.vecMax = vecMonsterMax;
Expand All @@ -746,12 +768,12 @@ void CGame::GameLoop()
pTarget2->m_bTakesDamage = true;

CCharacter* pTarget3 = CreateCharacter();
pTarget3->SetTransform(Vector(3, 3, 3), 0, Vector(0, 1, 0), Vector(-6, 0, 8));
pTarget3->SetTransform(Vector(2, 2, 2), 0, Vector(0, 1, 0), Vector(-6, 0, 8));
pTarget3->m_aabbSize.vecMin = vecMonsterMin;
pTarget3->m_aabbSize.vecMax = vecMonsterMax;
pTarget3->m_iBillboardTexture = m_iMonsterTexture;
pTarget3->m_bEnemyAI = true;
pTarget3->m_bTakesDamage = true;*/
pTarget3->m_bTakesDamage = true;

Vector vecPropMin = Vector(-.1f, 0, -.1f);
Vector vecPropMax = Vector(.1f, .2f, .1f);
Expand Down
7 changes: 7 additions & 0 deletions math/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ inline float TriangleWave(float flTime, float flLength)
// The negative values are flipped to positive, so that you have a triangle wave on [0, 1]: /\/\/\/\/
return fabs(flRemapped);
}

inline float CubicInterpolation(float t)
{
return -2*t*t*t + 3*t*t;
}


2 changes: 0 additions & 2 deletions renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ size_t CRenderer::LoadTextureIntoGL(string sFilename, int iClamp)

size_t CRenderer::LoadTextureIntoGL(unsigned char* pclrData, int x, int y, int iClamp, bool bNearestFiltering)
{
GLCall(glEnable(GL_TEXTURE_2D));

GLuint iGLId;
GLCall(glGenTextures(1, &iGLId));
GLCall(glBindTexture(GL_TEXTURE_2D, iGLId));
Expand Down
1 change: 0 additions & 1 deletion renderer/renderingcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ void CRenderingContext::UseProgram(class CShader* pShader)
void CRenderingContext::SetUniform(const char* pszName, int iValue)
{
int iUniform = glGetUniformLocation((GLuint)m_iProgram, pszName);
TAssert(iUniform > 0);
GLCall(glUniform1i(iUniform, iValue));
}

Expand Down

0 comments on commit d2b7f5c

Please sign in to comment.