Last active
August 4, 2016 14:51
-
-
Save Echooff3/63060187150fd3d00db8cdc024b43671 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class InterpolatedInt | |
{ | |
private float _currentValue = 0.0f; | |
private float _targetValue = 0.0f; | |
private float _percent = 1.0f; | |
public float easingValue = 0.25f; | |
public InterpolatedInt () | |
{ | |
} | |
public void update(float rate) { | |
if(_currentValue == _targetValue) return; | |
_percent += rate; | |
if (_percent > 1.0f) { | |
_percent = 1.0f; | |
} | |
//Xinterpolated = Xinital + InterpolationPercent * (Xfinal - Xinital) | |
_currentValue = _currentValue + _percent * ((_targetValue - _currentValue) * easingValue); | |
} | |
public int targetvalue { | |
get { return (int)_targetValue; } | |
set { | |
_targetValue = (float)value; | |
_percent = 0.0f; | |
} | |
} | |
public int currentValue { | |
get { return (int)_currentValue; } | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Xinterpolated = Xinital + InterpolationPercent * (Xfinal - Xinital) | |
Here’s that doc I was talking about. It’s a really good read. | |
http://webcache.googleusercontent.com/search?q=cache:f61qHt1is9kJ:x3ge.com/%3Fp%3D393&hl=en&gl=us&strip=1&vwsrc=0 | |
I grabbed a google doc version of it too. Since I was only able to pull the cached page. | |
https://docs.google.com/document/d/1ZxP67rQ0_p34H_fEoPrn6ttyE0ejtTryvZCg-LlE-O4/edit?usp=sharing | |
And the magic 3D function! | |
We must now review our Interpolate() function, this time to really interpolate vertices. Otherwise, we would have a very poor animation because of the number of frames the model can holds. With the interpolation, we can create an “infinity” of frames (we create just that we need when rendering). The formula is quite simple: | |
Xinterpolated = Xinital + InterpolationPercent * (Xfinal - Xinital) | |
So let’s interpolate all vertices of the current and the next frames. The new Interpolate() function looks like this: | |
// ---------------------------------------------- | |
// Interpolate() - interpolate and scale vertices | |
// from the current and the next frame. | |
// ---------------------------------------------- | |
void CMD2Model::Interpolate( vec3_t *vertlist ) | |
{ | |
vec3_t *curr_v; // pointeur to current frame vertices | |
vec3_t *next_v; // pointeur to next frame vertices | |
// create current frame and next frame's vertex list | |
// from the whole vertex list | |
curr_v = &m_vertices[ num_xyz * m_anim.curr_frame ]; | |
next_v = &m_vertices[ num_xyz * m_anim.next_frame ]; | |
// interpolate and scale vertices to avoid ugly animation | |
for( int i = 0; i < num_xyz ; i++ ) | |
{ | |
vertlist[i][0] = (curr_v[i][0] + m_anim.interpol * (next_v[i][0] - curr_v[i][0])) * m_scale; | |
vertlist[i][1] = (curr_v[i][1] + m_anim.interpol * (next_v[i][1] - curr_v[i][1])) * m_scale; | |
vertlist[i][2] = (curr_v[i][2] + m_anim.interpol * (next_v[i][2] - curr_v[i][2])) * m_scale; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment