00001 #include "VIcon.h"
00002 #include "glew.h"
00003
00004 VIcon::VIcon( VVector m_SeedPoint, float *data ) : mSeedPoint(m_SeedPoint), mSteps(0.5), mScale( 0.5f ),
00005 mColorB( VVector(0.8823f, 0.286f, 0.0f )),
00006 mColorF( VVector(0.8823f, 0.564f, 0.0f ) ),
00007 mColorI( VVector(0.937f, 0.8823f, 0.286f ) )
00008 {
00009 mData[ 0 ] = data[ 0 ];
00010 mData[ 1 ] = data[ 1 ];
00011 mData[ 2 ] = data[ 2 ];
00012 mData[ 3 ] = data[ 3 ];
00013 }
00014
00015 void VIcon::computeIcon( vTimeStep * m_TimeStep, int m_ActiveTimeStep )
00016 {
00017 mIconTail.clear();
00018
00019 std::vector< float > pixeldata;
00020 pixeldata = m_TimeStep[ m_ActiveTimeStep ].getFullFBODataVector();
00021
00022 int texsize_x, texsize_y;
00023 texsize_x = m_TimeStep[ m_ActiveTimeStep ].mFrameBufferObject->getWidth();
00024 texsize_y = m_TimeStep[ m_ActiveTimeStep ].mFrameBufferObject->getHeight();
00025
00026
00027 VVector arrayindex = VVector( texsize_x * ( 1.0 - mSeedPoint.getX()), texsize_y * mSeedPoint.getY(), 0.0f );
00028 int xfloor = (int) ( arrayindex.getX() - 0.5f ) - 1;
00029 int yfloor = (int) ( arrayindex.getY() - 0.5f ) - 1;
00030 int xceil = (int) ( arrayindex.getX() + 0.5f ) - 1;
00031 int yceil = (int) ( arrayindex.getY() + 0.5f ) - 1;
00032
00033 if ( xfloor < 0 || yfloor < 0 || xceil >= texsize_x || yceil >= texsize_x )
00034 {
00035 return;
00036 }
00037
00038
00039
00040 float velocity_x_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 ];
00041 float velocity_y_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 + 1 ];
00042 float velocity_z_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 + 2 ];
00043
00044
00045 float velocity_x_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 ];
00046 float velocity_y_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 + 1 ];
00047 float velocity_z_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 + 2 ];
00048
00049
00050 float velocity_x_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 ];
00051 float velocity_y_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 + 1 ];
00052 float velocity_z_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 + 2 ];
00053
00054
00055 float velocity_x_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 ];
00056 float velocity_y_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 + 1 ];
00057 float velocity_z_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 + 2 ];
00058
00059 float interpolval_x_L = ( arrayindex.getX() - xfloor ) * velocity_x_cf + ( xceil - arrayindex.getX() ) * velocity_x_ff;
00060 float interpolval_y_L = ( arrayindex.getX() - xfloor ) * velocity_y_cf + ( xceil - arrayindex.getX() ) * velocity_y_ff;
00061 float interpolval_z_L = ( arrayindex.getX() - xfloor ) * velocity_z_cf + ( xceil - arrayindex.getX() ) * velocity_z_ff;
00062
00063 float interpolval_x_H = ( arrayindex.getX() - xfloor ) * velocity_x_cc + ( xceil - arrayindex.getX() ) * velocity_x_fc;
00064 float interpolval_y_H = ( arrayindex.getX() - xfloor ) * velocity_y_cc + ( xceil - arrayindex.getX() ) * velocity_y_fc;
00065 float interpolval_z_H = ( arrayindex.getX() - xfloor ) * velocity_z_cc + ( xceil - arrayindex.getX() ) * velocity_z_fc;
00066
00067 float interpolval_x = ( arrayindex.getY() - yfloor ) * interpolval_x_H + ( yceil - arrayindex.getY() ) * interpolval_x_L;
00068 float interpolval_y = ( arrayindex.getY() - yfloor ) * interpolval_y_H + ( yceil - arrayindex.getY() ) * interpolval_y_L;
00069 float interpolval_z = ( arrayindex.getY() - yfloor ) * interpolval_z_H + ( yceil - arrayindex.getY() ) * interpolval_z_L;
00070
00071 VVector interpolatedval = VVector( interpolval_x / mData[ 0 ], interpolval_y / mData[ 1 ], interpolval_z );
00072 interpolatedval.normalize();
00073
00074
00075 float anglerad = atan2( interpolatedval.getY(), interpolatedval.getX() ) - PI /2.0f;
00076
00077 VMatrix rotz = rotz = VMatrix::RotationZ( anglerad );
00078
00079 float keepratiox = ( mData[ 0 ] > mData[ 1 ] ) ? 1.0f : mData[ 0 ] / mData[ 1 ];
00080 float keepratioy = ( mData[ 1 ] > mData[ 0 ] ) ? 1.0f : mData[ 1 ] / mData[ 0 ];
00081
00082 float ratio = pow( max( mData[ 0 ], mData[ 1 ] ) / min( mData[ 0 ], mData[ 1 ] ), 2 ) * 1.5f * pow( 2.0f * mScale, 2.0f );
00083
00084 VVector off1, off2, off3, off4;
00085
00086 off1 = rotz * ( VVector( -0.0067f * keepratiox, - 0.0067f * keepratioy, -0.02f ) * ( keepratioy ) );
00087 off2 = rotz * ( VVector( 0.0067f * keepratiox, - 0.0067f * keepratioy, -0.02f ) * ( keepratioy ) );
00088 off3 = rotz * ( VVector( 0.0f * keepratiox, 0.0067f * keepratioy, -0.02f ) * ( keepratiox ) );
00089
00090 off1 = VVector( ( off1 ).getX() * keepratioy, ( off1 ).getY() * keepratiox, 0.0f );
00091 off2 = VVector( ( off2 ).getX() * keepratioy, ( off2 ).getY() * keepratiox, 0.0f );
00092 off3 = VVector( ( off3 ).getX() * keepratioy, ( off3 ).getY() * keepratiox, 0.0f );
00093
00094 VVector p1 = mSeedPoint + off1* ratio;
00095 VVector p2 = mSeedPoint + off2* ratio;
00096 VVector p3 = mSeedPoint + off3* ratio;
00097
00098 VVector p4 = ( p1 + p2 ) / 2.0f;
00099
00100
00101 p1.setX( p1.getX() * mData[ 0 ] + mData[ 2 ] );
00102 p2.setX( p2.getX() * mData[ 0 ] + mData[ 2 ] );
00103 p3.setX( p3.getX() * mData[ 0 ] + mData[ 2 ] );
00104 p4.setX( p4.getX() * mData[ 0 ] + mData[ 2 ] );
00105
00106 p1.setY( p1.getY() * mData[ 1 ] + mData[ 3 ] );
00107 p2.setY( p2.getY() * mData[ 1 ] + mData[ 3 ] );
00108 p3.setY( p3.getY() * mData[ 1 ] + mData[ 3 ] );
00109 p4.setY( p4.getY() * mData[ 1 ] + mData[ 3 ] );
00110
00111 mTriangles[ 0 ] = p1;
00112 mTriangles[ 1 ] = p2;
00113 mTriangles[ 2 ] = p3;
00114 mTriangles[ 3 ] = p4;
00115
00116 bool outofdata = false;
00117 float sactualpoint_x = 1.0f - mSeedPoint.getX();
00118 float sactualpoint_y = mSeedPoint.getY();
00119
00120 mIconTail.push_back( mTriangles[ 3 ] );
00121
00122 for ( int i = 0; i < 5 ; i++)
00123 {
00124 if (outofdata ) break;
00125
00126
00127
00128 VVector arrayindex = VVector( texsize_x * sactualpoint_x, texsize_y * sactualpoint_y, 0.0f );
00129 int xfloor = (int) ( arrayindex.getX() - 0.5f ) - 1;
00130 int yfloor = (int) ( arrayindex.getY() - 0.5f ) - 1;
00131 int xceil = (int) ( arrayindex.getX() + 0.5f ) - 1;
00132 int yceil = (int) ( arrayindex.getY() + 0.5f ) - 1;
00133
00134 if ( xfloor < 0 || yfloor < 0 || xceil >= texsize_x || yceil >= texsize_x )
00135 {
00136
00137 outofdata = true;
00138 break;
00139 }
00140
00141
00142
00143 float velocity_x_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 ];
00144 float velocity_y_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 + 1 ];
00145 float velocity_z_ff = pixeldata[ xfloor * 4 + yfloor * texsize_x * 4 + 2 ];
00146
00147
00148 float velocity_x_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 ];
00149 float velocity_y_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 + 1 ];
00150 float velocity_z_fc = pixeldata[ xfloor * 4 + yceil * texsize_x * 4 + 2 ];
00151
00152
00153 float velocity_x_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 ];
00154 float velocity_y_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 + 1 ];
00155 float velocity_z_cf = pixeldata[ xceil * 4 + yfloor* texsize_x * 4 + 2 ];
00156
00157
00158 float velocity_x_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 ];
00159 float velocity_y_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 + 1 ];
00160 float velocity_z_cc = pixeldata[ xceil * 4 + yceil * texsize_x * 4 + 2 ];
00161
00162 float interpolval_x_L = ( arrayindex.getX() - xfloor ) * velocity_x_cf + ( xceil - arrayindex.getX() ) * velocity_x_ff;
00163 float interpolval_y_L = ( arrayindex.getX() - xfloor ) * velocity_y_cf + ( xceil - arrayindex.getX() ) * velocity_y_ff;
00164 float interpolval_z_L = ( arrayindex.getX() - xfloor ) * velocity_z_cf + ( xceil - arrayindex.getX() ) * velocity_z_ff;
00165
00166 float interpolval_x_H = ( arrayindex.getX() - xfloor ) * velocity_x_cc + ( xceil - arrayindex.getX() ) * velocity_x_fc;
00167 float interpolval_y_H = ( arrayindex.getX() - xfloor ) * velocity_y_cc + ( xceil - arrayindex.getX() ) * velocity_y_fc;
00168 float interpolval_z_H = ( arrayindex.getX() - xfloor ) * velocity_z_cc + ( xceil - arrayindex.getX() ) * velocity_z_fc;
00169
00170 float interpolval_x = ( arrayindex.getY() - yfloor ) * interpolval_x_H + ( yceil - arrayindex.getY() ) * interpolval_x_L;
00171 float interpolval_y = ( arrayindex.getY() - yfloor ) * interpolval_y_H + ( yceil - arrayindex.getY() ) * interpolval_y_L;
00172 float interpolval_z = ( arrayindex.getY() - yfloor ) * interpolval_z_H + ( yceil - arrayindex.getY() ) * interpolval_z_L;
00173
00174 VVector interpolatedval = VVector( interpolval_x, interpolval_y, interpolval_z );
00175 VVector interp_mult = VVector( interpolatedval );
00176 interp_mult.setX( -interp_mult.getX( ) );
00177 interp_mult.normalize();
00178 interp_mult *= 0.01f;
00179
00180
00181 VVector oldpos_world = VVector();
00182 oldpos_world.setX( ( 1.0f - sactualpoint_x ) * mData[ 0 ] + mData[ 2 ] );
00183 oldpos_world.setY( sactualpoint_y * mData[ 1 ] + mData[ 3 ] );
00184
00185 VVector newpos_world = oldpos_world - interp_mult;
00186
00187 VVector newpos_tex = VVector();
00188 newpos_tex.setX( ( newpos_world.getX() - mData[ 2 ] ) / mData[ 0 ] );
00189 newpos_tex.setY( ( newpos_world.getY() - mData[ 3 ] ) / mData[ 1 ] );
00190
00191 if( ( newpos_tex.getX() ) > 1.0f || ( newpos_tex.getY() ) > 1.0f
00192 || ( newpos_tex.getX() ) < 0.0f || ( newpos_tex.getY() ) < 0.0f )
00193 {
00194 outofdata = true;
00195 break;
00196 }
00197
00198 sactualpoint_x = 1.0 - newpos_tex.getX();
00199 sactualpoint_y = newpos_tex.getY();
00200
00201
00202
00203 newpos_tex.setX( -( newpos_tex.getX() * mData[ 0 ] ) + mData[ 2 ] + mData[ 0 ]);
00204 newpos_tex.setY( ( newpos_tex.getY() * mData[ 1 ] ) + mData[ 3 ] );
00205 mIconTail.push_back( newpos_tex );
00206
00207
00208 float epsilon = 0.0000001f;
00209 VVector posdifference = mIconTail[ mIconTail.size() - 1 ] - mIconTail[ mIconTail.size() - 2 ];
00210 if ( posdifference.getMagnitude() < epsilon)
00211 {
00212 outofdata = true;
00213 break;
00214 }
00215
00216 }
00217
00218 pixeldata.clear();
00219 }
00220
00221 void VIcon::draw()
00222 {
00223
00224
00225
00226
00227 glBegin( GL_TRIANGLES );
00228
00229 glColor3fv( mColorB.getPtr() );
00230 glVertex3fv( mTriangles[ 0 ].getPtr() );
00231
00232 glColor3fv( mColorF.getPtr() );
00233 glVertex3fv( mTriangles[ 3 ].getPtr() );
00234
00235 glColor3fv( mColorB.getPtr() );
00236 glVertex3fv( mTriangles[ 2 ].getPtr() );
00237
00238
00239
00240 glColor3fv( mColorF.getPtr() );
00241 glVertex3fv( mTriangles[ 3 ].getPtr() );
00242
00243 glColor3fv( mColorB.getPtr() );
00244 glVertex3fv( mTriangles[ 1 ].getPtr() );
00245
00246 glColor3fv( mColorB.getPtr() );
00247 glVertex3fv( mTriangles[ 2 ].getPtr() );
00248
00249 glEnd();
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 }