![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsModelDeformableGLSL.cpp 00003 ******************************************************************************/ 00008 /****************************************************************************** 00009 SUKITTI PUNAK (10/17/2006) 00010 UPDATE (11/09/2007) 00011 ******************************************************************************/ 00012 #include "TAPsModelDeformableGLSL.hpp" 00013 // Using Inclusion Model (i.e. definitions are included in declarations) 00014 // (this name.cpp is included in name.hpp) 00015 // Each friend is defined directly inside its declaration. 00016 00017 BEGIN_NAMESPACE_TAPs__OpenGL 00018 //============================================================================= 00019 // START: STATIC MEMBER(S) AND FUNCTION(S) 00020 template <typename T> T 00021 ModelDeformableGLSL<T>::g_tPressureValue = 1.0; 00022 //============================================================================= 00023 //----------------------------------------------------------------------------- 00024 // default constructor 00025 template <typename T> 00026 ModelDeformableGLSL<T>::ModelDeformableGLSL () 00027 : OpenGLModel<T>() 00028 { 00029 //--------------------------------------------------------------- 00030 // Determine GPU Type 00031 GLubyte const * vendor = glGetString( GL_VENDOR ); 00032 if ( vendor[0] == 'A' 00033 && vendor[1] == 'T' 00034 && vendor[2] == 'I' ) { 00035 m_iGPUInfo = 1; 00036 } 00037 else if ( vendor[0] == 'N' 00038 && vendor[1] == 'V' 00039 && vendor[2] == 'I' 00040 && vendor[3] == 'D' 00041 && vendor[4] == 'I' 00042 && vendor[5] == 'A') { 00043 m_iGPUInfo = 2; 00044 } 00045 else { 00046 m_iGPUInfo = 0; 00047 } 00048 //------------------------------------------- 00049 std::string strExtensions( (char const *)glGetString( GL_EXTENSIONS ) ); 00050 if ( strExtensions.find( "NV_vertex_program3" ) == std::string::npos ) { 00051 m_bSupportExtension_NV_vertex_program3 = false; 00052 } 00053 else { 00054 m_bSupportExtension_NV_vertex_program3 = true; 00055 } 00056 //------------------------------------------- 00057 // Max Combined Texture Image Units 00058 int combined_texture_units; 00059 glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &combined_texture_units ); 00060 //------------------------------------------- 00061 // Max Texture Image Units 00062 int texture_units; 00063 glGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS, &texture_units ); 00064 //------------------------------------------- 00065 // Max Vertex Texture Image Units if supported 00066 int vertex_texture_units; 00067 if ( m_bSupportExtension_NV_vertex_program3 ) { 00068 glGetIntegerv( GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &vertex_texture_units ); 00069 } 00070 //------------------------------------------- 00071 #ifdef TAPs_DEBUG_MODE 00072 #ifdef TAPs_USE_WXWIDGETS 00073 wxLogWarning( wxT( "OpenGL Extensions: %s" ), strExtensions.c_str() ); 00074 wxLogWarning( wxT( "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %i" ), combined_texture_units ); 00075 wxLogWarning( wxT( "GL_MAX_TEXTURE_IMAGE_UNITS: %i" ), texture_units ); 00076 if ( m_bSupportExtension_NV_vertex_program3 ) { 00077 wxLogWarning( wxT( "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB: %i" ), vertex_texture_units ); 00078 } 00079 #else 00080 std::cout << "OpenGL Extensions: " << strExtensions << "\n"; 00081 std::cout << "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: " << combined_texture_units << "\n"; 00082 std::cout << "GL_MAX_TEXTURE_IMAGE_UNITS: " << texture_units << "\n"; 00083 if ( m_bSupportExtension_NV_vertex_program3 ) { 00084 std::cout << "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB: " << vertex_texture_units << "\n"; 00085 } 00086 #endif 00087 #endif//TAPs_DEBUG_MODE 00088 //--------------------------------------------------------------- 00089 // Since Microsoft gl.h is version 1.1, 00090 // So this fn calls glewInit() for latest OpenGL version 00091 // and initialize GLSL. 00092 if ( !GFnInitGLSL() ) { 00093 std::cout << "GFnInitGLSL() returns false!" << std::endl; 00094 } 00095 else { 00096 std::cout << "GFnInitGLSL() returns true!" << std::endl; 00097 } 00098 Default(); 00099 //--------------------------------------------------------------- 00100 //--------------------------------------------------------------- 00101 #ifdef TAPs_DEBUG_MODE 00102 std::cout << "ModelDeformableGLSL<" << typeid(T).name() << "> Constructor\n"; 00103 #endif//TAPs_DEBUG_MODE 00104 00105 // DEBUG for PNTri Drawing 00106 //GLchar *VertexShaderSource, *FragmentShaderSource; 00107 //ReadShaderSource( "Resource/Shader/PNTri", &VertexShaderSource, &FragmentShaderSource ); 00108 //int success = InstallShaders( VertexShaderSource, FragmentShaderSource, g_PNTriProg ); 00109 //assert( success ); 00110 } 00111 //----------------------------------------------------------------------------- 00112 // Destructor 00113 template <typename T> 00114 ModelDeformableGLSL<T>::~ModelDeformableGLSL () 00115 { 00116 Clear(); 00117 //--------------------------------------------------------------- 00118 #ifdef TAPs_DEBUG_MODE 00119 std::cout << "ModelDeformableGLSL<" << typeid(T).name() << "> Destructor\n"; 00120 #endif//TAPs_DEBUG_MODE 00121 } 00122 //----------------------------------------------------------------------------- 00123 // Default 00124 template <typename T> 00125 void ModelDeformableGLSL<T>::Default () 00126 { 00127 // Simulation State(s) 00128 m_bIsCollided = false; 00129 //------------------------------------------- 00130 m_vGridResolution.SetXYZ( 0, 0, 0 ); 00131 m_vGridDimension.SetXYZ( 0, 0, 0 ); 00132 m_iTotalElements = 0; 00133 m_fElementVolume = 0; 00134 //------------------------------------------- 00135 // Simulation Attributes 00136 //----------------------- 00137 m_tSimThreshold = IC_Thresholds::OUTSIDE_MODEL + IC_Thresholds::HALF_THRESHOLD_ADD; 00138 //m_tSimThreshold = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY + IC_Thresholds::HALF_THRESHOLD_ADD; 00139 //----------------------- 00140 // Time Step 00141 m_tTimeStep = 0.010; // e.g. 0.010 is 10 msec 00142 //----------------------- 00143 // Frames Per Pulsation 00144 m_usFramesPerPulsation = 20; // e.g. 20 frames/pulsation 00145 //----------------------- 00146 // Relaxation Contraints 00147 m_tMaxRelaxation = 1.1; 00148 m_tMinRelaxation = 0.9; 00149 //----------------------- 00150 // Element Properties 00151 m_tElementMass = 1.0; 00152 //----------------------- 00153 // Element Approx Radius for Collision Detection 00154 m_tElementApproxRadius = 0.0; 00155 //------------------------------------------- 00156 // Default Spring Properties 00157 //----------------------- 00159 //T stiffness = 2500; 00160 //SPRING_PROP.SetValueForAllStiffnesses( stiffness ); 00162 //SPRING_PROP.SetValueForAllDampers( stiffness / 90 ); 00163 //----------------------- 00164 // Good number: 2500 for stiffness and (stiffness / 10) for damper 00165 T stiffness = 800; 00166 SPRING_PROP.SetValueForAllStiffnesses( stiffness ); 00167 // If SimStepByVerletIntegration damper is multiplied by dt 00168 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00169 SPRING_PROP.SetValueForAllDampers( stiffness / 10.0 ); 00170 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00171 //----------------------- 00172 // Spring Rest Lengths have to be set when the grids are created! 00173 //--------------------------------- 00174 // Surface 00175 m_ipSurfaceBoundary = NULL; 00176 //--------------------------------- 00177 // Connectivity 00178 // m_ipElementConnect = NULL; 00179 // m_iElementMaxValence = 0; 00180 //------------------------------------------- 00181 // For drawing useful objects 00182 //m_vOGLUsefulObj = NULL; 00183 //--------------------------------------------------------------- 00184 m_glslFBO_vPosition = 0; 00185 //m_glslFBO_vVelocity = 0; 00186 m_glslFBO_vConnectivity = 0; 00187 m_glslFBO_vCollisionDetection = 0; 00188 m_glslFBO_vOffsetValues = 0; 00189 m_glslRBO = 0; 00190 m_glslpBufferIDForPosition = NULL; 00191 m_glslpBufferIDForConnectivity = NULL; 00192 //m_glslpBufferIDForCollisionDetection = NULL; 00193 //m_glslpVertexArrayBufferID = NULL; 00194 //------------------------------------------- 00195 // Default Visualization 00196 DefaultVisualization(); 00197 //------------------------------------------- 00198 // For 3D Object-Aligned Slice Draw Direction 00199 //m_glslFBO_v3DObjAlignedSliceDrawDirection = 0; 00200 //m_glui2DTextureFor3DObjAlignedSliceDrawDirection = 0; 00201 //------------------------------------------- 00202 // Gradient Elements 00203 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00204 m_3DTextureGradient = NULL; 00205 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00206 //------------------------------------------- 00207 // Home Position Elements 00208 m_3DTextureHomePosition = NULL; 00209 //------------------------------------------- 00210 // Position Elements 00211 m_3DTexturePosition = NULL; 00212 //------------------------------------------- 00213 // Velocity Elements 00214 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00215 m_gluipNameTextureVelocity = NULL; 00216 m_gluipNameTextureVelocityNext = NULL; 00217 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00218 //------------------------------------------- 00219 // Connectivity Elements 00220 m_3DTextureConnectivity = NULL; 00221 //------------------------------------------- 00222 // Ellipsoid Influence Volume 00223 m_3DTextureEllipsoidInfluence = NULL; 00224 //------------------------------------------- 00225 // Collision Detection 00226 m_3DTextureCollisionDetection = NULL; 00227 //------------------------------------------- 00228 // Offset Values 00229 m_3DTextureOffsetValues = NULL; 00230 //------------------------------------------- 00231 m_vGridResolution.SetXYZ( 0, 0, 0 ); 00232 //------------------------------------------- 00297 //--------------------------------- 00298 m_glpTexelForVertexPos = NULL; 00299 m_glpTexelForObjectOrigData = NULL; 00300 //------------------------------------------- 00301 // For GLSL 00302 m_glslProgramObjectForDefModelStep = NULL; 00303 m_glslProgramObjectForRelaxationConstraint = NULL; 00304 m_glslProgramObjectForDefModelCollisionDetection = NULL; 00305 m_glslProgramObjectForDefModelCDTooltipSphereCylinder = NULL; 00306 m_glslProgramObjectForRemovingElements = NULL; 00307 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00308 m_glslProgramObjectForRemovingConnections = NULL; 00309 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00310 m_glslProgramObjectForUpdateConnectivity = NULL; 00311 00312 // Grabbing 00313 m_glslProgramObjectForDefModelCDGrabStart = NULL; 00314 m_glslProgramObjectForDefModelCDGrabMove = NULL; 00315 m_glslProgramObjectForDefModelCDGrabEnd = NULL; 00316 } 00317 //----------------------------------------------------------------------------- 00318 // Clear 00319 template <typename T> 00320 void ModelDeformableGLSL<T>::Clear () 00321 { 00322 //--------------------------------------------------------------- 00323 // Delete Frame (Render) Buffers 00324 if ( m_glslFBO_vPosition > 0 ) { 00325 glDeleteFramebuffersEXT( 1, &m_glslFBO_vPosition ); 00326 } 00327 //if ( m_glslFBO_vVelocity > 0 ) { 00328 // glDeleteFramebuffersEXT( 1, &m_glslFBO_vVelocity ); 00329 //} 00330 if ( m_glslFBO_vConnectivity > 0 ) { 00331 glDeleteFramebuffersEXT( 1, &m_glslFBO_vConnectivity ); 00332 } 00333 if ( m_glslFBO_vCollisionDetection > 0 ) { 00334 glDeleteFramebuffersEXT( 1, &m_glslFBO_vCollisionDetection ); 00335 } 00336 if ( m_glslFBO_vOffsetValues > 0 ) { 00337 glDeleteFramebuffersEXT( 1, &m_glslFBO_vOffsetValues ); 00338 } 00339 if ( m_glslRBO > 0 ) { 00340 glDeleteRenderbuffersEXT( 1, &m_glslRBO ); 00341 } 00342 if ( m_glslpBufferIDForPosition ) { 00343 glDeleteBuffers( 1, m_glslpBufferIDForPosition ); 00344 delete [] m_glslpBufferIDForPosition; 00345 } 00346 if ( m_glslpBufferIDForConnectivity ) { 00347 glDeleteBuffers( 1, m_glslpBufferIDForConnectivity ); 00348 delete [] m_glslpBufferIDForConnectivity; 00349 } 00350 //if ( m_glslpBufferIDForCollisionDetection ) { 00351 // glDeleteBuffers( 1, m_glslpBufferIDForCollisionDetection ); 00352 // delete [] m_glslpBufferIDForCollisionDetection; 00353 //} 00354 //if ( m_glslpVertexArrayBufferID ) { 00355 // glDeleteBuffers( 1, m_glslpVertexArrayBufferID ); 00356 //} 00357 //--------------------------------------------------------------- 00358 // Clear Visualization 00359 ClearVisualization(); 00360 //--------------------------------------------------------------- 00361 // Delete Textures - Gradient Elements 00362 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00363 if ( m_3DTextureGradient ) { 00364 delete m_3DTextureGradient; 00365 } 00366 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00367 //--------------------------------------------------------------- 00368 // Delete Textures - Home Position Elements 00369 if ( m_3DTextureHomePosition ) { 00370 delete m_3DTextureHomePosition; 00371 } 00372 //--------------------------------------------------------------- 00373 // Delete Textures - Position Elements 00374 if ( m_3DTexturePosition ) { 00375 delete m_3DTexturePosition; 00376 } 00377 //--------------------------------------------------------------- 00378 // Delete Textures - Velocity Elements 00379 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00380 if ( m_gluipNameTextureVelocity != NULL ) { 00381 glDeleteTextures( m_TexturePositionParameters.numOfTextures, m_gluipNameTextureVelocity ); 00382 delete [] m_gluipNameTextureVelocity; 00383 } 00384 if ( m_gluipNameTextureVelocityNext != NULL ) { 00385 glDeleteTextures( m_TexturePositionParameters.num2DTextures, m_gluipNameTextureVelocityNext ); 00386 delete [] m_gluipNameTextureVelocityNext; 00387 } 00388 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00389 //--------------------------------------------------------------- 00390 // Delete Textures - Connectivity Elements 00391 if ( m_3DTextureConnectivity ) { 00392 delete m_3DTextureConnectivity; 00393 } 00394 //--------------------------------------------------------------- 00395 // Delete Textures - Ellipsoid Influence Volume 00396 if ( m_3DTextureEllipsoidInfluence ) { 00397 delete m_3DTextureEllipsoidInfluence; 00398 } 00399 //--------------------------------------------------------------- 00400 // Delete Textures - Collision Detection Elements 00401 if ( m_3DTextureCollisionDetection ) { 00402 delete m_3DTextureCollisionDetection; 00403 } 00404 //--------------------------------------------------------------- 00405 // Delete Textures - Offset Values 00406 if ( m_3DTextureOffsetValues ) { 00407 delete m_3DTextureOffsetValues; 00408 } 00409 //--------------------------------------------------------------- 00410 if ( m_glpTexelForVertexPos ) { 00411 delete [] m_glpTexelForVertexPos; 00412 } 00413 //--------------------------------------------------------------- 00414 if ( m_glpTexelForObjectOrigData ) { 00415 delete [] m_glpTexelForObjectOrigData; 00416 } 00417 //--------------------------------------------------------------- 00418 // For GLSL 00419 if ( m_glslProgramObjectForDefModelStep ) { 00420 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelStep ); 00421 } 00422 if ( m_glslProgramObjectForRelaxationConstraint ) { 00423 m_glslShaderManager.Delete( m_glslProgramObjectForRelaxationConstraint ); 00424 } 00425 if ( m_glslProgramObjectForDefModelCollisionDetection ) { 00426 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelCollisionDetection ); 00427 } 00428 if ( m_glslProgramObjectForDefModelCDTooltipSphereCylinder ) { 00429 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelCDTooltipSphereCylinder ); 00430 } 00431 if ( m_glslProgramObjectForRemovingElements ) { 00432 m_glslShaderManager.Delete( m_glslProgramObjectForRemovingElements ); 00433 } 00434 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00435 if ( m_glslProgramObjectForRemovingConnections ) { 00436 m_glslShaderManager.Delete( m_glslProgramObjectForRemovingConnections ); 00437 } 00438 #endif //TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00439 if ( m_glslProgramObjectForUpdateConnectivity ) { 00440 m_glslShaderManager.Delete( m_glslProgramObjectForUpdateConnectivity ); 00441 } 00442 // Grabbing 00443 if ( m_glslProgramObjectForDefModelCDGrabStart ) { 00444 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelCDGrabStart ); 00445 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelCDGrabMove ); 00446 m_glslShaderManager.Delete( m_glslProgramObjectForDefModelCDGrabEnd ); 00447 } 00448 //--------------------------------------------------------------- 00449 /* 00450 #ifdef TAPs_DEBUG_MODE 00451 #ifdef TAPs_USE_WXWIDGETS 00452 wxLogWarning( wxT( "Finish clearing the deformable model data." ) ); 00453 #else 00454 std::cout << "Finish clearing the deformable model data." << std::endline; 00455 #endif 00456 #endif//TAPs_DEBUG_MODE 00457 //*/ 00458 Default(); 00459 } 00460 //----------------------------------------------------------------------------- 00461 // Default Visualization 00462 template <typename T> 00463 void ModelDeformableGLSL<T>::DefaultVisualization () 00464 { 00465 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00466 m_Visualization_RTGenMesh = NULL; 00467 #endif 00468 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00469 m_Visualization_3DTexture = NULL; 00470 #endif 00471 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00472 m_Visualization_RayCasting = NULL; 00473 #endif 00474 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00475 m_Visualization_Mesh = NULL; 00476 #endif 00477 } 00478 //----------------------------------------------------------------------------- 00479 // Clear Visualization 00480 template <typename T> 00481 void ModelDeformableGLSL<T>::ClearVisualization () 00482 { 00483 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00484 if ( m_Visualization_RTGenMesh ) { 00485 delete m_Visualization_RTGenMesh; 00486 } 00487 #endif 00488 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00489 if ( m_Visualization_3DTexture ) { 00490 delete m_Visualization_3DTexture; 00491 } 00492 #endif 00493 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00494 if ( m_Visualization_RayCasting ) { 00495 delete m_Visualization_RayCasting; 00496 } 00497 #endif 00498 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00499 if ( m_Visualization_Mesh ) { 00500 delete m_Visualization_Mesh; 00501 } 00502 #endif 00503 //--------------------------------- 00504 DefaultVisualization(); 00505 } 00506 //----------------------------------------------------------------------------- 00507 // Setup Visualization 00508 template <typename T> 00509 int ModelDeformableGLSL<T>::SetupVisualization ( 00510 enum GridGenerator<T>::VertexFlag *** pFlagDataForXYZVoxels 00511 ) 00512 { 00514 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00515 //=============================================================== 00516 // Setup visualization by real-time generated mesh 00517 //--------------------------------------------------------------- 00518 m_Visualization_RTGenMesh = new ModelDeformableGLSL_Visualization_RTGenMesh<T>( this ); 00519 if ( !m_Visualization_RTGenMesh ) { 00520 #ifdef TAPs_USE_WXWIDGETS 00521 wxLogError( wxT( "ERROR: ModelDeformableGLSL --> Cannot create a real-time generated mesh for visualization of size (%i, %i, %i)!" ), 00522 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00523 #else 00524 std::cerr << "ERROR: ModelDeformableGLSL --> Cannot create a real-time generated mesh for visualization of size (" 00525 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00526 << ")!" << std::endl; 00527 #endif 00528 return -1;//return false; 00529 } 00530 00531 //std::cout << "AFTER new m_Visualization_RTGenMesh" << std::endl; 00532 00533 if ( !m_Visualization_RTGenMesh->SetupVisualization( 00534 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00535 pFlagDataForXYZVoxels ) ) 00536 { 00537 #ifdef TAPs_USE_WXWIDGETS 00538 wxLogError( wxT( "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create a real-time generated mesh for visualization of size (%i, %i, %i)!" ), 00539 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00540 #else 00541 std::cerr << "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create a real-time generated mesh for visualization of size (" 00542 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00543 << ")!" << std::endl; 00544 #endif 00545 return -2;//return false; 00546 } 00547 00548 //std::cout << "AFTER m_Visualization_RTGenMesh->SetupVisualization()" << std::endl; 00549 00550 //--------------------------------------------------------------- 00551 //=============================================================== 00552 #endif 00553 00554 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00555 //=============================================================== 00556 // Setup a 3D Texture (for Visualization) 00557 //--------------------------------------------------------------- 00558 m_Visualization_3DTexture = new ModelDeformableGLSL_Visualization_3DTexture<T>( this ); 00559 if ( !m_Visualization_3DTexture ) { 00560 #ifdef TAPs_USE_WXWIDGETS 00561 wxLogError( wxT( "ERROR: ModelDeformableGLSL --> Cannot create 3D texture visualization of size (%i, %i, %i)!" ), 00562 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00563 #else 00564 std::cerr << "ERROR: ModelDeformableGLSL --> Cannot create 3D texture visualization of size (" 00565 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00566 << ")!" << std::endl; 00567 #endif 00568 return -3;//return false; 00569 } 00570 00571 //std::cout << "AFTER new m_Visualization_3DTexture" << std::endl; 00572 00573 if ( !m_Visualization_3DTexture->SetupVisualization( 00574 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00575 pFlagDataForXYZVoxels ) ) 00576 { 00577 #ifdef TAPs_USE_WXWIDGETS 00578 wxLogError( wxT( "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create 3D texture of size (%i, %i, %i)!" ), 00579 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00580 #else 00581 std::cerr << "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create 3D texture of size (" 00582 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00583 << ")!" << std::endl; 00584 #endif 00585 return -4;//return false; 00586 } 00587 00588 //std::cout << "AFTER m_Visualization_3DTexture->SetupVisualization()" << std::endl; 00589 00590 //--------------------------------------------------------------- 00591 //=============================================================== 00592 #endif 00593 00594 00595 //*/ 00596 // DEBUG 00597 //m_Visualization_RTGenMesh->Set3DTexture( m_Visualization_3DTexture->Get3DTextureVisualization() ); 00598 //*/ 00599 00600 00602 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00603 //=============================================================== 00604 //--------------------------------------------------------------- 00605 //--------------------------------------------------------------- 00606 //=============================================================== 00607 #endif 00608 00609 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00610 //=============================================================== 00611 //--------------------------------------------------------------- 00612 //--------------------------------------------------------------- 00613 //=============================================================== 00614 #endif 00615 00616 //--------------------------------------------------------------- 00617 //=============================================================== 00618 //--------------------------------------------------------------- 00619 return true; 00620 } 00621 //----------------------------------------------------------------------------- 00622 // Initialize 00623 template <typename T> 00624 int ModelDeformableGLSL<T>::InitializeFromGridGeneratorDataFloat ( 00625 GridGenerator<T> * pGridGenerator 00626 ) 00627 { 00628 int iElementSpaceDimension = 4; // XYZ + scalar 00629 //int iElementSpaceDimension = 3; // XYZ 00630 //int iElementSpaceDimension = 2; // XY 00631 //--------------------------------------------------------------- 00632 // Position Elements 00633 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00634 if ( m_3DTextureGradient ) return -40;//return false; 00635 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00636 if ( m_3DTextureHomePosition ) return -50;//return false; 00637 if ( m_3DTexturePosition ) return -100;//return false; 00638 if ( m_3DTextureConnectivity ) return -200;//return false; 00639 if ( m_3DTextureEllipsoidInfluence ) return -300;//return false; 00640 if ( m_3DTextureCollisionDetection ) return -400;//return false; 00641 if ( m_3DTextureOffsetValues ) return -500;//return false; 00642 //------------------------------------------- 00643 // Velocity Elements 00644 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00645 if ( m_gluipNameTextureVelocity != NULL ) return -600;//return false; 00646 if ( m_gluipNameTextureVelocityNext != NULL ) return -700;//return false; 00647 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00648 //------------------------------------------- 00649 if ( !pGridGenerator ) return -800;//return false; 00650 //------------------------------------------- 00651 if ( !pGridGenerator->IsGridGenerated() ) return -900;//return false; 00652 //------------------------------------------- 00653 // Grid Info 00654 m_vGridResolution.SetXYZ( pGridGenerator->GetGridSizeX(), 00655 pGridGenerator->GetGridSizeY(), 00656 pGridGenerator->GetGridSizeZ() ); 00657 m_vGridDimension.SetXYZ( pGridGenerator->GetGridDimensionX(), 00658 pGridGenerator->GetGridDimensionY(), 00659 pGridGenerator->GetGridDimensionZ() ); 00660 00661 // Total Elements and Element's Volume 00662 m_iTotalElements = m_vGridResolution[2] * m_vGridResolution[1] * m_vGridResolution[0]; 00663 m_fElementVolume = m_vGridDimension[2] * m_vGridDimension[1] * m_vGridDimension[0]; 00664 00665 // Element's Approximate Radius 00666 //m_tElementApproxRadius = ( m_vGridDimension[0] + m_vGridDimension[1] + m_vGridDimension[2] ) / 6.0; 00667 if ( m_vGridDimension[0] > m_vGridDimension[1] ) { 00668 m_tElementApproxRadius = m_vGridDimension[0]; 00669 } 00670 else { 00671 m_tElementApproxRadius = m_vGridDimension[1]; 00672 } 00673 if ( m_vGridDimension[2] > m_tElementApproxRadius ) { 00674 m_tElementApproxRadius = m_vGridDimension[2]; 00675 } 00676 00677 // Make element approx radius 1.5 times bigger 00678 //m_tElementApproxRadius *= 1.5; 00679 00680 //--------------------------------------------------------------- 00681 // Set Spring Lengths 00682 SPRING_PROP.SetValueForAllSpringLengths( m_vGridDimension[0], m_vGridDimension[1], m_vGridDimension[2] ); 00683 //--------------------------------------------------------------- 00684 // DEBUG 00685 //#ifdef TAPs_DEBUG_MODE 00686 //SPRING_PROP.PrintOut(); 00687 //#endif 00688 //--------------------------------------------------------------- 00689 int iMemorySizeForTotalElements = m_iTotalElements * iElementSpaceDimension; // (#x * #y * #z) * 4 00690 //--------------------------------------------------------------- 00691 00692 //=============================================================== 00693 // CPU 00694 //--------------------------------------------------------------- 00695 // Element Data 00696 T **** ptElementPosition = 00697 pGridGenerator->ReturnPtrToVertexPositionData(); // XYZ in 4D Array 00698 enum GridGenerator<T>::VertexFlag *** pcElementFlag = 00699 pGridGenerator->ReturnPtrToVertexFlagData(); // Enum in 3D Array 00700 T **** ptElementVertexInterpolation = 00701 pGridGenerator->ReturnPtrToVertexInterpolationData(); // XYZ in 4D Array 00702 //--------------------------------------------------------------- 00703 //=============================================================== 00704 00705 //=============================================================== 00706 // Initialization the (constant) values and connections 00707 //--------------------------------------------------------------- 00708 InitConnectionConstants(); 00709 //--------------------------------------------------------------- 00710 //=============================================================== 00711 00712 //std::cout << "AFTER InitConnectionConstants()" << std::endl; 00713 00714 //=============================================================== 00715 // Setup Visualization 00716 //--------------------------------------------------------------- 00717 int errCode = SetupVisualization( pcElementFlag ); 00718 if ( errCode < 0 ) { 00719 Clear(); 00720 return -1000 + errCode;//return false; 00721 } 00722 //--------------------------------------------------------------- 00723 //=============================================================== 00724 00725 //std::cout << "AFTER SetupVisualization()" << std::endl; 00726 00727 //=============================================================== 00728 // Setup a 3D Texture (for Positions and Connectivities) 00729 //--------------------------------------------------------------- 00730 if ( !Setup3DTexturesForSimulation( 00731 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00732 ptElementPosition, pcElementFlag, ptElementVertexInterpolation, 00733 g_tPressureValue 00734 ) 00735 ) 00736 { 00737 #ifdef TAPs_USE_WXWIDGETS 00738 wxLogError( wxT( "ERROR: ModelDeformableGLSL::Setup2DTextures Fn --> Cannot create 2D textures of size (%i, %i, %i)!" ), 00739 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00740 #else 00741 std::cerr << "ERROR: ModelDeformableGLSL::Setup2DTextures Fn --> Cannot create 2D textures of size (" 00742 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00743 << ")!" << std::endl; 00744 #endif 00745 return -1100;//return false; 00746 } 00747 00748 //std::cout << "AFTER Setup3DTexturesForSimulation()" << std::endl; 00749 00750 // Set AABB of the deformable model 00751 SetBoundingAABBLowPoint( pGridGenerator->GetAABBMinPt() ); 00752 SetBoundingAABBHighPoint( pGridGenerator->GetAABBMaxPt() ); 00753 00754 //--------------------------------------------------------------- 00755 // Set up Buffers and GLSL Shaders 00756 int retVal = SetupBuffersAndShaders(); 00757 if ( retVal != 0 ) return retVal; 00758 //--------------------------------------------------------------- 00759 00760 //--------------------------------------------------------------- 00761 // Update Parameters for GLSL Shaders 00762 UpdateParametersForShaders(); 00763 //--------------------------------------------------------------- 00764 00765 //* 00766 //=============================================================== 00767 // FIX BY HACKING 00768 //--------------------------------------------------------------- 00769 // There is a delay when UpdateConnectivity fn is called for the 00770 // first two times. 00771 // So to avoid these delays during simulation, 00772 // UpdateConnectivity fn are called twice here 00773 // (in RemoveElementsByCollision fn). 00774 // So that the delays are moved to preprocessing time. 00775 // Where one call each does not work. 00776 GLfloat tools[8], spheres[32]; 00777 RemoveElementsByCollision( 0, tools, 0, spheres ); 00778 RemoveElementsByCollision( 0, tools, 0, spheres ); 00779 //--------------------------------------------------------------- 00780 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00781 GLfloat tempMat[16]; 00782 RemoveConnectionsByCollision( 0, 0, tempMat, tempMat ); 00783 RemoveConnectionsByCollision( 0, 0, tempMat, tempMat ); 00784 #endif//TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00785 00786 //=============================================================== 00787 //PrioritizeTextures(); 00788 //*/ 00789 00790 //--------------------------------------------------------------- 00791 return 0;//return true; 00792 } // END: InitializeFromGridGeneratorDataFloat Fn 00793 //----------------------------------------------------------------------------- 00794 // Load from a file 00795 template <typename T> 00796 bool ModelDeformableGLSL<T>::LoadFromFile ( const std::string & fileName ) 00797 { 00798 //=============================================================== 00799 // CHECK COMPILATION OPTIONS 00800 //=============================================================== 00801 //=============================================================== 00802 // CLEAR CURRENT DATA 00803 //=============================================================== 00804 //=============================================================== 00805 // LOAD PARAMETERS 00806 //=============================================================== 00807 //=============================================================== 00808 // LOAD TEXTURES: (- not load / + load) 00809 // - home position --- m_3DTextureHomePosition 00810 // + position --- m_3DTexturePosition 00811 // + connectivity (3x3 or one) --- m_3DTextureConnectivity 00812 // + ellipsoid influence (intp) --- m_3DTextureEllipsoidInfluence 00813 // - collision detection --- m_3DTextureCollisionDetection 00814 // - offsets for grabbing --- m_3DTextureOffsetValues 00815 //=============================================================== 00816 //=============================================================== 00817 // CREATE THE DEFORMABLE MODEL --- INITIALIZE SHADERS 00818 //=============================================================== 00819 //=============================================================== 00820 // SET PARAMETERS 00821 //=============================================================== 00822 00823 //=============================================================== 00824 // Open file 00825 std::ifstream inFile( fileName.c_str(), std::ios::in ); 00826 if ( !inFile ) { 00827 #ifdef TAPs_DEBUG_MODE 00828 #ifdef TAPs_USE_WXWIDGETS 00829 wxLogError( wxT( "Can't open input file \"%s\"\n" ), fileName.c_str() ); 00830 #else 00831 std::cout << "Can't open input file \"" << fileName << "\"" << std::endl; 00832 #endif 00833 #else 00834 std::cerr << "Can't open input file \"" << fileName << "\"" << std::endl; 00835 #endif 00836 return false; 00837 } 00838 else { 00839 //wxLogError( wxT( "Save to file \"%s\"\n" ), fileName.c_str() ); 00840 } 00841 //=============================================================== 00842 00843 //=============================================================== 00844 // START: Check Compilation Options 00845 //--------------------------------------------------------------- 00846 // ................................ 00847 //--------------------------------------------------------------- 00848 // END: Check Compilation Options 00849 //=============================================================== 00850 00851 //=============================================================== 00852 // START: Clear Current Data 00853 //--------------------------------------------------------------- 00854 Clear(); 00855 //--------------------------------------------------------------- 00856 // END: Clear Current Data 00857 //=============================================================== 00858 00859 int i = 0; 00860 const int SIZE = 256; 00861 char line[SIZE]; 00862 00863 //=============================================================== 00864 // Check the header file 00865 inFile.getline( line, SIZE ); 00866 if ( strncmp( line,"#DEFORMABLE_OBJECT#", sizeof("#DEFORMABLE_OBJECT#") ) ) { 00867 #ifdef TAPs_DEBUG_MODE 00868 #ifdef TAPs_USE_WXWIDGETS 00869 wxLogError( wxT( "The input file \"%s\" is not for deformable object!\n" ), fileName.c_str() ); 00870 #else 00871 std::cout << "The input file \"" << fileName << "\" is not for deformable object!" << std::endl; 00872 #endif 00873 #else 00874 std::cerr << "The input file \"" << fileName << "\" is not for deformable object!" << std::endl; 00875 #endif 00876 return false; 00877 } 00878 //=============================================================== 00879 00880 //=============================================================== 00881 // The file is for deformable object, so process it. 00882 //--------------------------------------------------------------- 00883 // Temp Data 00884 GLfloat * pPositions = NULL; // current positions 00885 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 00886 GLfloat * pConnections = NULL; // connectivities 00887 #endif 00888 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00889 GLubyte * pConnections = NULL; // connectivities 00890 #endif 00891 GLfloat * pEllipsoids = NULL; // ellipsoid influences, i.e., interpolation values 00892 //------------------------------------------- 00893 // Default Values of Textures for Positions 00894 GLenum target = GL_TEXTURE_3D; 00895 GLint level = 0; 00896 GLint internalFormat = GL_RGBA32F_ARB; 00897 GLint border = 0; 00898 //GLenum pixelFormat = GL_RGB; 00899 GLenum pixelFormat = GL_RGBA; 00900 GLenum dataType = GL_FLOAT; 00901 //------------------------------------------- 00902 //--------------------------------- 00903 // TEMP VISUALIZATION VALUES 00904 // For RT Gen Mesh 00905 bool bUseGlobalIntp; 00906 T tGlobalIntpVal; 00907 bool bDrawnWithPNTris; 00908 int iPNTrisSmoothness; 00909 GLuint ui3DTextureID; 00910 //--------------------------------- 00911 // For 3D Texture 00912 //... 00913 //--------------------------------- 00914 while( inFile && !inFile.eof() ) { 00915 inFile.getline( line, SIZE ); 00916 if ( !strncmp( line,"#COMPILATION_OPTIONS#", sizeof("#COMPILATION_OPTIONS#") ) ) { 00917 if ( !ProcessLinesOfCompilationOptions( inFile ) ) { 00918 return false; 00919 } 00920 } 00921 if ( !strncmp( line,"#VISUALIZED_BY_RT_GEN_MESH#", sizeof("#VISUALIZED_BY_RT_GEN_MESH#") ) ) { 00922 if ( IsVisualizedByRTGenMesh() ) { 00923 if ( !ProcessLinesOfVisualizedByRTGenMesh( inFile, 00924 bUseGlobalIntp, 00925 tGlobalIntpVal, 00926 bDrawnWithPNTris, 00927 iPNTrisSmoothness, 00928 ui3DTextureID 00929 ) ) { 00930 return false; 00931 } 00932 } 00933 if ( IsVisualizedBy3DTexture() ) { 00934 if ( !ProcessLinesOfVisualizedBy3DTexture( inFile ) ) { 00935 return false; 00936 } 00937 } 00938 } 00939 if ( !strncmp( line,"#PARAMETERS#", sizeof("#PARAMETERS#") ) ) { 00940 if ( !ProcessLinesOfParameters( inFile ) ) { 00941 return false; 00942 } 00943 } 00944 if ( !strncmp( line,"#SPRING_REST_LENGTH#", sizeof("#SPRING_REST_LENGTH#") ) ) { 00945 if ( !ProcessLinesOfSpringRestLength( inFile ) ) { 00946 return false; 00947 } 00948 } 00949 if ( !strncmp( line,"#SPRING_STIFFNESS#", sizeof("#SPRING_STIFFNESS#") ) ) { 00950 if ( !ProcessLinesOfSpringStiffness( inFile ) ) { 00951 return false; 00952 } 00953 } 00954 if ( !strncmp( line,"#SPRING_DAMPING#", sizeof("#SPRING_DAMPING#") ) ) { 00955 if ( !ProcessLinesOfSpringDamping( inFile ) ) { 00956 return false; 00957 } 00958 } 00959 if ( !strncmp( line,"#POSITIONS#", sizeof("#POSITIONS#") ) ) { 00960 pPositions = new GLfloat[m_iTotalElements * 4]; 00961 if ( !ProcessLinesOfPositions( inFile, pPositions ) ) { 00962 delete [] pPositions; 00963 Clear(); 00964 return false; 00965 } 00966 //--------------------------------------------- 00967 // Setup Visualization 00968 int errCode = SetupVisualization( NULL ); 00969 if ( errCode < 0 ) { 00970 Clear(); 00971 //return -1000 + errCode; 00972 return false; 00973 } 00974 //--------------------------------------------- 00975 // Setup a 3D Texture for Gradients 00976 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00977 m_3DTextureGradient = SetupA3DTexture( 00978 target, level, GL_RGB16F_ARB, 00979 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00980 border, GL_RGB, GL_FLOAT, 00981 pPositions, 00982 1, // gradeint needs only one 3D texture 00983 GL_NEAREST, GL_NEAREST, 00984 GL_CLAMP, GL_CLAMP, GL_CLAMP 00985 ); 00986 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00987 00988 // Setup a 3D Texture for Home Positions 00989 m_3DTextureHomePosition = SetupA3DTexture( 00990 target, level, internalFormat, 00991 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00992 border, pixelFormat, dataType, 00993 pPositions, 00994 1, // home position needs only one 3D texture 00995 GL_NEAREST, GL_NEAREST, 00996 GL_CLAMP, GL_CLAMP, GL_CLAMP 00997 ); 00998 00999 // Setup 3D Textures for Positions -- current, next, and previous 01000 m_3DTexturePosition = SetupA3DTexture( 01001 target, level, internalFormat, 01002 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 01003 border, pixelFormat, dataType, 01004 pPositions, 01005 3, // current, next, and previous 01006 //GL_NEAREST, GL_NEAREST, 01007 GL_LINEAR, GL_LINEAR, 01008 GL_CLAMP, GL_CLAMP, GL_CLAMP 01009 ); 01010 //--------------------------------------------- 01011 01012 //============================================= 01013 // Setup a 3D Texture for Collision Detection 01014 // Current Collision Info is (index [0]) 01015 //--------------------------------------------- 01016 // Clear data for collision detection texture 01017 for ( int i = 0; i < m_vGridResolution[0]*m_vGridResolution[1]*m_vGridResolution[2]*4; ++i ) { 01018 pPositions[i] = 0; 01019 } 01020 //----------------------------------- 01021 m_3DTextureCollisionDetection = SetupA3DTexture( 01022 target, level, internalFormat, 01023 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 01024 border, pixelFormat, dataType, 01025 pPositions, 01026 1, 01027 GL_NEAREST, GL_NEAREST, 01028 GL_CLAMP, GL_CLAMP, GL_CLAMP 01029 ); 01030 //--------------------------------------------- 01031 //============================================= 01032 01033 //============================================= 01034 // Setup a 3D Texture for Offset Values 01035 // Current Offset Values is (index [0]) 01036 //--------------------------------------------- 01037 m_3DTextureOffsetValues = SetupA3DTexture( 01038 target, level, internalFormat, 01039 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 01040 border, pixelFormat, dataType, 01041 pPositions, 01042 1, 01043 GL_NEAREST, GL_NEAREST, 01044 GL_CLAMP, GL_CLAMP, GL_CLAMP 01045 ); 01046 //--------------------------------------------- 01047 //============================================= 01048 01049 01050 delete [] pPositions; 01051 pPositions = NULL; 01052 } 01053 if ( !strncmp( line,"#CONNECTIONS#", sizeof("#CONNECTIONS#") ) ) { 01054 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01055 pConnections = new GLfloat[m_iTotalElements * 3 * 3 * 3]; // 3x3 x rgb 01056 #endif 01057 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01058 pConnections = new GLubyte[m_iTotalElements * 4]; // 1 x rgba 01059 #endif 01060 if ( !ProcessLinesOfConnections( inFile, pConnections ) ) { 01061 delete [] pConnections; 01062 Clear(); 01063 return false; 01064 } 01065 //--------------------------------------------- 01066 // Values of Textures for Connectivities 01067 // 4 components for one FCB+1, and 3(width) x 3(height) for one plane 01068 GLenum target = m_3DTexturePosition->GetTarget(); 01069 GLint level = m_3DTexturePosition->GetLevel(); 01070 GLint internalFormat = GL_RGBA; 01071 GLsizei width = m_3DTexturePosition->GetWidth(); 01072 GLsizei height = m_3DTexturePosition->GetHeight(); 01073 GLsizei depth = m_3DTexturePosition->GetDepth(); 01074 GLint border = m_3DTexturePosition->GetBorder(); 01075 GLenum pixelFormat = GL_RGBA; 01076 GLenum dataType = GL_UNSIGNED_BYTE; 01077 // 01078 unsigned char internalFormatNumOfComponents = 4; 01079 unsigned char pixelFormatNumOfComponents = 4; 01080 // 01081 unsigned short numOfTextures = 2; 01082 //----------------------------------- 01083 // One 3D texture for Connectivities 01084 m_3DTextureConnectivity = new Texture( 01085 target, level, internalFormat, 01086 width, height, depth, 01087 border, pixelFormat, dataType, 01088 //connectivityData, // texels 01089 NULL , // texels 01090 numOfTextures, 01091 GL_NEAREST, GL_NEAREST, // mag & min filter 01092 GL_CLAMP, GL_CLAMP, GL_CLAMP // wrap s, t, & r 01093 ); 01094 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 01095 //----------------------------------- 01096 // Current (for reading) [0] & Change (for writing) [1] 01097 for ( int i = 0; i < numOfTextures; ++i ) { 01098 GLuint texName = m_3DTextureConnectivity->GetTexture( i ); 01099 glBindTexture( GL_TEXTURE_3D, texName ); 01100 glTexImage3D( 01101 m_3DTextureConnectivity->GetTarget(), 01102 m_3DTextureConnectivity->GetLevel(), 01103 m_3DTextureConnectivity->GetInternalFormat(), 01104 m_3DTextureConnectivity->GetWidth(), 01105 m_3DTextureConnectivity->GetHeight(), 01106 m_3DTextureConnectivity->GetDepth(), 01107 m_3DTextureConnectivity->GetBorder(), 01108 m_3DTextureConnectivity->GetPixelFormat(), 01109 m_3DTextureConnectivity->GetDataType(), 01110 pConnections 01111 ); 01112 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 01113 } 01114 //--------------------------------------------- 01115 //********************************************* 01116 // The coordinate (s,t) values must be mapped to range [0,1] 01117 SetupTextureCoordinateValues( 01118 offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition, 01119 m_3DTexturePosition->GetWidth(), 01120 m_3DTexturePosition->GetHeight(), 01121 m_3DTexturePosition->GetDepth() 01122 ); 01123 SetupTextureCoordinateValues( 01124 offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection, 01125 width, 01126 height, 01127 depth 01128 ); 01129 //********************************************* 01130 //--------------------------------------------- 01131 delete [] pConnections; 01132 pConnections = NULL; 01133 } 01134 if ( !strncmp( line,"#ELLIPSOID_INFLUENCES#", sizeof("#ELLIPSOID_INFLUENCES#") ) ) { 01135 pEllipsoids = new GLfloat[m_iTotalElements * 3]; // 1 x rgb 01136 if ( !ProcessLinesOfEllipsoidInfluences( inFile, pEllipsoids ) ) { 01137 delete [] pEllipsoids; 01138 Clear(); 01139 return false; 01140 } 01141 //--------------------------------------------- 01142 m_3DTextureEllipsoidInfluence = SetupA3DTexture( 01143 //target, level, internalFormat, 01144 target, level, GL_RGB, 01145 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 01146 //border, pixelFormat, dataType, 01147 border, GL_RGB, GL_FLOAT, 01148 pEllipsoids, 01149 1, 01150 GL_NEAREST, GL_NEAREST, 01151 GL_CLAMP, GL_CLAMP, GL_CLAMP 01152 ); 01153 delete [] pEllipsoids; 01154 pEllipsoids = NULL; 01155 } 01156 //std::cout << ++i << ": " << line << "\n"; 01157 } 01158 //--------------------------------------------------------------- 01159 //=============================================================== 01160 01161 //=============================================================== 01162 // START: Set up Textures 01163 //--------------------------------------------------------------- 01164 // ................................ 01165 //--------------------------------------------------------------- 01166 // END: Set up Textures 01167 //=============================================================== 01168 01169 // Close File 01170 inFile.close(); 01171 01172 //------------------------------------------- 01173 // Set up Buffers and GLSL Shaders 01174 int ret = SetupBuffersAndShaders(); 01175 if ( ret != 0 ) { 01176 std::cout << "SetupBuffersAndShaders() returns : " << ret << std::endl; 01177 //assert( false ); 01178 return false; 01179 } 01180 //------------------------------------------- 01181 01182 //------------------------------------------- 01183 // Setup Parameters 01184 //SetParametersFromTheLoadedFile(); 01185 //------------------------------------------- 01186 01187 // DEBUG 01188 //std::cout << "Before UpdateParametersForShaders\n"; 01189 01190 //------------------------------------------- 01191 // Update Parameters for Visualizations 01192 if ( IsVisualizedByRTGenMesh() ) { 01193 RetVisualRTGenMesh()->SetUseGlobalInterpolationValue( bUseGlobalIntp ); 01194 RetVisualRTGenMesh()->SetGlobalInterpolationValue( tGlobalIntpVal ); 01195 RetVisualRTGenMesh()->SetStatusDrawnWithPNTriangle( bDrawnWithPNTris ); 01196 RetVisualRTGenMesh()->SetPNTriangleSmoothness( iPNTrisSmoothness ); 01197 RetVisualRTGenMesh()->Set3DTexture( ui3DTextureID ); 01198 } 01199 if ( IsVisualizedBy3DTexture() ) { 01200 //... 01201 } 01202 //------------------------------------------- 01203 01204 //------------------------------------------- 01205 // Update Parameters for GLSL Shaders 01206 UpdateParametersForShaders(); 01207 //------------------------------------------- 01208 01209 // DEBUG 01210 //std::cout << "After UpdateParametersForShaders\n"; 01211 01212 //* 01213 //=============================================================== 01214 // FIX BY HACKING 01215 //--------------------------------------------------------------- 01216 // There is a delay when UpdateConnectivity fn is called for the 01217 // first two times. 01218 // So to avoid these delays during simulation, 01219 // UpdateConnectivity fn are called twice here 01220 // (in RemoveElementsByCollision fn). 01221 // So that the delays are moved to preprocessing time. 01222 // Where one call each does not work. 01223 GLfloat tools[8], spheres[32]; 01224 RemoveElementsByCollision( 0, tools, 0, spheres ); 01225 RemoveElementsByCollision( 0, tools, 0, spheres ); 01226 //--------------------------------------------------------------- 01227 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01228 GLfloat tempMat[16]; 01229 RemoveConnectionsByCollision( 0, 0, tempMat, tempMat ); 01230 RemoveConnectionsByCollision( 0, 0, tempMat, tempMat ); 01231 #endif//TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01232 //=============================================================== 01233 //PrioritizeTextures(); 01234 //*/ 01235 01236 return true; 01237 } 01238 //----------------------------------------------------------------------------- 01239 // Save to a file 01240 template <typename T> 01241 bool ModelDeformableGLSL<T>::SaveToFile ( const std::string & fileName ) 01242 { 01243 //=============================================================== 01244 // SAVE COMPILATION OPTIONS 01245 //=============================================================== 01246 //=============================================================== 01247 // SAVE PARAMETERS 01248 //=============================================================== 01249 //=============================================================== 01250 // SAVE TEXTURES: (- not save / + save) 01251 // - home position --- m_3DTextureHomePosition 01252 // + position --- m_3DTexturePosition 01253 // + connectivity (3x3 or one) --- m_3DTextureConnectivity 01254 // + ellipsoid influence (intp) --- m_3DTextureEllipsoidInfluence 01255 // - collision detection --- m_3DTextureCollisionDetection 01256 // - offsets for grabbing --- m_3DTextureOffsetValues 01257 //=============================================================== 01258 01259 if ( m_vGridResolution[0] == 0 ) { 01260 #ifdef TAPs_DEBUG_MODE 01261 #ifdef TAPs_USE_WXWIDGETS 01262 wxLogError( wxT( "The deformable object is not initialized yet!" ) ); 01263 #else 01264 std::cout << "The deformable object is not initialized yet!" << std::endl; 01265 #endif 01266 #else 01267 std::cerr << "The deformable object is not initialized yet!" << std::endl; 01268 #endif 01269 return false; 01270 } 01271 01272 // Open file 01273 std::ofstream outFile( fileName.c_str(), std::ios::out ); 01274 if ( !outFile ) { 01275 #ifdef TAPs_DEBUG_MODE 01276 #ifdef TAPs_USE_WXWIDGETS 01277 wxLogError( wxT( "Can't open output file \"%s\"\n" ), fileName.c_str() ); 01278 #else 01279 std::cout << "Can't open output file \"" << fileName << "\"" << std::endl; 01280 #endif 01281 #else 01282 std::cerr << "Can't open output file \"" << fileName << "\"" << std::endl; 01283 #endif 01284 return false; 01285 } 01286 else { 01287 //wxLogError( wxT( "Save to file \"%s\"\n" ), fileName.c_str() ); 01288 } 01289 01290 //=============================================================== 01291 // START: Write Compilation Options 01292 //--------------------------------------------------------------- 01293 outFile << "#DEFORMABLE_OBJECT#\n\n"; 01294 01295 outFile << "#COMPILATION_OPTIONS#\n"; 01296 outFile << "INTEGRATION: "; 01297 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01298 outFile << "Explicit_Euler\n"; 01299 #endif 01300 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 01301 outFile << "Verlet\n"; 01302 #endif 01303 outFile << "CONNECTIVITY_TEXTURE: "; 01304 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01305 outFile << "3X3_TexelsPerElement\n"; 01306 #endif 01307 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01308 outFile << "One_TexelPerElement\n"; 01309 #endif 01310 outFile << "VISUALIZATION_AVAILABLE:"; 01311 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01312 outFile << " [Real-Time_Mesh_Generation]"; 01313 #endif 01314 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 01315 outFile << " [3D_Texture]"; 01316 #endif 01317 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 01318 outFile << " [Ray_Casting]"; 01319 #endif 01320 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 01321 outFile << " [Predefined_Surface_Mesh]"; 01322 #endif 01323 outFile << "\n"; 01324 01325 //--------------------------------- 01326 outFile << "REAL-TIME_MESH_GENERATION_USES_PN_TRIANGLES: "; 01327 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI 01328 outFile << "No\n"; 01329 #endif 01330 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI 01331 outFile << "Yes\n"; 01332 #endif 01333 //--------------------------------- 01334 01335 //--------------------------------- 01336 outFile << "VISUALIZATION_ON_GPU: "; 01337 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_CPU_RENDERING 01338 outFile << "No\n"; 01339 #endif 01340 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING 01341 outFile << "Yes\n"; 01342 #endif 01343 //--------------------------------- 01344 01345 //--------------------------------- 01346 outFile << "VISUALIZATION_USE_BUFFERS_ON_GPU: "; 01347 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_NOT_USE_BUFFERS 01348 outFile << "No\n"; 01349 #endif 01350 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS 01351 outFile << "Yes\n"; 01352 #endif 01353 //--------------------------------- 01354 01355 //--------------------------------- 01356 outFile << "REAL-TIME_MESH_GENERATION_USES_GRADIENT_TEXTURE: "; 01357 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 01358 outFile << "No\n"; 01359 #endif 01360 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 01361 outFile << "Yes\n"; 01362 #endif 01363 //--------------------------------- 01364 01365 //--------------------------------- 01366 outFile << "REAL-TIME MESH GENERATION USES CUBE TRACKING TEXTURE: "; 01367 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES 01368 outFile << "No\n"; 01369 #endif 01370 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES 01371 outFile << "Yes\n"; 01372 #endif 01373 //--------------------------------- 01374 01375 // ADDED FACE, VERTEX, EDGE CONNECTIVITY OR GRADIENT COMPUTATIONS 01376 01377 //--------------------------------- 01378 outFile << "#END_OF_COMPILATION_OPTIONS#\n\n"; 01379 //--------------------------------------------------------------- 01380 // END: Write Compilation Options 01381 //=============================================================== 01382 01383 //=============================================================== 01384 // START: Save Visualization Parameter Values 01385 //--------------------------------------------------------------- 01386 outFile << "#VISUALIZATIONS#\n"; 01387 //------------------------------------------- 01388 // RT Gen Mesh 01389 if ( IsVisualizedByRTGenMeshAvailable() ) { 01390 outFile << "#VISUALIZED_BY_RT_GEN_MESH#\n"; 01391 outFile << " USE_GLOBAL_INTP: "; 01392 if ( RetVisualRTGenMesh()->GetUseGlobalInterpolationValue() ) outFile << "True\n"; 01393 else outFile << "False\n"; 01394 outFile << " GLOBAL_INTP_VALUE: " << RetVisualRTGenMesh()->GetGlobalInterpolationValue() << "\n"; 01395 outFile << " DRAWN_WITH_PNTRIANGLES: "; 01396 if ( RetVisualRTGenMesh()->GetStatusDrawnWithPNTriangle() ) outFile << "True\n"; 01397 else outFile << "False\n"; 01398 outFile << " PNTRIANGLES_SMOOTHNESS: " << RetVisualRTGenMesh()->GetPNTriangleSmoothness() << "\n"; 01399 outFile << " 3D_TEXTURE_ID: " << RetVisualRTGenMesh()->Get3DTexture() << "\n"; 01400 outFile << "#END_OF_VISUALIZED_BY_RT_GEN_MESH#\n"; 01401 } 01402 //------------------------------------------- 01403 // 3D Texture 01404 if ( IsVisualizedBy3DTextureAvailable() ) { 01405 outFile << "#VISUALIZED_BY_3D_TEXTURE#\n"; 01406 // ... 01407 outFile << "#END_OF_VISUALIZED_BY_3D_TEXTURE#\n"; 01408 } 01409 //------------------------------------------- 01410 outFile << "#END_OF_VISUALIZATIONS#\n\n"; 01411 //--------------------------------------------------------------- 01412 // END: Save Visualization Parameter Values 01413 //=============================================================== 01414 01415 //=============================================================== 01416 // START: Save Parameter Values 01417 //--------------------------------------------------------------- 01418 outFile << "#PARAMETERS#\n"; 01419 outFile << "AABB_HIGH_POINT: " << GetBoundingAABBHighPoint()[0] << " " << GetBoundingAABBHighPoint()[1] << " " << GetBoundingAABBHighPoint()[2] << "\n"; 01420 outFile << "AABB_LOW_POINT: " << GetBoundingAABBLowPoint()[0] << " " << GetBoundingAABBLowPoint()[1] << " " << GetBoundingAABBLowPoint()[2] << "\n"; 01421 outFile << "GRID_RESOLUTION: " << m_vGridResolution[0] << " " << m_vGridResolution[1] << " " << m_vGridResolution[2] << "\n"; 01422 outFile << "GRID_DIMENSION: " << m_vGridDimension[0] << " " << m_vGridDimension[1] << " " << m_vGridDimension[2] << "\n"; 01423 outFile << "TOTAL_ELEMENTS: " << m_iTotalElements << "\n"; 01424 outFile << "ELEMENT_VOLUME: " << m_fElementVolume << "\n"; 01425 outFile << "ELEMENT_MASS: " << m_tElementMass << "\n"; 01426 outFile << "ELEMENT_APPROX_RADIUS: " << m_tElementApproxRadius << "\n"; 01427 outFile << "SIM_THRESHOLD: " << m_tSimThreshold << "\n"; 01428 outFile << "SIM_TIME_STEP: " << m_tTimeStep << "\n"; 01429 outFile << "SIM_FRAMES_PER_PULSATION: " << m_usFramesPerPulsation << "\n"; 01430 outFile << "MAX_RELAX_CONSTRAINT: " << m_tMaxRelaxation << "\n"; 01431 outFile << "MIN_RELAX_CONSTRAINT: " << m_tMinRelaxation << "\n"; 01432 //--------------------------------- 01433 outFile << "#END_OF_PARAMETERS#\n\n"; 01434 //--------------------------------- 01435 // REST LENGTH OF SPRINGS 01436 outFile << "#27 Spring Rest Lengths\n"; 01437 outFile << "#SPRING_REST_LENGTH#\n"; 01438 // Front Plane 01439 outFile << "REST_LENGTH_FNW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ] << "\n"; 01440 outFile << "REST_LENGTH_FN: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ] << "\n"; 01441 outFile << "REST_LENGTH_FNE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ] << "\n"; 01442 outFile << "REST_LENGTH_FW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ] << "\n"; 01443 outFile << "REST_LENGTH_F: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ] << "\n"; 01444 outFile << "REST_LENGTH_FE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ] << "\n"; 01445 outFile << "REST_LENGTH_FSW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ] << "\n"; 01446 outFile << "REST_LENGTH_FS: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ] << "\n"; 01447 outFile << "REST_LENGTH_FSE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ] << "\n"; 01448 // Center Plane 01449 outFile << "REST_LENGTH_NW: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ] << "\n"; 01450 outFile << "REST_LENGTH_N: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ] << "\n"; 01451 outFile << "REST_LENGTH_NE: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ] << "\n"; 01452 outFile << "REST_LENGTH_W: " << SPRING_PROP.REST_LENGTH[ SpringProp::WEST ] << "\n"; 01453 outFile << "REST_LENGTH_H: " << SPRING_PROP.REST_LENGTH[ SpringProp::HOME ] << "\n"; 01454 outFile << "REST_LENGTH_E: " << SPRING_PROP.REST_LENGTH[ SpringProp::EAST ] << "\n"; 01455 outFile << "REST_LENGTH_SW: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ] << "\n"; 01456 outFile << "REST_LENGTH_S: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ] << "\n"; 01457 outFile << "REST_LENGTH_SE: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ] << "\n"; 01458 // Back Plane 01459 outFile << "REST_LENGTH_BNW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ] << "\n"; 01460 outFile << "REST_LENGTH_BN: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ] << "\n"; 01461 outFile << "REST_LENGTH_BNE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ] << "\n"; 01462 outFile << "REST_LENGTH_BW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ] << "\n"; 01463 outFile << "REST_LENGTH_B: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK ] << "\n"; 01464 outFile << "REST_LENGTH_BE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ] << "\n"; 01465 outFile << "REST_LENGTH_BSW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ] << "\n"; 01466 outFile << "REST_LENGTH_BS: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ] << "\n"; 01467 outFile << "REST_LENGTH_BSE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ] << "\n"; 01468 //--------------------------------- 01469 outFile << "#END_OF_SPRING_REST_LENGTH#\n\n"; 01470 //--------------------------------- 01471 // STIFFNESS OF SPRINGS 01472 outFile << "#27 Spring Stiffnesses\n"; 01473 outFile << "#SPRING_STIFFNESS#\n"; 01474 // Front Plane 01475 outFile << "STIFFNESS_FNW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ] << "\n"; 01476 outFile << "STIFFNESS_FN: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ] << "\n"; 01477 outFile << "STIFFNESS_FNE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ] << "\n"; 01478 outFile << "STIFFNESS_FW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ] << "\n"; 01479 outFile << "STIFFNESS_F: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT ] << "\n"; 01480 outFile << "STIFFNESS_FE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ] << "\n"; 01481 outFile << "STIFFNESS_FSW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ] << "\n"; 01482 outFile << "STIFFNESS_FS: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ] << "\n"; 01483 outFile << "STIFFNESS_FSE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ] << "\n"; 01484 // Center Plane 01485 outFile << "STIFFNESS_NW: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ] << "\n"; 01486 outFile << "STIFFNESS_N: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH ] << "\n"; 01487 outFile << "STIFFNESS_NE: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ] << "\n"; 01488 outFile << "STIFFNESS_W: " << SPRING_PROP.STIFFNESS[ SpringProp::WEST ] << "\n"; 01489 outFile << "STIFFNESS_H: " << SPRING_PROP.STIFFNESS[ SpringProp::HOME ] << "\n"; 01490 outFile << "STIFFNESS_E: " << SPRING_PROP.STIFFNESS[ SpringProp::EAST ] << "\n"; 01491 outFile << "STIFFNESS_SW: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ] << "\n"; 01492 outFile << "STIFFNESS_S: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ] << "\n"; 01493 outFile << "STIFFNESS_SE: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ] << "\n"; 01494 // Back Plane 01495 outFile << "STIFFNESS_BNW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ] << "\n"; 01496 outFile << "STIFFNESS_BN: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ] << "\n"; 01497 outFile << "STIFFNESS_BNE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ] << "\n"; 01498 outFile << "STIFFNESS_BW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ] << "\n"; 01499 outFile << "STIFFNESS_B: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK ] << "\n"; 01500 outFile << "STIFFNESS_BE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ] << "\n"; 01501 outFile << "STIFFNESS_BSW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ] << "\n"; 01502 outFile << "STIFFNESS_BS: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ] << "\n"; 01503 outFile << "STIFFNESS_BSE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ] << "\n"; 01504 //--------------------------------- 01505 outFile << "#END_OF_SPRING_STIFFNESS#\n\n"; 01506 //--------------------------------- 01507 // DAMPING OF SPRINGS 01508 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01509 outFile << ""; // DAMPING OF SPRINGS 01510 #endif 01511 //--------------------------------- 01512 // THE DAMPER FOR VERLET INTEGRATION 01513 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 01514 outFile << ""; // THE ONLY ONE DAMPER --- NEED TO ADD TO THE TEXTURE_ONE --- 01515 // THE CURRENT DEFAULT IS 1.0 HARD CODED IN THE SHADER 01516 #endif 01517 //--------------------------------- 01518 outFile << "\n"; 01519 //--------------------------------------------------------------- 01520 // END: Save Parameter Values 01521 //=============================================================== 01522 01523 glPushAttrib( GL_ALL_ATTRIB_BITS ); 01524 //=============================================================== 01525 // START: Save Position Texture 01526 //--------------------------------------------------------------- 01527 { 01528 Texture * texture3DPosition = RetObject3DTexturePosition(); 01529 //------------------------------------------------- 01530 GLsizei sizeForPosition = 01531 texture3DPosition->GetWidth() * 01532 texture3DPosition->GetHeight() * 01533 texture3DPosition->GetDepth() * 01534 texture3DPosition->GetInternalFormatNumberOfComponents(); 01535 GLfloat * dataForPosition = new GLfloat[ sizeForPosition ]; 01536 //------------------------------------------------- 01537 // Read data for positions from a texture to memory 01538 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 01539 texture3DPosition->BindTexture(0); 01540 glGetTexImage( 01541 texture3DPosition->GetTarget(), 01542 texture3DPosition->GetLevel(), 01543 texture3DPosition->GetPixelFormat(), 01544 texture3DPosition->GetDataType(), 01545 dataForPosition 01546 ); 01547 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 01548 //------------------------------------------------- 01549 outFile << "#POSITIONS#\n"; 01550 outFile << std::setiosflags( std::ios::right );// << std::setprecision( 6 ); 01551 int i = 0; 01552 for ( int x = 0; x < texture3DPosition->GetWidth(); ++x ) { 01553 for ( int y = 0; y < texture3DPosition->GetHeight(); ++y ) { 01554 for ( int z = 0; z < texture3DPosition->GetDepth(); ++z ) { 01555 outFile << "[" << x << "," << y << "," << z << "]:"; 01556 for ( int d = 0; d < texture3DPosition->GetInternalFormatNumberOfComponents(); ++d ) { 01557 //outFile << setw( 16 ) << dataForPosition[i++]; 01558 outFile << " " << dataForPosition[i++]; 01559 } 01560 outFile << "\n"; 01561 } 01562 } 01563 } 01564 outFile << "#END_OF_POSITIONS#\n\n"; 01565 //------------------------------------------------- 01566 } 01567 //--------------------------------------------------------------- 01568 // END: Save Position Texture 01569 //=============================================================== 01570 01571 //=============================================================== 01572 // START: Save Connectivity Texture 01573 //--------------------------------------------------------------- 01574 { 01575 Texture * texture3DConnectivity = RetObject3DTextureConnectivity(); 01576 //------------------------------------------------- 01577 GLsizei sizeForConnectivity = 01578 texture3DConnectivity->GetWidth() * 01579 texture3DConnectivity->GetHeight() * 01580 texture3DConnectivity->GetDepth() * 01581 texture3DConnectivity->GetInternalFormatNumberOfComponents(); 01582 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01583 GLubyte * dataForConnectivity = new GLubyte[ sizeForConnectivity ]; 01584 #endif 01585 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01586 GLfloat * dataForConnectivity = new GLfloat[ sizeForConnectivity ]; 01587 #endif 01588 //------------------------------------------------- 01589 // Read data for connectivity from a texture to memory 01590 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 01591 texture3DConnectivity->BindTexture(0); 01592 glGetTexImage( 01593 texture3DConnectivity->GetTarget(), 01594 texture3DConnectivity->GetLevel(), 01595 texture3DConnectivity->GetPixelFormat(), 01596 texture3DConnectivity->GetDataType(), 01597 dataForConnectivity 01598 ); 01599 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 01600 //------------------------------------------------- 01601 outFile << "#CONNECTIONS#\n"; 01602 outFile << std::setiosflags( std::ios::right );// << std::setprecision( 6 ); 01603 int i = 0; 01604 for ( int x = 0; x < texture3DConnectivity->GetWidth(); ++x ) { 01605 for ( int y = 0; y < texture3DConnectivity->GetHeight(); ++y ) { 01606 for ( int z = 0; z < texture3DConnectivity->GetDepth(); ++z ) { 01607 outFile << "[" << x << "," << y << "," << z << "]:"; 01608 for ( int d = 0; d < texture3DConnectivity->GetInternalFormatNumberOfComponents(); ++d ) { 01609 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01610 //outFile << setw( 4 ) << static_cast<int>( dataForConnectivity[i++] ); 01611 outFile << " " << static_cast<int>( dataForConnectivity[i++] ); 01612 #endif 01613 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01614 //outFile << setw( 16 ) << dataForConnectivity[i++]; 01615 outFile << " " << dataForConnectivity[i++]; 01616 #endif 01617 } 01618 outFile << "\n"; 01619 } 01620 } 01621 } 01622 outFile << "#END_OF_CONNECTIONS#\n\n"; 01623 //------------------------------------------------- 01624 } 01625 //--------------------------------------------------------------- 01626 // END: Save Connectivity Texture 01627 //=============================================================== 01628 01629 //=============================================================== 01630 // START: Save Ellipsoid Influence Texture 01631 //--------------------------------------------------------------- 01632 { 01633 Texture * texture3DEllipsoidInfluence = RetObject3DTextureEllipsoidInfluence(); 01634 //------------------------------------------------- 01635 GLsizei sizeForEllipsoidInfluence = 01636 texture3DEllipsoidInfluence->GetWidth() * 01637 texture3DEllipsoidInfluence->GetHeight() * 01638 texture3DEllipsoidInfluence->GetDepth() * 01639 texture3DEllipsoidInfluence->GetInternalFormatNumberOfComponents(); 01640 GLfloat * dataForEllipsoidInfluence = new GLfloat[ sizeForEllipsoidInfluence ]; 01641 //------------------------------------------------- 01642 // Read data for positions from a texture to memory 01643 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 01644 texture3DEllipsoidInfluence->BindTexture(0); 01645 glGetTexImage( 01646 texture3DEllipsoidInfluence->GetTarget(), 01647 texture3DEllipsoidInfluence->GetLevel(), 01648 texture3DEllipsoidInfluence->GetPixelFormat(), 01649 texture3DEllipsoidInfluence->GetDataType(), 01650 dataForEllipsoidInfluence 01651 ); 01652 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 01653 //------------------------------------------------- 01654 outFile << "#ELLIPSOID_INFLUENCES#\n"; 01655 outFile << std::setiosflags( std::ios::right );// << std::setprecision( 6 ); 01656 int i = 0; 01657 for ( int x = 0; x < texture3DEllipsoidInfluence->GetWidth(); ++x ) { 01658 for ( int y = 0; y < texture3DEllipsoidInfluence->GetHeight(); ++y ) { 01659 for ( int z = 0; z < texture3DEllipsoidInfluence->GetDepth(); ++z ) { 01660 outFile << "[" << x << "," << y << "," << z << "]:"; 01661 for ( int d = 0; d < texture3DEllipsoidInfluence->GetInternalFormatNumberOfComponents(); ++d ) { 01662 //outFile << setw( 16 ) << dataForEllipsoidInfluence[i++]; 01663 outFile << " " << dataForEllipsoidInfluence[i++]; 01664 } 01665 outFile << "\n"; 01666 } 01667 } 01668 } 01669 outFile << "#END_OF_ELLIPSOID_INFLUENCES#\n\n"; 01670 //------------------------------------------------- 01671 } 01672 //--------------------------------------------------------------- 01673 // END: Save Ellipsoid Influence Texture 01674 //=============================================================== 01675 //--------------------------------------------------------------- 01676 glPopAttrib(); 01677 01678 // Close file 01679 outFile.close(); 01680 01681 return true; 01682 } 01683 //----------------------------------------------------------------------------- 01684 // Load from a file 01685 template <typename T> 01686 bool ModelDeformableGLSL<T>::ProcessLinesOfCompilationOptions ( std::ifstream & inFile ) 01687 { 01688 /* 01689 const int SIZE = 256; 01690 char line[SIZE]; 01691 char *delimSpaces = "\t \n"; // tab, space, new line 01692 char *token = NULL; 01693 char *end; 01694 //*/ 01695 01696 return true; 01697 } 01698 //----------------------------------------------------------------------------- 01699 // Load from a file 01700 template <typename T> 01701 bool ModelDeformableGLSL<T>::ProcessLinesOfParameters ( std::ifstream & inFile ) 01702 { 01703 /* 01704 // DEBUG 01705 std::cout << "CHECK ==> m_vGridResolution: " << m_vGridResolution << "\n"; 01706 std::cout << "CHECK ==> m_vGridDimension: " << m_vGridDimension << "\n"; 01707 std::cout << "CHECK ==> m_iTotalElements: " << m_iTotalElements << "\n"; 01708 std::cout << "CHECK ==> m_fElementVolume: " << m_fElementVolume << "\n"; 01709 std::cout << "CHECK ==> m_tElementMass: " << m_tElementMass << "\n"; 01710 std::cout << "CHECK ==> m_tElementApproxRadius: " << m_tElementApproxRadius << "\n"; 01711 std::cout << "CHECK ==> m_tSimThreshold: " << m_tSimThreshold << "\n"; 01712 std::cout << "CHECK ==> m_tTimeStep: " << m_tTimeStep << "\n"; 01713 std::cout << "CHECK ==> m_tMaxRelaxation: " << m_tMaxRelaxation << "\n"; 01714 std::cout << "CHECK ==> m_tMinRelaxation: " << m_tMinRelaxation << "\n"; 01715 //*/ 01716 01717 01718 const int SIZE = 256; 01719 char line[SIZE]; 01720 char *delimSpaces = "\t \n"; // tab, space, new line 01721 char *token = NULL; 01722 char *end; 01723 //----------------------------------------------------- 01724 /* 01725 E.g.: 01726 #PARAMETERS# 01727 line0: GRID_RESOLUTION: 8 8 8 <---- Start Here! 01728 line1: GRID_DIMENSION: 0.284155 0.28572 0.28572 01729 line2: TOTAL_ELEMENTS: 512 01730 line3: ELEMENT_VOLUME: 0.0231972 01731 line4: ELEMENT_MASS: 1 01732 line5: ELEMENT_APPROX_RADIUS: 0.142599 01733 line6: SIM_THRESHOLD: 101 01734 line7: SIM_TIME_STEP: 0.01 01735 line8: MAX_RELAX_CONSTRAINT: 1.1 01736 line9: MIN_RELAX_CONSTRAINT: 0.9 <---- End Here! 01737 //*/ 01738 { 01739 // AABB_HIGH_POINT: 01740 inFile.getline( line, SIZE ); 01741 token = strtok( line, delimSpaces ); // the first token 01742 if ( !strcmp( token, "AABB_HIGH_POINT:" ) ) { 01743 Vector3<T> vHighPt; 01744 vHighPt[0] = strtod( strtok( NULL, delimSpaces ), &end ); 01745 vHighPt[1] = strtod( strtok( NULL, delimSpaces ), &end ); 01746 vHighPt[2] = strtod( strtok( NULL, delimSpaces ), &end ); 01747 SetBoundingAABBHighPoint( vHighPt ); 01748 } 01749 01750 // AABB_LOW_POINT: 01751 inFile.getline( line, SIZE ); 01752 token = strtok( line, delimSpaces ); // the first token 01753 if ( !strcmp( token, "AABB_LOW_POINT:" ) ) { 01754 Vector3<T> vLowPt; 01755 vLowPt[0] = strtod( strtok( NULL, delimSpaces ), &end ); 01756 vLowPt[1] = strtod( strtok( NULL, delimSpaces ), &end ); 01757 vLowPt[2] = strtod( strtok( NULL, delimSpaces ), &end ); 01758 SetBoundingAABBLowPoint( vLowPt ); 01759 } 01760 01761 // GRID_RESOLUTION: 01762 inFile.getline( line, SIZE ); 01763 token = strtok( line, delimSpaces ); // the first token 01764 if ( !strcmp( token, "GRID_RESOLUTION:" ) ) { 01765 m_vGridResolution[0] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 01766 m_vGridResolution[1] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 01767 m_vGridResolution[2] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 01768 } 01769 01770 // GRID_DIMENSION: 01771 inFile.getline( line, SIZE ); 01772 token = strtok( line, delimSpaces ); // the first token 01773 if ( !strcmp( token, "GRID_DIMENSION:" ) ) { 01774 m_vGridDimension[0] = strtod( strtok( NULL, delimSpaces ), &end ); 01775 m_vGridDimension[1] = strtod( strtok( NULL, delimSpaces ), &end ); 01776 m_vGridDimension[2] = strtod( strtok( NULL, delimSpaces ), &end ); 01777 } 01778 01779 // TOTAL_ELEMENTS: 01780 inFile.getline( line, SIZE ); 01781 token = strtok( line, delimSpaces ); // the first token 01782 if ( !strcmp( token, "TOTAL_ELEMENTS:" ) ) { 01783 m_iTotalElements = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 01784 } 01785 01786 // ELEMENT_VOLUME: 01787 inFile.getline( line, SIZE ); 01788 token = strtok( line, delimSpaces ); // the first token 01789 if ( !strcmp( token, "ELEMENT_VOLUME:" ) ) { 01790 m_fElementVolume = strtod( strtok( NULL, delimSpaces ), &end ); 01791 } 01792 01793 // ELEMENT_MASS: 01794 inFile.getline( line, SIZE ); 01795 token = strtok( line, delimSpaces ); // the first token 01796 if ( !strcmp( token, "ELEMENT_MASS:" ) ) { 01797 m_tElementMass = strtod( strtok( NULL, delimSpaces ), &end ); 01798 } 01799 01800 // ELEMENT_APPROX_RADIUS: 01801 inFile.getline( line, SIZE ); 01802 token = strtok( line, delimSpaces ); // the first token 01803 if ( !strcmp( token, "ELEMENT_APPROX_RADIUS:" ) ) { 01804 m_tElementApproxRadius = strtod( strtok( NULL, delimSpaces ), &end ); 01805 } 01806 01807 // SIM_THRESHOLD: 01808 inFile.getline( line, SIZE ); 01809 token = strtok( line, delimSpaces ); // the first token 01810 if ( !strcmp( token, "SIM_THRESHOLD:" ) ) { 01811 m_tSimThreshold = strtod( strtok( NULL, delimSpaces ), &end ); 01812 } 01813 01814 // SIM_TIME_STEP: 01815 inFile.getline( line, SIZE ); 01816 token = strtok( line, delimSpaces ); // the first token 01817 if ( !strcmp( token, "SIM_TIME_STEP:" ) ) { 01818 m_tTimeStep = strtod( strtok( NULL, delimSpaces ), &end ); 01819 } 01820 01821 // SIM_FRAMES_PER_PULSATION: 01822 inFile.getline( line, SIZE ); 01823 token = strtok( line, delimSpaces ); // the first token 01824 if ( !strcmp( token, "SIM_FRAMES_PER_PULSATION:" ) ) { 01825 m_usFramesPerPulsation = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 01826 } 01827 01828 // MAX_RELAX_CONSTRAINT: 01829 inFile.getline( line, SIZE ); 01830 token = strtok( line, delimSpaces ); // the first token 01831 if ( !strcmp( token, "MAX_RELAX_CONSTRAINT:" ) ) { 01832 m_tMaxRelaxation = strtod( strtok( NULL, delimSpaces ), &end ); 01833 } 01834 01835 // MIN_RELAX_CONSTRAINT: 01836 inFile.getline( line, SIZE ); 01837 token = strtok( line, delimSpaces ); // the first token 01838 if ( !strcmp( token, "MIN_RELAX_CONSTRAINT:" ) ) { 01839 m_tMinRelaxation = strtod( strtok( NULL, delimSpaces ), &end ); 01840 } 01841 } 01842 //----------------------------------------------------- 01843 /* 01844 // DEBUG 01845 std::cout << "CHECK ==> m_vGridResolution: " << m_vGridResolution << "\n"; 01846 std::cout << "CHECK ==> m_vGridDimension: " << m_vGridDimension << "\n"; 01847 std::cout << "CHECK ==> m_iTotalElements: " << m_iTotalElements << "\n"; 01848 std::cout << "CHECK ==> m_fElementVolume: " << m_fElementVolume << "\n"; 01849 std::cout << "CHECK ==> m_tElementMass: " << m_tElementMass << "\n"; 01850 std::cout << "CHECK ==> m_tElementApproxRadius: " << m_tElementApproxRadius << "\n"; 01851 std::cout << "CHECK ==> m_tSimThreshold: " << m_tSimThreshold << "\n"; 01852 std::cout << "CHECK ==> m_tTimeStep: " << m_tTimeStep << "\n"; 01853 std::cout << "CHECK ==> m_tMaxRelaxation: " << m_tMaxRelaxation << "\n"; 01854 std::cout << "CHECK ==> m_tMinRelaxation: " << m_tMinRelaxation << "\n"; 01855 //*/ 01856 //----------------------------------------------------- 01857 return true; 01858 } 01859 //----------------------------------------------------------------------------- 01860 // Load from a file 01861 template <typename T> 01862 bool ModelDeformableGLSL<T>::ProcessLinesOfSpringRestLength ( std::ifstream & inFile ) 01863 { 01864 const int SIZE = 256; 01865 char line[SIZE]; 01866 char *delimSpaces = "\t \n"; // tab, space, new line 01867 char *token = NULL; 01868 char *end; 01869 //----------------------------------------------------- 01870 /* 01871 E.g.: 01872 #SPRING_REST_LENGTH# 01873 line 0: REST_LENGTH_FNW: 0.49398 <---- Start Here! 01874 line 1: REST_LENGTH_FN: 0.404069 01875 line 2: REST_LENGTH_FNE: 0.49398 01876 line 3: REST_LENGTH_FW: 0.402964 01877 line 4: REST_LENGTH_F: 0.28572 01878 line 5: REST_LENGTH_FE: 0.402964 01879 line 6: REST_LENGTH_FSW: 0.49398 01880 line 7: REST_LENGTH_FS: 0.404069 01881 line 8: REST_LENGTH_FSE: 0.49398 01882 line 9: REST_LENGTH_NW: 0.402964 01883 line10: REST_LENGTH_N: 0.28572 01884 line11: REST_LENGTH_NE: 0.402964 01885 line12: REST_LENGTH_W: 0.284155 01886 line13: REST_LENGTH_H: 0 01887 line14: REST_LENGTH_E: 0.284155 01888 line15: REST_LENGTH_SW: 0.402964 01889 line16: REST_LENGTH_S: 0.28572 01890 line17: REST_LENGTH_SE: 0.402964 01891 line18: REST_LENGTH_BNW: 0.49398 01892 line19: REST_LENGTH_BN: 0.404069 01893 line20: REST_LENGTH_BNE: 0.49398 01894 line21: REST_LENGTH_BW: 0.402964 01895 line22: REST_LENGTH_B: 0.28572 01896 line23: REST_LENGTH_BE: 0.402964 01897 line24: REST_LENGTH_BSW: 0.49398 01898 line25: REST_LENGTH_BS: 0.404069 01899 line26: REST_LENGTH_BSE: 0.49398 <---- End Here! 01900 //*/ 01901 { 01902 int i = 0; 01903 // Front Plane 01904 //------------------------------------------------- 01905 // REST_LENGTH_FNW: 01906 inFile.getline( line, SIZE ); 01907 token = strtok( line, delimSpaces ); // the first token 01908 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ] 01909 = strtod( strtok( NULL, delimSpaces ), &end ); 01910 // REST_LENGTH_FN: 01911 inFile.getline( line, SIZE ); 01912 token = strtok( line, delimSpaces ); // the first token 01913 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ] 01914 = strtod( strtok( NULL, delimSpaces ), &end ); 01915 // REST_LENGTH_FNE: 01916 inFile.getline( line, SIZE ); 01917 token = strtok( line, delimSpaces ); // the first token 01918 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ] 01919 = strtod( strtok( NULL, delimSpaces ), &end ); 01920 // REST_LENGTH_FW: 01921 inFile.getline( line, SIZE ); 01922 token = strtok( line, delimSpaces ); // the first token 01923 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ] 01924 = strtod( strtok( NULL, delimSpaces ), &end ); 01925 // REST_LENGTH_F: 01926 inFile.getline( line, SIZE ); 01927 token = strtok( line, delimSpaces ); // the first token 01928 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ] 01929 = strtod( strtok( NULL, delimSpaces ), &end ); 01930 // REST_LENGTH_FE: 01931 inFile.getline( line, SIZE ); 01932 token = strtok( line, delimSpaces ); // the first token 01933 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ] 01934 = strtod( strtok( NULL, delimSpaces ), &end ); 01935 // REST_LENGTH_FSW: 01936 inFile.getline( line, SIZE ); 01937 token = strtok( line, delimSpaces ); // the first token 01938 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ] 01939 = strtod( strtok( NULL, delimSpaces ), &end ); 01940 // REST_LENGTH_FS: 01941 inFile.getline( line, SIZE ); 01942 token = strtok( line, delimSpaces ); // the first token 01943 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ] 01944 = strtod( strtok( NULL, delimSpaces ), &end ); 01945 // REST_LENGTH_FSE: 01946 inFile.getline( line, SIZE ); 01947 token = strtok( line, delimSpaces ); // the first token 01948 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ] 01949 = strtod( strtok( NULL, delimSpaces ), &end ); 01950 01951 // Center Plane 01952 //------------------------------------------------- 01953 // REST_LENGTH_NW: 01954 inFile.getline( line, SIZE ); 01955 token = strtok( line, delimSpaces ); // the first token 01956 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ] 01957 = strtod( strtok( NULL, delimSpaces ), &end ); 01958 // REST_LENGTH_N: 01959 inFile.getline( line, SIZE ); 01960 token = strtok( line, delimSpaces ); // the first token 01961 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ] 01962 = strtod( strtok( NULL, delimSpaces ), &end ); 01963 // REST_LENGTH_NE: 01964 inFile.getline( line, SIZE ); 01965 token = strtok( line, delimSpaces ); // the first token 01966 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ] 01967 = strtod( strtok( NULL, delimSpaces ), &end ); 01968 // REST_LENGTH_W: 01969 inFile.getline( line, SIZE ); 01970 token = strtok( line, delimSpaces ); // the first token 01971 SPRING_PROP.REST_LENGTH[ SpringProp::WEST ] 01972 = strtod( strtok( NULL, delimSpaces ), &end ); 01973 // REST_LENGTH_H: 01974 inFile.getline( line, SIZE ); 01975 token = strtok( line, delimSpaces ); // the first token 01976 SPRING_PROP.REST_LENGTH[ SpringProp::HOME ] 01977 = strtod( strtok( NULL, delimSpaces ), &end ); 01978 // REST_LENGTH_E: 01979 inFile.getline( line, SIZE ); 01980 token = strtok( line, delimSpaces ); // the first token 01981 SPRING_PROP.REST_LENGTH[ SpringProp::EAST ] 01982 = strtod( strtok( NULL, delimSpaces ), &end ); 01983 // REST_LENGTH_SW: 01984 inFile.getline( line, SIZE ); 01985 token = strtok( line, delimSpaces ); // the first token 01986 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ] 01987 = strtod( strtok( NULL, delimSpaces ), &end ); 01988 // REST_LENGTH_S: 01989 inFile.getline( line, SIZE ); 01990 token = strtok( line, delimSpaces ); // the first token 01991 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ] 01992 = strtod( strtok( NULL, delimSpaces ), &end ); 01993 // REST_LENGTH_SE: 01994 inFile.getline( line, SIZE ); 01995 token = strtok( line, delimSpaces ); // the first token 01996 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ] 01997 = strtod( strtok( NULL, delimSpaces ), &end ); 01998 01999 // Back Plane 02000 //------------------------------------------------- 02001 // REST_LENGTH_BNW: 02002 inFile.getline( line, SIZE ); 02003 token = strtok( line, delimSpaces ); // the first token 02004 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ] 02005 = strtod( strtok( NULL, delimSpaces ), &end ); 02006 // REST_LENGTH_BN: 02007 inFile.getline( line, SIZE ); 02008 token = strtok( line, delimSpaces ); // the first token 02009 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ] 02010 = strtod( strtok( NULL, delimSpaces ), &end ); 02011 // REST_LENGTH_BNE: 02012 inFile.getline( line, SIZE ); 02013 token = strtok( line, delimSpaces ); // the first token 02014 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ] 02015 = strtod( strtok( NULL, delimSpaces ), &end ); 02016 // REST_LENGTH_BW: 02017 inFile.getline( line, SIZE ); 02018 token = strtok( line, delimSpaces ); // the first token 02019 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ] 02020 = strtod( strtok( NULL, delimSpaces ), &end ); 02021 // REST_LENGTH_B: 02022 inFile.getline( line, SIZE ); 02023 token = strtok( line, delimSpaces ); // the first token 02024 SPRING_PROP.REST_LENGTH[ SpringProp::BACK ] 02025 = strtod( strtok( NULL, delimSpaces ), &end ); 02026 // REST_LENGTH_BE: 02027 inFile.getline( line, SIZE ); 02028 token = strtok( line, delimSpaces ); // the first token 02029 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ] 02030 = strtod( strtok( NULL, delimSpaces ), &end ); 02031 // REST_LENGTH_BSW: 02032 inFile.getline( line, SIZE ); 02033 token = strtok( line, delimSpaces ); // the first token 02034 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ] 02035 = strtod( strtok( NULL, delimSpaces ), &end ); 02036 // REST_LENGTH_BS: 02037 inFile.getline( line, SIZE ); 02038 token = strtok( line, delimSpaces ); // the first token 02039 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ] 02040 = strtod( strtok( NULL, delimSpaces ), &end ); 02041 // REST_LENGTH_BSE: 02042 inFile.getline( line, SIZE ); 02043 token = strtok( line, delimSpaces ); // the first token 02044 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ] 02045 = strtod( strtok( NULL, delimSpaces ), &end ); 02046 } 02047 //----------------------------------------------------- 02048 /* 02049 // DEBUG 02050 // REST LENGTH OF SPRINGS 02051 std::cout << "#27 Spring Rest Lengths\n"; 02052 std::cout << "#SPRING_REST_LENGTH#\n"; 02053 // Front Plane 02054 std::cout << "REST_LENGTH_FNW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ] << "\n"; 02055 std::cout << "REST_LENGTH_FN: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ] << "\n"; 02056 std::cout << "REST_LENGTH_FNE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ] << "\n"; 02057 std::cout << "REST_LENGTH_FW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ] << "\n"; 02058 std::cout << "REST_LENGTH_F: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ] << "\n"; 02059 std::cout << "REST_LENGTH_FE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ] << "\n"; 02060 std::cout << "REST_LENGTH_FSW: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ] << "\n"; 02061 std::cout << "REST_LENGTH_FS: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ] << "\n"; 02062 std::cout << "REST_LENGTH_FSE: " << SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ] << "\n"; 02063 // Center Plane 02064 std::cout << "REST_LENGTH_NW: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ] << "\n"; 02065 std::cout << "REST_LENGTH_N: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ] << "\n"; 02066 std::cout << "REST_LENGTH_NE: " << SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ] << "\n"; 02067 std::cout << "REST_LENGTH_W: " << SPRING_PROP.REST_LENGTH[ SpringProp::WEST ] << "\n"; 02068 std::cout << "REST_LENGTH_H: " << SPRING_PROP.REST_LENGTH[ SpringProp::HOME ] << "\n"; 02069 std::cout << "REST_LENGTH_E: " << SPRING_PROP.REST_LENGTH[ SpringProp::EAST ] << "\n"; 02070 std::cout << "REST_LENGTH_SW: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ] << "\n"; 02071 std::cout << "REST_LENGTH_S: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ] << "\n"; 02072 std::cout << "REST_LENGTH_SE: " << SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ] << "\n"; 02073 // Back Plane 02074 std::cout << "REST_LENGTH_BNW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ] << "\n"; 02075 std::cout << "REST_LENGTH_BN: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ] << "\n"; 02076 std::cout << "REST_LENGTH_BNE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ] << "\n"; 02077 std::cout << "REST_LENGTH_BW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ] << "\n"; 02078 std::cout << "REST_LENGTH_B: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK ] << "\n"; 02079 std::cout << "REST_LENGTH_BE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ] << "\n"; 02080 std::cout << "REST_LENGTH_BSW: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ] << "\n"; 02081 std::cout << "REST_LENGTH_BS: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ] << "\n"; 02082 std::cout << "REST_LENGTH_BSE: " << SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ] << "\n"; 02083 //--------------------------------- 02084 std::cout << "\n"; 02085 //*/ 02086 //----------------------------------------------------- 02087 return true; 02088 } 02089 //----------------------------------------------------------------------------- 02090 // Load from a file 02091 template <typename T> 02092 bool ModelDeformableGLSL<T>::ProcessLinesOfSpringStiffness ( std::ifstream & inFile ) 02093 { 02094 const int SIZE = 256; 02095 char line[SIZE]; 02096 char *delimSpaces = "\t \n"; // tab, space, new line 02097 char *token = NULL; 02098 char *end; 02099 //----------------------------------------------------- 02100 /* 02101 E.g.: 02102 #SPRING_STIFFNESS# 02103 line 0: STIFFNESS_FNW: 400 <---- Start Here! 02104 line 1: STIFFNESS_FN: 400 02105 line 2: STIFFNESS_FNE: 400 02106 line 3: STIFFNESS_FW: 400 02107 line 4: STIFFNESS_F: 400 02108 line 5: STIFFNESS_FE: 400 02109 line 6: STIFFNESS_FSW: 400 02110 line 7: STIFFNESS_FS: 400 02111 line 8: STIFFNESS_FSE: 400 02112 line 9: STIFFNESS_NW: 400 02113 line10: STIFFNESS_N: 400 02114 line11: STIFFNESS_NE: 400 02115 line12: STIFFNESS_W: 400 02116 line13: STIFFNESS_H: 600 02117 line14: STIFFNESS_E: 400 02118 line15: STIFFNESS_SW: 400 02119 line16: STIFFNESS_S: 400 02120 line17: STIFFNESS_SE: 400 02121 line18: STIFFNESS_BNW: 400 02122 line19: STIFFNESS_BN: 400 02123 line20: STIFFNESS_BNE: 400 02124 line21: STIFFNESS_BW: 400 02125 line22: STIFFNESS_B: 400 02126 line23: STIFFNESS_BE: 400 02127 line24: STIFFNESS_BSW: 400 02128 line25: STIFFNESS_BS: 400 02129 line26: STIFFNESS_BSE: 400 <---- End Here! 02130 //*/ 02131 { 02132 int i = 0; 02133 // Front Plane 02134 //------------------------------------------------- 02135 // STIFFNESS_FNW: 02136 inFile.getline( line, SIZE ); 02137 token = strtok( line, delimSpaces ); // the first token 02138 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ] 02139 = strtod( strtok( NULL, delimSpaces ), &end ); 02140 // STIFFNESS_FN: 02141 inFile.getline( line, SIZE ); 02142 token = strtok( line, delimSpaces ); // the first token 02143 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ] 02144 = strtod( strtok( NULL, delimSpaces ), &end ); 02145 // STIFFNESS_FNE: 02146 inFile.getline( line, SIZE ); 02147 token = strtok( line, delimSpaces ); // the first token 02148 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ] 02149 = strtod( strtok( NULL, delimSpaces ), &end ); 02150 // STIFFNESS_FW: 02151 inFile.getline( line, SIZE ); 02152 token = strtok( line, delimSpaces ); // the first token 02153 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ] 02154 = strtod( strtok( NULL, delimSpaces ), &end ); 02155 // STIFFNESS_F: 02156 inFile.getline( line, SIZE ); 02157 token = strtok( line, delimSpaces ); // the first token 02158 SPRING_PROP.STIFFNESS[ SpringProp::FRONT ] 02159 = strtod( strtok( NULL, delimSpaces ), &end ); 02160 // STIFFNESS_FE: 02161 inFile.getline( line, SIZE ); 02162 token = strtok( line, delimSpaces ); // the first token 02163 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ] 02164 = strtod( strtok( NULL, delimSpaces ), &end ); 02165 // STIFFNESS_FSW: 02166 inFile.getline( line, SIZE ); 02167 token = strtok( line, delimSpaces ); // the first token 02168 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ] 02169 = strtod( strtok( NULL, delimSpaces ), &end ); 02170 // STIFFNESS_FS: 02171 inFile.getline( line, SIZE ); 02172 token = strtok( line, delimSpaces ); // the first token 02173 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ] 02174 = strtod( strtok( NULL, delimSpaces ), &end ); 02175 // STIFFNESS_FSE: 02176 inFile.getline( line, SIZE ); 02177 token = strtok( line, delimSpaces ); // the first token 02178 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ] 02179 = strtod( strtok( NULL, delimSpaces ), &end ); 02180 02181 // Center Plane 02182 //------------------------------------------------- 02183 // STIFFNESS_NW: 02184 inFile.getline( line, SIZE ); 02185 token = strtok( line, delimSpaces ); // the first token 02186 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ] 02187 = strtod( strtok( NULL, delimSpaces ), &end ); 02188 // STIFFNESS_N: 02189 inFile.getline( line, SIZE ); 02190 token = strtok( line, delimSpaces ); // the first token 02191 SPRING_PROP.STIFFNESS[ SpringProp::NORTH ] 02192 = strtod( strtok( NULL, delimSpaces ), &end ); 02193 // STIFFNESS_NE: 02194 inFile.getline( line, SIZE ); 02195 token = strtok( line, delimSpaces ); // the first token 02196 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ] 02197 = strtod( strtok( NULL, delimSpaces ), &end ); 02198 // STIFFNESS_W: 02199 inFile.getline( line, SIZE ); 02200 token = strtok( line, delimSpaces ); // the first token 02201 SPRING_PROP.STIFFNESS[ SpringProp::WEST ] 02202 = strtod( strtok( NULL, delimSpaces ), &end ); 02203 02204 // STIFFNESS_H: 02205 inFile.getline( line, SIZE ); 02206 token = strtok( line, delimSpaces ); // the first token 02207 SPRING_PROP.STIFFNESS[ SpringProp::HOME ] 02208 = strtod( strtok( NULL, delimSpaces ), &end ); 02209 // Memorize the home spring for restoring it value after collision detection 02210 SPRING_PROP.SetSpringStiffness ( 02211 SpringProp::HOME, 02212 SPRING_PROP.STIFFNESS[ SpringProp::HOME ] 02213 ); 02214 02215 // STIFFNESS_E: 02216 inFile.getline( line, SIZE ); 02217 token = strtok( line, delimSpaces ); // the first token 02218 SPRING_PROP.STIFFNESS[ SpringProp::EAST ] 02219 = strtod( strtok( NULL, delimSpaces ), &end ); 02220 // STIFFNESS_SW: 02221 inFile.getline( line, SIZE ); 02222 token = strtok( line, delimSpaces ); // the first token 02223 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ] 02224 = strtod( strtok( NULL, delimSpaces ), &end ); 02225 // STIFFNESS_S: 02226 inFile.getline( line, SIZE ); 02227 token = strtok( line, delimSpaces ); // the first token 02228 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ] 02229 = strtod( strtok( NULL, delimSpaces ), &end ); 02230 // STIFFNESS_SE: 02231 inFile.getline( line, SIZE ); 02232 token = strtok( line, delimSpaces ); // the first token 02233 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ] 02234 = strtod( strtok( NULL, delimSpaces ), &end ); 02235 02236 // Back Plane 02237 //------------------------------------------------- 02238 // STIFFNESS_BNW: 02239 inFile.getline( line, SIZE ); 02240 token = strtok( line, delimSpaces ); // the first token 02241 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ] 02242 = strtod( strtok( NULL, delimSpaces ), &end ); 02243 // STIFFNESS_BN: 02244 inFile.getline( line, SIZE ); 02245 token = strtok( line, delimSpaces ); // the first token 02246 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ] 02247 = strtod( strtok( NULL, delimSpaces ), &end ); 02248 // STIFFNESS_BNE: 02249 inFile.getline( line, SIZE ); 02250 token = strtok( line, delimSpaces ); // the first token 02251 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ] 02252 = strtod( strtok( NULL, delimSpaces ), &end ); 02253 // STIFFNESS_BW: 02254 inFile.getline( line, SIZE ); 02255 token = strtok( line, delimSpaces ); // the first token 02256 SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ] 02257 = strtod( strtok( NULL, delimSpaces ), &end ); 02258 // STIFFNESS_B: 02259 inFile.getline( line, SIZE ); 02260 token = strtok( line, delimSpaces ); // the first token 02261 SPRING_PROP.STIFFNESS[ SpringProp::BACK ] 02262 = strtod( strtok( NULL, delimSpaces ), &end ); 02263 // STIFFNESS_BE: 02264 inFile.getline( line, SIZE ); 02265 token = strtok( line, delimSpaces ); // the first token 02266 SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ] 02267 = strtod( strtok( NULL, delimSpaces ), &end ); 02268 // STIFFNESS_BSW: 02269 inFile.getline( line, SIZE ); 02270 token = strtok( line, delimSpaces ); // the first token 02271 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ] 02272 = strtod( strtok( NULL, delimSpaces ), &end ); 02273 // STIFFNESS_BS: 02274 inFile.getline( line, SIZE ); 02275 token = strtok( line, delimSpaces ); // the first token 02276 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ] 02277 = strtod( strtok( NULL, delimSpaces ), &end ); 02278 // STIFFNESS_BSE: 02279 inFile.getline( line, SIZE ); 02280 token = strtok( line, delimSpaces ); // the first token 02281 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ] 02282 = strtod( strtok( NULL, delimSpaces ), &end ); 02283 } 02284 //----------------------------------------------------- 02285 /* 02286 // DEBUG 02287 // REST LENGTH OF SPRINGS 02288 std::cout << "#27 Spring Rest Lengths\n"; 02289 std::cout << "#SPRING_STIFFNESS#\n"; 02290 // Front Plane 02291 std::cout << "STIFFNESS_FNW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ] << "\n"; 02292 std::cout << "STIFFNESS_FN: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ] << "\n"; 02293 std::cout << "STIFFNESS_FNE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ] << "\n"; 02294 std::cout << "STIFFNESS_FW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ] << "\n"; 02295 std::cout << "STIFFNESS_F: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT ] << "\n"; 02296 std::cout << "STIFFNESS_FE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ] << "\n"; 02297 std::cout << "STIFFNESS_FSW: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ] << "\n"; 02298 std::cout << "STIFFNESS_FS: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ] << "\n"; 02299 std::cout << "STIFFNESS_FSE: " << SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ] << "\n"; 02300 // Center Plane 02301 std::cout << "STIFFNESS_NW: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ] << "\n"; 02302 std::cout << "STIFFNESS_N: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH ] << "\n"; 02303 std::cout << "STIFFNESS_NE: " << SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ] << "\n"; 02304 std::cout << "STIFFNESS_W: " << SPRING_PROP.STIFFNESS[ SpringProp::WEST ] << "\n"; 02305 std::cout << "STIFFNESS_H: " << SPRING_PROP.STIFFNESS[ SpringProp::HOME ] << "\n"; 02306 std::cout << "STIFFNESS_E: " << SPRING_PROP.STIFFNESS[ SpringProp::EAST ] << "\n"; 02307 std::cout << "STIFFNESS_SW: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ] << "\n"; 02308 std::cout << "STIFFNESS_S: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ] << "\n"; 02309 std::cout << "STIFFNESS_SE: " << SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ] << "\n"; 02310 // Back Plane 02311 std::cout << "STIFFNESS_BNW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ] << "\n"; 02312 std::cout << "STIFFNESS_BN: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ] << "\n"; 02313 std::cout << "STIFFNESS_BNE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ] << "\n"; 02314 std::cout << "STIFFNESS_BW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ] << "\n"; 02315 std::cout << "STIFFNESS_B: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK ] << "\n"; 02316 std::cout << "STIFFNESS_BE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ] << "\n"; 02317 std::cout << "STIFFNESS_BSW: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ] << "\n"; 02318 std::cout << "STIFFNESS_BS: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ] << "\n"; 02319 std::cout << "STIFFNESS_BSE: " << SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ] << "\n"; 02320 //--------------------------------- 02321 std::cout << "\n"; 02322 //*/ 02323 //----------------------------------------------------- 02324 return true; 02325 } 02326 //----------------------------------------------------------------------------- 02327 // Load from a file 02328 template <typename T> 02329 bool ModelDeformableGLSL<T>::ProcessLinesOfSpringDamping ( std::ifstream & inFile ) 02330 { 02331 //----------------------------------------------------- 02332 return true; 02333 } 02334 //----------------------------------------------------------------------------- 02335 // Load from a file 02336 template <typename T> 02337 bool ModelDeformableGLSL<T>::ProcessLinesOfPositions ( 02338 std::ifstream & inFile, GLfloat * pPositions ) 02339 { 02340 const int SIZE = 256; 02341 char line[SIZE]; 02342 char *delimSpaces = "\t \n"; // tab, space, new line 02343 char *token = NULL; 02344 char *end; 02345 //----------------------------------------------------- 02346 /* 02347 E.g.: 02348 #POSITIONS# 02349 [0,0,0]: 0 0 0 0 <---- Start Here! 02350 [0,0,1]: 0 0 0 0 02351 [0,0,2]: 0 0 0 0 02352 [0,0,3]: 0 0 0 0 02353 [0,0,4]: 0 0 0 0 02354 [7,7,5]: 0 0 0 0 02355 ... 02356 [7,7,6]: 0 0 0 0 02357 [7,7,7]: 0 0 0 0 <---- End Here! 02358 #END_OF_POSITIONS# 02359 //*/ 02360 //----------------------------------------------------- 02361 int idx = 0; 02362 for ( int i = 0; i < m_iTotalElements; ++i ) { 02363 inFile.getline( line, SIZE ); 02364 token = strtok( line, delimSpaces ); // the first token 02365 // x, y, z positions and w for flag 02366 pPositions[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02367 pPositions[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02368 pPositions[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02369 pPositions[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02370 } 02371 //----------------------------------------------------- 02372 /* 02373 // DEBUG 02374 idx = 0; 02375 std::cout << "CHECK ==> Positions:\n"; 02376 std::cout << "--------------------\n"; 02377 for ( int z = 0; z < m_vGridResolution[2]; ++z ) { 02378 for ( int y = 0; y < m_vGridResolution[1]; ++y ) { 02379 for ( int x = 0; x < m_vGridResolution[0]; ++x ) { 02380 std::cout << "[" << z << "," << y << "," << x << "]: " 02381 << pPositions[idx+0] << " " 02382 << pPositions[idx+1] << " " 02383 << pPositions[idx+2] << " " 02384 << pPositions[idx+3] << "\n"; 02385 idx += 4; 02386 } 02387 } 02388 } 02389 std::cout << "------------------------\n"; 02390 std::cout << "END CHECK ==> Positions:\n"; 02391 //*/ 02392 //----------------------------------------------------- 02393 return true; 02394 } 02395 //----------------------------------------------------------------------------- 02396 // Process Lines of Connections (3X3) 02397 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 02398 template <typename T> 02399 bool ModelDeformableGLSL<T>::ProcessLinesOfConnections ( 02400 std::ifstream & inFile, GLfloat * pConnections ) 02401 { 02402 assert( false ); 02403 return true; 02404 } 02405 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 02406 //----------------------------------------------------------------------------- 02407 // Process Lines of Connections (ONE) 02408 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 02409 template <typename T> 02410 bool ModelDeformableGLSL<T>::ProcessLinesOfConnections ( 02411 std::ifstream & inFile, GLubyte * pConnections ) 02412 { 02413 const int SIZE = 256; 02414 char line[SIZE]; 02415 char *delimSpaces = "\t \n"; // tab, space, new line 02416 char *token = NULL; 02417 char *end; 02418 //----------------------------------------------------- 02419 /* 02420 E.g.: 02421 #CONNECTIONS# 02422 [0,0,0]: 0 0 0 0 <---- Start Here! 02423 [0,0,1]: 0 0 0 0 02424 [0,0,2]: 0 0 0 0 02425 ... 02426 [0,2,2]: 104 0 0 6 02427 [0,2,3]: 248 0 0 6 02428 [0,2,4]: 248 0 0 6 02429 [0,2,5]: 208 0 0 6 02430 ... 02431 [7,7,5]: 0 0 0 0 02432 [7,7,6]: 0 0 0 0 02433 [7,7,7]: 0 0 0 0 <---- End Here! 02434 #END_OF_CONNECTIONS# 02435 //*/ 02436 //----------------------------------------------------- 02437 int idx = 0; 02438 for ( int i = 0; i < m_iTotalElements; ++i ) { 02439 inFile.getline( line, SIZE ); 02440 token = strtok( line, delimSpaces ); // the first token 02441 // rgba for connectivity 02442 pConnections[idx++] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02443 pConnections[idx++] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02444 pConnections[idx++] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02445 pConnections[idx++] = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02446 } 02447 //----------------------------------------------------- 02448 /* 02449 // DEBUG 02450 idx = 0; 02451 std::cout << "CHECK ==> Connectivities:\n"; 02452 std::cout << "-------------------------\n"; 02453 for ( int z = 0; z < m_vGridResolution[2]; ++z ) { 02454 for ( int y = 0; y < m_vGridResolution[1]; ++y ) { 02455 for ( int x = 0; x < m_vGridResolution[0]; ++x ) { 02456 std::cout << "[" << z << "," << y << "," << x << "]: " 02457 << static_cast<int>( pConnections[idx+0] ) << " " 02458 << static_cast<int>( pConnections[idx+1] ) << " " 02459 << static_cast<int>( pConnections[idx+2] ) << " " 02460 << static_cast<int>( pConnections[idx+3] ) << "\n"; 02461 idx += 4; 02462 } 02463 } 02464 } 02465 std::cout << "-----------------------------\n"; 02466 std::cout << "END CHECK ==> Connectivities:\n"; 02467 //*/ 02468 //----------------------------------------------------- 02469 return true; 02470 } 02471 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 02472 //----------------------------------------------------------------------------- 02473 // Load from a file 02474 template <typename T> 02475 bool ModelDeformableGLSL<T>::ProcessLinesOfEllipsoidInfluences ( 02476 std::ifstream & inFile, GLfloat * pEllipsoids ) 02477 { 02478 const int SIZE = 256; 02479 char line[SIZE]; 02480 char *delimSpaces = "\t \n"; // tab, space, new line 02481 char *token = NULL; 02482 char *end; 02483 //----------------------------------------------------- 02484 /* 02485 E.g.: 02486 #POSITIONS# 02487 [0,0,0]: 0 0 0 0 <---- Start Here! 02488 [0,0,1]: 0 0 0 0 02489 [0,0,2]: 0 0 0 0 02490 [0,0,3]: 0 0 0 0 02491 [0,0,4]: 0 0 0 0 02492 [7,7,5]: 0 0 0 0 02493 ... 02494 [7,7,6]: 0 0 0 0 02495 [7,7,7]: 0 0 0 0 <---- End Here! 02496 #END_OF_POSITIONS# 02497 //*/ 02498 //----------------------------------------------------- 02499 int idx = 0; 02500 for ( int i = 0; i < m_iTotalElements; ++i ) { 02501 inFile.getline( line, SIZE ); 02502 token = strtok( line, delimSpaces ); // the first token 02503 // xyz for ellipsoid influence 02504 pEllipsoids[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02505 pEllipsoids[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02506 pEllipsoids[idx++] = strtod( strtok( NULL, delimSpaces ), &end ); 02507 } 02508 //----------------------------------------------------- 02509 /* 02510 // DEBUG 02511 idx = 0; 02512 std::cout << "CHECK ==> Ellipsoids:\n"; 02513 std::cout << "--------------------\n"; 02514 for ( int z = 0; z < m_vGridResolution[2]; ++z ) { 02515 for ( int y = 0; y < m_vGridResolution[1]; ++y ) { 02516 for ( int x = 0; x < m_vGridResolution[0]; ++x ) { 02517 std::cout << "[" << z << "," << y << "," << x << "]: " 02518 << pEllipsoids[idx+0] << " " 02519 << pEllipsoids[idx+1] << " " 02520 << pEllipsoids[idx+2] << "\n"; 02521 idx += 3; 02522 } 02523 } 02524 } 02525 std::cout << "------------------------\n"; 02526 std::cout << "END CHECK ==> Ellipsoids:\n"; 02527 //*/ 02528 //----------------------------------------------------- 02529 return true; 02530 } 02531 //----------------------------------------------------------------------------- 02532 // Load from a file 02533 template <typename T> 02534 bool ModelDeformableGLSL<T>::ProcessLinesOfVisualizedByRTGenMesh ( 02535 std::ifstream & inFile, 02536 // 02537 bool & bUseGlobalIntp, 02538 T & tGlobalIntpVal, 02539 bool & bDrawnWithPNTris, 02540 int & iPNTrisSmoothness, 02541 GLuint & ui3DTextureID 02542 ) 02543 { 02544 const int SIZE = 256; 02545 char line[SIZE]; 02546 char *delimSpaces = "\t \n"; // tab, space, new line 02547 char *token = NULL; 02548 char *end; 02549 //----------------------------------------------------- 02550 /* 02551 E.g.: 02552 #VISUAL_BY_RT_GEN_MESH# 02553 USE_GLOBAL_INTP: True <---- Start Here! 02554 GLOBAL_INTP_VALUE: 0.3 02555 DRAWN_WITH_PNTRIANGLES: True 02556 PNTRIANGLES_SMOOTHNESS: 4 02557 3D_TEXTURE_ID: 1 02558 #END_OF_VISUAL_BY_RT_GEN_MESH# <---- End Here! 02559 //*/ 02560 //* 02561 inFile.getline( line, SIZE ); 02562 while ( strncmp( line, "#END_OF_VISUALIZED_BY_RT_GEN_MESH#", sizeof("#END_OF_VISUALIZED_BY_RT_GEN_MESH#") ) ) { 02563 //std::cout << "LINE: " << line << std::endl; 02564 token = strtok( line, delimSpaces ); // the first token 02565 if ( !strcmp( token, "USE_GLOBAL_INTP:" ) ) { 02566 token = strtok( NULL, delimSpaces ); 02567 if ( !strcmp( token, "True" ) ) bUseGlobalIntp = true; 02568 else bUseGlobalIntp = false; 02569 //RetVisualRTGenMesh()->SetUseGlobalInterpolationValue( bUseGlobalIntp ); 02570 } 02571 else if ( !strcmp( token, "GLOBAL_INTP_VALUE:" ) ) { 02572 tGlobalIntpVal = strtod( strtok( NULL, delimSpaces ), &end ); 02573 //RetVisualRTGenMesh()->SetGlobalInterpolationValue( tGlobalIntpVal ); 02574 } 02575 else if ( !strcmp( token, "DRAWN_WITH_PNTRIANGLES:" ) ) { 02576 token = strtok( NULL, delimSpaces ); 02577 if ( !strcmp( token, "True" ) ) bDrawnWithPNTris = true; 02578 else bDrawnWithPNTris = false; 02579 //RetVisualRTGenMesh()->SetStatusDrawnWithPNTriangle( bDrawnWithPNTris ); 02580 } 02581 else if ( !strcmp( token, "PNTRIANGLES_SMOOTHNESS:" ) ) { 02582 iPNTrisSmoothness = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02583 //RetVisualRTGenMesh()->SetPNTriangleSmoothness( iPNTrisSmoothness ); 02584 } 02585 else if ( !strcmp( token, "3D_TEXTURE_ID:" ) ) { 02586 ui3DTextureID = strtol( strtok( NULL, delimSpaces ), &end, 10 ); 02587 //RetVisualRTGenMesh()->Set3DTexture( ui3DTextureID ); 02588 } 02589 02590 inFile.getline( line, SIZE ); // next line 02591 } 02592 //*/ 02593 //----------------------------------------------------- 02594 return true; 02595 } 02596 //----------------------------------------------------------------------------- 02597 // Load from a file 02598 template <typename T> 02599 bool ModelDeformableGLSL<T>::ProcessLinesOfVisualizedBy3DTexture ( 02600 std::ifstream & inFile ) 02601 { 02602 //... 02603 //----------------------------------------------------- 02604 return true; 02605 } 02606 //----------------------------------------------------------------------------- 02607 /* 02608 // 02609 template <typename T> 02610 void ModelDeformableGLSL<T>::PrioritizeTextures () 02611 { 02612 GLfloat tPriority = 1.0; 02613 m_3DTexturePosition->BindTexture( 0 ); 02614 glTexParameterfv( GL_TEXTURE_3D, GL_TEXTURE_PRIORITY, &tPriority ); 02615 m_3DTexturePosition->BindTexture( 1 ); 02616 glTexParameterfv( GL_TEXTURE_3D, GL_TEXTURE_PRIORITY, &tPriority ); 02617 m_3DTexturePosition->BindTexture( 2 ); 02618 glTexParameterfv( GL_TEXTURE_3D, GL_TEXTURE_PRIORITY, &tPriority ); 02619 glBindTexture( GL_TEXTURE_3D, 0 ); 02620 } 02621 //*/ 02622 //----------------------------------------------------------------------------- 02623 // Get Half Length 02624 template <typename T> 02625 T ModelDeformableGLSL<T>::GetMaxHalfLength () const 02626 { 02627 T maxHalfSize = 0.0; 02628 // for ( int i = 0; i < m_iNoVertices; ++i ) 02629 // { 02630 // } 02631 return maxHalfSize; 02632 } 02633 //----------------------------------------------------------------------------- 02634 // Calculate and set the normals 02635 template <typename T> 02636 void ModelDeformableGLSL<T>::CalAndSetNormals () 02637 { 02638 // CalAndSetFaceNormalsNotNormalized(); 02639 // DetermineFaceRings(); 02640 // CalAndSetElementNormals(); 02641 // NormalizeFaceNormals(); 02642 } 02643 //----------------------------------------------------------------------------- 02644 02645 //****************************************************************************** 02646 // ApplyAndResetTransform 02647 //****************************************************************************** 02648 //----------------------------------------------------------------------------- 02649 template <typename T> 02650 void ModelDeformableGLSL<T>::ApplyAndResetTransform () 02651 { 02652 // for ( int i = 0; i < m_iNoVertices; ++i ) { 02653 // m_prXElement[i].SetPosition( 02654 // ( GetTransform().ReturnMatrixTransform() 02655 // * Vector4<T>( m_prXElement[i].GetPosition() ) 02656 // ).GetVector3() 02657 // ); 02658 // } 02659 //--------------------------------------------------------------- 02660 // Set Transformation to Identity Matrix 02661 GetTransform().MakeIdentity(); 02662 //--------------------------------------------------------------- 02663 // Recalculate Bounding Volume(s) 02664 CalBoundingAABB(); 02665 CalBoundingEllipsoid(); 02666 CalBoundingSphere(); 02667 } 02668 //----------------------------------------------------------------------------- 02669 //***************************************************************************** 02670 02671 //***************************************************************************** 02672 // Virtual Fns from Collision Detection from ColDetSupport class 02673 //***************************************************************************** 02674 //----------------------------------------------------------------------------- 02675 template <typename T> 02676 void ModelDeformableGLSL<T>::CalBoundingAABB () 02677 { 02678 /* 02679 m_paBoundingAABB[0][0] = m_paBoundingAABB[1][0] = m_prXElement[0][0]; 02680 m_paBoundingAABB[0][1] = m_paBoundingAABB[1][1] = m_prXElement[0][1]; 02681 m_paBoundingAABB[0][2] = m_paBoundingAABB[1][2] = m_prXElement[0][2]; 02682 for ( int i = 1; i < m_iNoVertices; ++i ) 02683 { 02684 // Find lowest x, y, and z 02685 if ( m_paBoundingAABB[0][0] > m_prXElement[i][0] ) 02686 m_paBoundingAABB[0][0] = m_prXElement[i][0]; 02687 if ( m_paBoundingAABB[0][1] > m_prXElement[i][1] ) 02688 m_paBoundingAABB[0][1] = m_prXElement[i][1]; 02689 if ( m_paBoundingAABB[0][2] > m_prXElement[i][2] ) 02690 m_paBoundingAABB[0][2] = m_prXElement[i][2]; 02691 // Find highest x, y, and z 02692 if ( m_paBoundingAABB[1][0] < m_prXElement[i][0] ) 02693 m_paBoundingAABB[1][0] = m_prXElement[i][0]; 02694 if ( m_paBoundingAABB[1][1] < m_prXElement[i][1] ) 02695 m_paBoundingAABB[1][1] = m_prXElement[i][1]; 02696 if ( m_paBoundingAABB[1][2] < m_prXElement[i][2] ) 02697 m_paBoundingAABB[1][2] = m_prXElement[i][2]; 02698 } 02699 // Find the bounding volume center 02700 m_pBoundingCenter[0] = ( m_paBoundingAABB[0][0] + m_paBoundingAABB[1][0] ) / 2.0; 02701 m_pBoundingCenter[1] = ( m_paBoundingAABB[0][1] + m_paBoundingAABB[1][1] ) / 2.0; 02702 m_pBoundingCenter[2] = ( m_paBoundingAABB[0][2] + m_paBoundingAABB[1][2] ) / 2.0; 02703 //*/ 02704 } 02705 //----------------------------------------------------------------------------- 02706 template <typename T> 02707 void ModelDeformableGLSL<T>::CalBoundingEllipsoid () 02708 { 02709 /* 02710 m_pBoundingCenter[0] = ( m_paBoundingAABB[0][0] + m_paBoundingAABB[1][0] ) / 2.0; 02711 m_pBoundingCenter[1] = ( m_paBoundingAABB[0][1] + m_paBoundingAABB[1][1] ) / 2.0; 02712 m_pBoundingCenter[2] = ( m_paBoundingAABB[0][2] + m_paBoundingAABB[1][2] ) / 2.0; 02713 m_pBoundingEllipsoid[0] = fabs( (m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0])/2.0 ); 02714 m_pBoundingEllipsoid[1] = fabs( (m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1])/2.0 ); 02715 m_pBoundingEllipsoid[2] = fabs( (m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2])/2.0 ); 02716 //*/ 02717 02718 /* 02719 T xLength = m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0]; 02720 T yLength = m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1]; 02721 T zLength = m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2]; 02722 xLength *= xLength; 02723 yLength *= yLength; 02724 zLength *= zLength; 02725 m_pBoundingEllipsoid[0] = sqrt( yLength + zLength ) / 2.0; 02726 m_pBoundingEllipsoid[1] = sqrt( zLength + xLength ) / 2.0; 02727 m_pBoundingEllipsoid[2] = sqrt( xLength + yLength ) / 2.0; 02728 //*/ 02729 02730 T x = m_paBoundingAABB[1][0] - m_pBoundingCenter[0]; 02731 x *= x; 02732 T y = m_paBoundingAABB[1][1] - m_pBoundingCenter[1]; 02733 y *= y; 02734 T z = m_paBoundingAABB[1][2] - m_pBoundingCenter[2]; 02735 z *= z; 02736 m_pBoundingEllipsoid[1] = sqrt( y + z ); 02737 m_pBoundingEllipsoid[2] = sqrt( z + x ); 02738 m_pBoundingEllipsoid[0] = sqrt( x + y ); 02739 } 02740 //----------------------------------------------------------------------------- 02741 template <typename T> 02742 void ModelDeformableGLSL<T>::CalBoundingSphere () 02743 { 02744 /* 02745 T xLength = m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0]; 02746 T yLength = m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1]; 02747 T zLength = m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2]; 02748 xLength *= xLength; 02749 yLength *= yLength; 02750 zLength *= zLength; 02751 m_pBoundingSphere = sqrt( xLength + yLength + zLength ) / 2.0; 02752 //*/ 02753 // T squaredLength; 02754 m_pBoundingSphere = 0; 02755 // for ( int i = 0; i < m_iNoVertices; ++i ) { 02756 // squaredLength = (m_prXElement[i].GetPosition() - m_pBoundingCenter).SquaredLength(); 02757 // if ( squaredLength > m_pBoundingSphere ) 02758 // m_pBoundingSphere = squaredLength; 02759 // } 02760 m_pBoundingSphere = sqrt( m_pBoundingSphere ); 02761 } 02762 //----------------------------------------------------------------------------- 02763 //***************************************************************************** 02764 02765 02766 //============================================================================= 02767 // START: Get/Set and Calculation Fn(s) 02768 //----------------------------------------------------------------------------- 02769 template <typename T> 02770 void ModelDeformableGLSL<T>::CalAndRecordFreqsOfHistogramRange_0_255_ToArray ( 02771 GLubyte freqs[256] ) 02772 { 02773 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 02774 if ( m_Visualization_3DTexture ) { 02775 m_Visualization_3DTexture-> 02776 CalAndRecordFreqsOfHistogramRange_0_255_ToArray( freqs ); 02777 return; 02778 } 02779 #else 02780 //=============================================================== 02781 // Read data from GPU 02782 //--------------------------------------------------------------- 02783 glPushAttrib( GL_ALL_ATTRIB_BITS ); 02784 //----------------------------------------------------- 02785 GLsizei sizeForVisual = 02786 m_3DTexturePosition->GetWidth() * 02787 m_3DTexturePosition->GetHeight() * 02788 m_3DTexturePosition->GetDepth() * 02789 m_3DTexturePosition->GetInternalFormatNumberOfComponents(); 02790 GLfloat * dataForVisual = new GLfloat[ sizeForVisual ]; 02791 { 02792 //================================================= 02793 // Read data for positions from a texture to memory 02794 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 02795 m_3DTexturePosition->BindTexture(0); 02796 glGetTexImage( 02797 m_3DTexturePosition->GetTarget(), 02798 m_3DTexturePosition->GetLevel(), 02799 m_3DTexturePosition->GetPixelFormat(), 02800 m_3DTexturePosition->GetDataType(), 02801 dataForVisual 02802 ); 02803 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 02804 //================================================= 02805 } 02806 //--------------------------------------------------------------- 02807 glPopAttrib(); 02808 //--------------------------------------------------------------- 02809 //=============================================================== 02810 //--------------------------------------------------------------- 02811 // Calculate and Record the 256 frequencies for histogram to the input array 02812 for ( int f = 0; f < 256; ++f ) { 02813 freqs[f] = 0; 02814 } 02815 GLubyte idx; 02816 for ( int i = 3; i < sizeForVisual; i+=4 ) { 02817 double D = dataForVisual[i] * 255.0; 02818 int I = (int) D; 02819 if ( D-I >= 0.5 ) idx = I+1; 02820 else idx = I; 02821 if ( idx > 255 ) idx = 255; 02822 else if ( idx < 0 ) idx = 0; 02823 ++freqs[idx]; 02824 } 02825 //------------------------------------------- 02826 // DEBUG 02827 //for ( int f = 0; f < 256; ++f ) { 02828 // std::cout << "freqs[" << f << "]: " << (int)freqs[f] << "\n"; 02829 //} 02830 //------------------------------------------- 02831 //--------------------------------------------------------------- 02832 delete [] dataForVisual; 02833 #endif 02834 } 02835 //----------------------------------------------------------------------------- 02836 // END: Get/Set and Calculation Fn(s) 02837 //============================================================================= 02838 02839 //============================================================================= 02840 // OpenGL Display Fn(s) 02841 //----------------------------------------------------------------------------- 02842 template <typename T> 02843 void ModelDeformableGLSL<T>::DrawGL ( GLenum eDrawMode ) 02844 { 02845 } 02846 //----------------------------------------------------------------------------- 02847 template <typename T> 02848 void ModelDeformableGLSL<T>::DrawByGL ( DrawType drawType ) 02849 { 02850 //--------------------------------------------------------------- 02851 switch ( drawType ) { 02852 case DRAW_RT_GEN_MESH: 02853 case DRAW_RT_GEN_MESH_BY_GPU: 02854 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02855 VisualizeByRTGenMesh( drawType ); 02856 #else 02857 Visualize( drawType ); 02858 #endif 02859 break; 02860 case DRAW_RT_GEN_MESH_BY_CPU: 02861 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02862 VisualizeByRTGenMeshBySW( drawType ); 02863 #else 02864 Visualize( drawType ); 02865 #endif 02866 break; 02867 case DRAW_RT_GEN_MESH_BY_CPU_STANDARD_MC: 02868 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02869 VisualizeByRTGenMeshBySW_StandardMC( drawType ); 02870 #else 02871 Visualize( drawType ); 02872 #endif 02873 break; 02874 case DRAW_3D_TEXTURE: 02875 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 02876 VisualizeBy3DTexture( drawType ); 02877 #else 02878 Visualize( drawType ); 02879 #endif 02880 break; 02881 case DRAW_ALL_ELEMENTS: 02882 DrawByGL_AllElementsWithConnectivities_GPU(); 02883 break; 02884 case DRAW_ALL_ELEMENTS_WITH_CONNECTIVITIES: 02885 DrawByGL_AllElementsWithConnectivities_GPU(); 02886 break; 02887 02888 /* 02889 case ALL_ELEMENTS: 02890 glPushMatrix(); 02891 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02892 VisualizeByRTGenMeshBySW( drawType ); 02893 #else 02894 glTranslatef( ( GetBoundingAABBHighPoint()[0] - GetBoundingAABBLowPoint()[0]), 0, 0 ); 02895 DrawByGL_AllElementsWithConnectivities_GPU_AsQuads(); 02896 #endif 02897 glPopMatrix(); 02898 break; 02899 case ALL_ELEMENTS_WITH_CONNECTIVITIES: 02900 glPushMatrix(); 02901 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02902 glTranslatef( ( GetBoundingAABBHighPoint()[0] - GetBoundingAABBLowPoint()[0]), 0, 0 ); 02903 VisualizeByRTGenMeshBySW( drawType ); 02904 #else 02905 glTranslatef( ( GetBoundingAABBHighPoint()[0] - GetBoundingAABBLowPoint()[0]), 0, 0 ); 02906 DrawByGL_AllElementsWithConnectivities_GPU_AsQuads(); 02907 #endif 02908 glPopMatrix(); 02909 break; 02910 //*/ 02911 default: 02912 Visualize( drawType ); 02913 break; 02914 } 02915 } 02916 //----------------------------------------------------------------------------- 02917 template <typename T> 02918 void ModelDeformableGLSL<T>::Visualize ( DrawType drawType ) 02919 { 02920 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02921 VisualizeByRTGenMesh( drawType ); 02922 #endif 02923 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 02924 VisualizeBy3DTexture( drawType ); 02925 #endif 02926 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 02927 VisualizeByRayCasting( drawType ); 02928 #endif 02929 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 02930 VisualizeByMesh( drawType ); 02931 #endif 02932 } 02933 //----------------------------------------------------------------------------- 02934 02935 //============================================================================= 02936 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02937 //----------------------------------------------------------------------------- 02938 template <typename T> 02939 void ModelDeformableGLSL<T>::VisualizeByRTGenMesh ( DrawType drawType ) 02940 { 02941 if ( m_Visualization_RTGenMesh ) { 02942 m_Visualization_RTGenMesh->DrawByGLSL(); 02943 } 02944 } 02945 //------------------------------------- 02946 template <typename T> 02947 void ModelDeformableGLSL<T>::VisualizeByRTGenMeshBySW ( DrawType drawType ) 02948 { 02949 if ( m_Visualization_RTGenMesh ) { 02950 m_Visualization_RTGenMesh->DrawByGL(); 02951 } 02952 } 02953 //------------------------------------- 02954 template <typename T> 02955 void ModelDeformableGLSL<T>::VisualizeByRTGenMeshBySW_StandardMC ( DrawType drawType ) 02956 { 02957 if ( m_Visualization_RTGenMesh ) { 02958 m_Visualization_RTGenMesh->DrawByGL_StandardMC(); 02959 } 02960 } 02961 //----------------------------------------------------------------------------- 02962 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 02963 //============================================================================= 02964 02965 //============================================================================= 02966 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 02967 //----------------------------------------------------------------------------- 02968 template <typename T> 02969 void ModelDeformableGLSL<T>::VisualizeBy3DTexture ( DrawType drawType ) 02970 { 02971 if ( m_Visualization_3DTexture ) { 02972 m_Visualization_3DTexture->DrawByGLSL( 64 /* depth supersampling */ ); 02973 } 02974 } 02975 //----------------------------------------------------------------------------- 02976 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 02977 //============================================================================= 02978 02979 //============================================================================= 02980 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 02981 //----------------------------------------------------------------------------- 02982 template <typename T> 02983 void ModelDeformableGLSL<T>::VisualizeByRayCasting ( DrawType drawType ) 02984 { 02985 if ( m_Visualization_RayCasting ) { 02986 m_Visualization_RayCasting->DrawByGLSL( 64 /* depth supersampling */ ); 02987 } 02988 } 02989 //----------------------------------------------------------------------------- 02990 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 02991 //============================================================================= 02992 02993 //============================================================================= 02994 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 02995 //----------------------------------------------------------------------------- 02996 template <typename T> 02997 void ModelDeformableGLSL<T>::VisualizeByMesh ( DrawType drawType ) 02998 { 02999 if ( m_Visualization_Mesh ) { 03000 m_Visualization_Mesh->DrawByGLSL( 64 /* depth supersampling */ ); 03001 } 03002 } 03003 //----------------------------------------------------------------------------- 03004 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 03005 //============================================================================= 03006 03007 //============================================================================= 03008 // Helper Fn(s): Initialize connection constants (offsets) 03009 //----------------------------------------------------------------------------- 03010 template <typename T> 03011 std::string ModelDeformableGLSL<T>::Info () const 03012 { 03013 const int maxNumConnections = 26; 03014 std::string strInfo; 03015 //--------------------------------- 03016 strInfo += "Rest Length Stiffness Damper Distance Limit\n"; 03017 //================================= 03018 strInfo += "-----------\n"; 03019 strInfo += "FRONT GROUP:\n"; 03020 strInfo += "-----------"; 03021 //------------- 03022 strInfo += "\n FrontNorthWest: "; 03023 InfoConnectionProperties( strInfo, SpringProp::FRONT_NORTH_WEST, maxNumConnections ); 03024 strInfo += "\n FrontNorth: "; 03025 InfoConnectionProperties( strInfo, SpringProp::FRONT_NORTH, maxNumConnections ); 03026 strInfo += "\n FrontNorthEast: "; 03027 InfoConnectionProperties( strInfo, SpringProp::FRONT_NORTH_EAST, maxNumConnections ); 03028 //------------- 03029 strInfo += "\n FrontWest: "; 03030 InfoConnectionProperties( strInfo, SpringProp::FRONT_WEST, maxNumConnections ); 03031 strInfo += "\n Front: "; 03032 InfoConnectionProperties( strInfo, SpringProp::FRONT, maxNumConnections ); 03033 strInfo += "\n FrontEast: "; 03034 InfoConnectionProperties( strInfo, SpringProp::FRONT_EAST, maxNumConnections ); 03035 //------------- 03036 strInfo += "\n FrontSouthWest: "; 03037 InfoConnectionProperties( strInfo, SpringProp::FRONT_SOUTH_WEST, maxNumConnections ); 03038 strInfo += "\n FrontSouth: "; 03039 InfoConnectionProperties( strInfo, SpringProp::FRONT_SOUTH, maxNumConnections ); 03040 strInfo += "\n FrontSouthEast: "; 03041 InfoConnectionProperties( strInfo, SpringProp::FRONT_SOUTH_EAST, maxNumConnections ); 03042 //------------- 03043 strInfo += "\n"; 03044 //================================= 03045 strInfo += "------------\n"; 03046 strInfo += "CENTER GROUP:\n"; 03047 strInfo += "------------"; 03048 //------------- 03049 strInfo += "\n NorthWest: "; 03050 InfoConnectionProperties( strInfo, SpringProp::NORTH_WEST, maxNumConnections ); 03051 strInfo += "\n North: "; 03052 InfoConnectionProperties( strInfo, SpringProp::NORTH, maxNumConnections ); 03053 strInfo += "\n NorthEast: "; 03054 InfoConnectionProperties( strInfo, SpringProp::NORTH_EAST, maxNumConnections ); 03055 //------------- 03056 strInfo += "\n West: "; 03057 InfoConnectionProperties( strInfo, SpringProp::WEST, maxNumConnections ); 03058 strInfo += "\n East: "; 03059 InfoConnectionProperties( strInfo, SpringProp::EAST, maxNumConnections ); 03060 //------------- 03061 strInfo += "\n SouthWest: "; 03062 InfoConnectionProperties( strInfo, SpringProp::SOUTH_WEST, maxNumConnections ); 03063 strInfo += "\n South: "; 03064 InfoConnectionProperties( strInfo, SpringProp::SOUTH, maxNumConnections ); 03065 strInfo += "\n SouthEast: "; 03066 InfoConnectionProperties( strInfo, SpringProp::SOUTH_EAST, maxNumConnections ); 03067 //------------- 03068 strInfo += "\n"; 03069 //================================= 03070 strInfo += "----------\n"; 03071 strInfo += "BACK GROUP:\n"; 03072 strInfo += "----------"; 03073 //------------- 03074 strInfo += "\n BackNorthWest: "; 03075 InfoConnectionProperties( strInfo, SpringProp::BACK_NORTH_WEST, maxNumConnections ); 03076 strInfo += "\n BackNorth: "; 03077 InfoConnectionProperties( strInfo, SpringProp::BACK_NORTH, maxNumConnections ); 03078 strInfo += "\n BackNorthEast: "; 03079 InfoConnectionProperties( strInfo, SpringProp::BACK_NORTH_EAST, maxNumConnections ); 03080 //------------- 03081 strInfo += "\n BackWest: "; 03082 InfoConnectionProperties( strInfo, SpringProp::BACK_WEST, maxNumConnections ); 03083 strInfo += "\n Back: "; 03084 InfoConnectionProperties( strInfo, SpringProp::BACK, maxNumConnections ); 03085 strInfo += "\n BackEast: "; 03086 InfoConnectionProperties( strInfo, SpringProp::BACK_EAST, maxNumConnections ); 03087 //------------- 03088 strInfo += "\n BackSouthWest: "; 03089 InfoConnectionProperties( strInfo, SpringProp::BACK_SOUTH_WEST, maxNumConnections ); 03090 strInfo += "\n BackSouth: "; 03091 InfoConnectionProperties( strInfo, SpringProp::BACK_SOUTH, maxNumConnections ); 03092 strInfo += "\n BackSouthEast: "; 03093 InfoConnectionProperties( strInfo, SpringProp::BACK_SOUTH_EAST, maxNumConnections ); 03094 //------------- 03095 //strInfo += "\n"; 03096 //================================= 03097 return strInfo; 03098 } 03099 //----------------------------------------------------------------------------- 03100 template <typename T> 03101 void ModelDeformableGLSL<T>::InitConnectionConstants () 03102 { 03103 //=============================================================== 03104 // Index to Position Texture 03105 //--------------------------------------------------------------- 03106 int iOffsetElement = 4; 03107 int iOffsetX = iOffsetElement; 03108 int iOffsetY = m_vGridResolution[0] * iOffsetX; 03109 int iOffsetZ = m_vGridResolution[1] * iOffsetY; 03110 //--------- 03111 CONNECTION_INDEX_POSITION[SpringProp::EAST] = iOffsetX; 03112 CONNECTION_INDEX_POSITION[SpringProp::NORTH] = iOffsetY; 03113 CONNECTION_INDEX_POSITION[SpringProp::WEST] = -iOffsetX; 03114 CONNECTION_INDEX_POSITION[SpringProp::SOUTH] = -iOffsetY; 03115 //--------- 03116 CONNECTION_INDEX_POSITION[SpringProp::FRONT] = iOffsetZ; 03117 //--------- 03118 CONNECTION_INDEX_POSITION[SpringProp::BACK] = -iOffsetZ; 03119 //--------- 03120 CONNECTION_INDEX_POSITION[SpringProp::NORTH_EAST] = iOffsetY + iOffsetX; 03121 CONNECTION_INDEX_POSITION[SpringProp::NORTH_WEST] = iOffsetY - iOffsetX; 03122 CONNECTION_INDEX_POSITION[SpringProp::SOUTH_WEST] = -iOffsetY - iOffsetX; 03123 CONNECTION_INDEX_POSITION[SpringProp::SOUTH_EAST] = -iOffsetY + iOffsetX; 03124 //--------- 03125 CONNECTION_INDEX_POSITION[SpringProp::FRONT_EAST] = iOffsetZ + iOffsetX; 03126 CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH] = iOffsetZ + iOffsetY; 03127 CONNECTION_INDEX_POSITION[SpringProp::FRONT_WEST] = iOffsetZ - iOffsetX; 03128 CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH] = iOffsetZ - iOffsetY; 03129 //--------- 03130 CONNECTION_INDEX_POSITION[SpringProp::BACK_EAST] = -iOffsetZ + iOffsetX; 03131 CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH] = -iOffsetZ + iOffsetY; 03132 CONNECTION_INDEX_POSITION[SpringProp::BACK_WEST] = -iOffsetZ - iOffsetX; 03133 CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH] = -iOffsetZ - iOffsetY; 03134 //--------- 03135 CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_EAST] = iOffsetZ + iOffsetY + iOffsetX; 03136 CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_WEST] = iOffsetZ + iOffsetY - iOffsetX; 03137 CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_WEST] = iOffsetZ - iOffsetY - iOffsetX; 03138 CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_EAST] = iOffsetZ - iOffsetY + iOffsetX; 03139 //--------- 03140 CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_EAST] = -iOffsetZ + iOffsetY + iOffsetX; 03141 CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_WEST] = -iOffsetZ + iOffsetY - iOffsetX; 03142 CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_WEST] = -iOffsetZ - iOffsetY - iOffsetX; 03143 CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_EAST] = -iOffsetZ - iOffsetY + iOffsetX; 03144 //--------- 03145 CONNECTION_INDEX_POSITION[SpringProp::NOT_CONNECTED] = 0; 03146 //--------------------------------------------------------------- 03147 //=============================================================== 03148 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03149 //=============================================================== 03150 // Index to Connectivity Texture 03151 //--------------------------------------------------------------- 03152 // Create connection index to textures 03153 // Index 03154 // ---------------------------------------------------------------------- 03155 // | FRONT (x) | CENTER (y) | BACK (z) | 03156 // | 00 01 02 | 09 10 11 | 18 19 20 | 03157 // | 03 04 05 | 12 13 14 | 21 22 23 | 03158 // | 06 07 08 | 15 16 17 | 24 25 26 | 03159 // ---------------------------------------------------------------------- 03160 // Data 03161 // ---------------------------------------------------------------------- 03162 // | FRONT (x) | CENTER (y) | BACK (z) | 03163 // | 0z+y-x 0z+y-0 0z+y+x | 1z+y-x 1z+y-0 1z+y+x | 2z+y-x 2z+y-0 2z+y+x | 03164 // | 0z-0-x 0z-0-0 0z-0+x | 1z-0-x 1z-0-0 1z-0+x | 2z-0-x 2z-0-0 2z-0+x | 03165 // | 0z-y-x 0z-y-0 0z-y+x | 1z-y-x 1z-y-0 1z-y+x | 2z-y-x 2z-y-0 2z-y+x | 03166 // ---------------------------------------------------------------------- 03167 // The group is arranged across 3x3 subtexture of 4 components (ignore the 4th components) 03168 //--------------------------------------------------------------- 03169 int x = 4; 03170 int y = m_vGridResolution[0] * 3 * x; 03171 //int z = 1; 03172 //--------- 03173 // Front (x) 03174 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH_WEST] = y - x; 03175 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH] = y ; 03176 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH_EAST] = y + x; 03177 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_WEST] = -x; 03178 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT] = 0; 03179 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_EAST] = +x; 03180 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH_WEST] = -y - x; 03181 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH] = -y ; 03182 CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH_EAST] = -y + x; 03183 //--------- 03184 // Center (y) 03185 CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH_WEST] = y - x + 1; 03186 CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH] = y + 1; 03187 CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH_EAST] = y + x + 1; 03188 CONNECTION_INDEX_CONNECTIVITY[SpringProp::WEST] = -x + 1; 03189 CONNECTION_INDEX_CONNECTIVITY[SpringProp::NOT_CONNECTED] = 1; 03190 CONNECTION_INDEX_CONNECTIVITY[SpringProp::EAST] = +x + 1; 03191 CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH_WEST] = -y - x + 1; 03192 CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH] = -y + 1; 03193 CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH_EAST] = -y + x + 1; 03194 //--------- 03195 // Back (z) 03196 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH_WEST] = y - x + 2; 03197 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH] = y + 2; 03198 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH_EAST] = y + x + 2; 03199 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_WEST] = -x + 2; 03200 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK] = 2; 03201 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_EAST] = +x + 2; 03202 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH_WEST] = -y - x + 2; 03203 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH] = -y + 2; 03204 CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH_EAST] = -y + x + 2; 03205 //--------------------------------------------------------------- 03206 //=============================================================== 03207 #endif 03208 } 03209 //----------------------------------------------------------------------------- 03210 //============================================================================= 03211 03212 03213 03214 03215 //----------------------------------------------------------------------------- 03216 template <typename T> 03217 void ModelDeformableGLSL<T>::SetupTextureCoordinateValues ( 03218 T & coordS, T & coordT, T & coordP, 03219 int width, int height, int depth 03220 ) 03221 { 03222 coordS = 1.0 / width; 03223 coordT = 1.0 / height; 03224 coordP = 1.0 / depth; 03225 } 03226 //----------------------------------------------------------------------------- 03227 template <typename T> 03228 bool ModelDeformableGLSL<T>::GenerateBufferObjects () 03229 { 03230 //=============================================================== 03231 // Framebuffer Object(s) 03232 //--------------------------------------------------------------- 03233 //----------------------- 03234 // For Positions 03235 //----------------------- 03236 glGenFramebuffersEXT( 1, &m_glslFBO_vPosition ); 03237 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 03238 glFramebufferTexture3DEXT( 03239 GL_FRAMEBUFFER_EXT, // target 03240 GL_COLOR_ATTACHMENT0_EXT, // attached frame 03241 m_3DTexturePosition->GetTarget(), // texture target 03242 m_3DTexturePosition->GetTexture(0), // texture id 03243 0, // level 03244 0 // zoffset (for 3D texture) 03245 ); 03246 //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 03247 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 03248 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 03249 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 03253 //glGenFramebuffersEXT( 1, &m_glslFBO_vVelocity ); 03254 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vVelocity ); 03255 //glFramebufferTexture2DEXT( 03256 // GL_FRAMEBUFFER_EXT, // target 03257 // GL_COLOR_ATTACHMENT0_EXT, // attached frame 03258 // m_TexturePositionParameters.target, // texture target 03259 // m_gluipNameTextureVelocity[0], // texture id 03260 // 0, // level 03261 // 0 // zoffset (for 3D texture) 03262 //); 03263 //TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 03264 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 03265 //TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 03266 //----------------------- 03267 // For Connectivities 03268 //----------------------- 03269 glGenFramebuffersEXT( 1, &m_glslFBO_vConnectivity ); 03270 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vConnectivity ); 03271 glFramebufferTexture3DEXT( 03272 GL_FRAMEBUFFER_EXT, // target 03273 GL_COLOR_ATTACHMENT1_EXT, // attached frame 03274 m_3DTextureConnectivity->GetTarget(), // texture target 03275 m_3DTextureConnectivity->GetTexture(0), // texture id 03276 0, // level 03277 0 // zoffset (for 3D texture) 03278 ); 03279 //glDrawBuffer( GL_COLOR_ATTACHMENT1_EXT ); 03280 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 03281 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 03282 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 03283 //----------------------- 03284 // For Collision Detection 03285 //----------------------- 03286 glGenFramebuffersEXT( 1, &m_glslFBO_vCollisionDetection ); 03287 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 03288 glFramebufferTexture3DEXT( 03289 GL_FRAMEBUFFER_EXT, // target 03290 GL_COLOR_ATTACHMENT2_EXT, // attached frame 03291 m_3DTextureCollisionDetection->GetTarget(), // texture target 03292 m_3DTextureCollisionDetection->GetTexture(0), // texture id 03293 0, // level 03294 0 // zoffset (for 3D texture) 03295 ); 03296 //glDrawBuffer( GL_COLOR_ATTACHMENT2_EXT ); 03297 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 03298 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 03299 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 03300 //----------------------- 03301 // For Offset Values 03302 //----------------------- 03303 glGenFramebuffersEXT( 1, &m_glslFBO_vOffsetValues ); 03304 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vOffsetValues ); 03305 glFramebufferTexture3DEXT( 03306 GL_FRAMEBUFFER_EXT, // target 03307 GL_COLOR_ATTACHMENT3_EXT, // attached frame 03308 m_3DTextureOffsetValues->GetTarget(), // texture target 03309 m_3DTextureOffsetValues->GetTexture(0), // texture id 03310 0, // level 03311 0 // zoffset (for 3D texture) 03312 ); 03313 //glDrawBuffer( GL_COLOR_ATTACHMENT3_EXT ); 03314 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 03315 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 03316 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 03317 //--------------------------------------------------------------- 03318 //=============================================================== 03319 03320 //=============================================================== 03321 // Buffer(s) for Vertex Array 03322 //--------------------------------------------------------------- 03323 GLsizei numPointsForPosition = m_3DTexturePosition->GetWidth() 03324 * m_3DTexturePosition->GetHeight() 03325 * m_3DTexturePosition->GetDepth(); 03326 GLsizei numPointsForConnectivity = numPointsForPosition * 9; 03327 //------------------------------------------- 03328 // Buffer for Positions 03329 m_glslpBufferIDForPosition = new GLuint[ 1 ]; 03330 glGenBuffers( 1, m_glslpBufferIDForPosition ); 03331 GLsizeiptr sizeForPosition = sizeof( GLfloat ) * numPointsForPosition 03332 * m_3DTexturePosition->GetInternalFormatNumberOfComponents(); 03333 //------------------------------------------- 03334 // Buffer for Connectivities 03335 m_glslpBufferIDForConnectivity = new GLuint[ 1 ]; 03336 glGenBuffers( 1, m_glslpBufferIDForConnectivity ); 03337 GLsizeiptr sizeForConnectivity = sizeof( GLfloat ) * numPointsForConnectivity 03338 * m_3DTextureConnectivity->GetInternalFormatNumberOfComponents(); 03339 //------------------------------------------- 03340 // Buffer for Collision Detection 03341 //m_glslpBufferIDForCollisionDetection = new GLuint[ 1 ]; 03342 //glGenBuffers( 1, m_glslpBufferIDForCollisionDetection ); 03343 //GLsizeiptr sizeForCollisionDetection = sizeof( GLfloat ) * numPointsForPosition 03344 // * m_3DTexturePosition->GetInternalFormatNumberOfComponents(); 03345 //------------------------------------------------- 03346 // Bind Pixel Buffer: 03347 // To achieve a fast readback, bind the buffer object to 03348 // GL_PIXEL_PACK_ BUFFER using glBindBufferARB() After a buffer 03349 // is bound, glReadPixels() will pack (write) data into the Pixel 03350 // Buffer Object. 03351 for ( int i = 0; i < 1; ++i ) { 03352 //glBindBuffer( GL_ARRAY_BUFFER, m_glslpBufferIDForPosition[i] ); 03353 glBindBuffer( GL_PIXEL_PACK_BUFFER, m_glslpBufferIDForPosition[i] ); 03354 glBufferData( GL_PIXEL_PACK_BUFFER, sizeForPosition, NULL, GL_DYNAMIC_DRAW); 03355 //glBufferData( GL_PIXEL_PACK_BUFFER, size, NULL, GL_STATIC_DRAW); 03356 // 03357 glBindBuffer( GL_PIXEL_PACK_BUFFER, m_glslpBufferIDForConnectivity[i] ); 03358 glBufferData( GL_PIXEL_PACK_BUFFER, sizeForConnectivity, NULL, GL_DYNAMIC_DRAW); 03359 // 03360 //glBindBuffer( GL_PIXEL_PACK_BUFFER, m_glslpBufferIDForCollisionDetection[i] ); 03361 //glBufferData( GL_PIXEL_PACK_BUFFER, sizeForCollisionDetection, NULL, GL_DYNAMIC_DRAW); 03362 } 03363 //--------------------------------------------------------------- 03364 //=============================================================== 03365 //--------------------------------------------------------------- 03366 return true; 03367 } 03368 03369 //----------------------------------------------------------------------------- 03370 template <typename T> 03371 int ModelDeformableGLSL<T>::SetupBuffersAndShaders () 03372 { 03373 //=============================================================== 03374 // Generate Framebuffer Objects for Positions, (Velocities), & Connectivities 03375 //--------------------------------------------------------------- 03376 if ( !GenerateBufferObjects() ) 03377 { 03378 #ifdef TAPs_USE_WXWIDGETS 03379 wxLogError( wxT( "ERROR: ModelDeformableGLSL::GenerateBufferObjects Fn --> Cannot setup OpenGL Framebuffer Objects!" ) ); 03380 #else 03381 std::cout << "ERROR: ModelDeformableGLSL::GenerateBufferObjects Fn --> Cannot setup OpenGL Framebuffer Objects!" << std::endl; 03382 #endif 03383 return -1200;//return false; 03384 } 03385 03386 // DEBUG 03387 //std::cout << "AFTER GenerateBufferObjects()" << std::endl; 03388 03389 //--------------------------------------------------------------- 03390 //=============================================================== 03391 03392 //=============================================================== 03393 //--------------------------------------------------------------- 03394 #ifdef TAPs_DEBUG_MODE 03395 #ifdef TAPs_USE_WXWIDGETS 03396 wxLogWarning( wxT( " w/ (GPU) Grid Size: %i, %i, %i" ), 03397 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 03398 #endif 03399 #endif 03400 //--------------------------------------------------------------- 03401 // Model Initialization 03402 CalAndSetNormals(); 03403 ApplyMaterial(); 03404 //CalBoundingAABB(); 03405 //CalBoundingEllipsoid(); 03406 //CalBoundingSphere(); 03407 03408 // DEBUG 03409 //std::cout << "AFTER Model Inits" << std::endl; 03410 03411 //--------------------------------------------------------------- 03412 //=============================================================== 03413 03414 #define TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03415 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03416 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03417 03418 //=============================================================== 03419 // For Simulation by GLSL 03420 //--------------------------------------------------------------- 03421 //--------------------------------------------------------------- 03422 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 03423 //*********************************************************** 03424 // Simulation Step by Explicit Euler Integration 03425 //*********************************************************** 03426 // Not Implemented Yet! 03427 m_glslProgramObjectForDefModelStep = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03428 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03429 "Resource/Shader/DefModelStepExplicitEuler_Connectivity3x3.frag" 03430 #endif 03431 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03432 "Resource/Shader/DefModelStepExplicitEuler_ConnectivityOne.frag" 03433 #endif 03434 ); 03435 //------------------------------------------------- 03436 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03437 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03438 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3\n"; 03439 std::cout << "LOAD: \"Resource/Shader/DefModelStepExplicitEuler_Connectivity3x3.frag\" "; 03440 std::cout << "#endif\n"; 03441 #endif 03442 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03443 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03444 std::cout << "LOAD: \"Resource/Shader/DefModelStepExplicitEuler_ConnectivityOne.frag\" "; 03445 std::cout << "#endif\n"; 03446 #endif 03447 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03448 if ( m_glslProgramObjectForDefModelStep == NULL ) { 03449 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03450 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03451 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03452 Clear(); 03453 #ifdef TAPs_DEBUG_MODE 03454 #ifdef TAPs_USE_WXWIDGETS 03455 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (ODE)!" ) ); 03456 #else 03457 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (ODE)!\n"; 03458 #endif 03459 #endif 03460 return -1300;//return false; 03461 } 03462 else { 03463 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03464 std::cout << " was successful\n"; 03465 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03466 m_glslProgramObjectForDefModelStep->BeginGLSL(); 03467 //--------------------------------------------- 03468 //--------------------------------------------- 03469 m_glslProgramObjectForDefModelStep->EndGLSL(); 03470 } 03471 #endif // End of #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 03472 //--------------------------------------------------------------- 03473 //--------------------------------------------------------------- 03474 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 03475 03476 //* 03478 // DEBUG 03479 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03480 { 03481 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03482 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3\n"; 03483 // WITH GRADIENT TEXTURE 03484 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03485 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE\n"; 03486 std::cout << "LOAD: Resource/Shader/DefModelStepVerlet_Connectivity3x3_wGradTex.frag" << std::endl; 03487 std::cout << "#endif\n"; 03488 #endif 03489 // WITHOUT GRADIENT TEXTURE 03490 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03491 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE\n"; 03492 std::cout << "LOAD: Resource/Shader/DefModelStepVerlet_Connectivity3x3.frag" << std::endl; 03493 std::cout << "#endif\n"; 03494 #endif 03495 std::cout << "#endif\n"; 03496 #endif 03497 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03498 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03499 // WITH GRADIENT TEXTURE 03500 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03501 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE\n"; 03502 std::cout << "LOAD: Resource/Shader/DefModelStepVerlet_ConnectivityOne_wGradTex.frag" << std::endl; 03503 std::cout << "#endif\n"; 03504 #endif 03505 // WITHOUT GRADIENT TEXTURE 03506 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03507 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE\n"; 03508 std::cout << "LOAD: Resource/Shader/DefModelStepVerlet_ConnectivityOne.frag" << std::endl; 03509 std::cout << "#endif\n"; 03510 #endif 03511 std::cout << "#endif\n"; 03512 #endif 03513 } 03514 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03515 03516 //*/ 03517 03518 //*********************************************************** 03519 // Simulation Step by Verlet Integration 03520 //*********************************************************** 03521 m_glslProgramObjectForDefModelStep = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03522 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03523 // WITH GRADIENT TEXTURE 03524 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03525 "Resource/Shader/DefModelStepVerlet_Connectivity3x3_wGradTex.frag" 03526 #endif 03527 // WITHOUT GRADIENT TEXTURE 03528 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03529 "Resource/Shader/DefModelStepVerlet_Connectivity3x3.frag" 03530 #endif 03531 #endif 03532 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03533 // WITH GRADIENT TEXTURE 03534 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03535 "Resource/Shader/DefModelStepVerlet_ConnectivityOne_wGradTex.frag" 03536 #endif 03537 // WITHOUT GRADIENT TEXTURE 03538 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03539 "Resource/Shader/DefModelStepVerlet_ConnectivityOne.frag" 03540 #endif 03541 #endif 03542 ); 03543 //----------------------------------------------------------- 03544 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03545 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03546 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3\n"; 03547 // WITH GRADIENT TEXTURE 03548 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03549 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE\n"; 03550 std::cout << "LOAD: \"Resource/Shader/DefModelStepVerlet_Connectivity3x3_wGradTex.frag\" "; 03551 std::cout << "#endif\n"; 03552 #endif 03553 // WITHOUT GRADIENT TEXTURE 03554 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03555 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE\n"; 03556 std::cout << "LOAD: \"Resource/Shader/DefModelStepVerlet_Connectivity3x3.frag\" "; 03557 std::cout << "#endif\n"; 03558 #endif 03559 std::cout << "#endif\n"; 03560 #endif 03561 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03562 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03563 // WITH GRADIENT TEXTURE 03564 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 03565 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE\n"; 03566 std::cout << "LOAD: \"Resource/Shader/DefModelStepVerlet_ConnectivityOne_wGradTex.frag\" "; 03567 std::cout << "#endif\n"; 03568 #endif 03569 // WITHOUT GRADIENT TEXTURE 03570 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 03571 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE\n"; 03572 std::cout << "LOAD: \"Resource/Shader/DefModelStepVerlet_ConnectivityOne.frag\" "; 03573 std::cout << "#endif\n"; 03574 #endif 03575 std::cout << "#endif\n"; 03576 #endif 03577 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03578 if ( m_glslProgramObjectForDefModelStep == NULL ) { 03579 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03580 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03581 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03582 Clear(); 03583 #ifdef TAPs_DEBUG_MODE 03584 #ifdef TAPs_USE_WXWIDGETS 03585 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (ODE)!" ) ); 03586 #else 03587 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (ODE)!\n"; 03588 #endif 03589 #endif 03590 return -1400;//return false; 03591 } 03592 else { 03593 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03594 std::cout << " was successful\n"; 03595 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03596 m_glslProgramObjectForDefModelStep->BeginGLSL(); 03597 //------------------------------------------------- 03598 //------------------------------------------------- 03599 m_glslProgramObjectForDefModelStep->EndGLSL(); 03600 } 03601 //*********************************************************** 03602 #endif // End of #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 03603 //--------------------------------------------------------------- 03604 //=============================================================== 03605 03606 // DEBUG 03607 //std::cout << "AFTER Model ODE Integration Solver Setup" << std::endl; 03608 03609 //=============================================================== 03610 // For Relaxation Constraint by GLSL 03611 //--------------------------------------------------------------- 03612 m_glslProgramObjectForRelaxationConstraint = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03613 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03614 "Resource/Shader/DefModelRelaxationConstraint_Connectivity3x3.frag" 03615 #endif 03616 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03617 "Resource/Shader/DefModelRelaxationConstraint_ConnectivityOne.frag" 03618 #endif 03619 ); 03620 //--------------------------------------------------------------- 03621 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03622 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03623 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3\n"; 03624 std::cout << "LOAD: \"Resource/Shader/DefModelRelaxationConstraint_Connectivity3x3.frag\" "; 03625 std::cout << "#endif\n"; 03626 #endif 03627 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03628 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03629 std::cout << "LOAD: \"Resource/Shader/DefModelRelaxationConstraint_ConnectivityOne.frag\" "; 03630 std::cout << "#endif\n"; 03631 #endif 03632 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03633 if ( m_glslProgramObjectForRelaxationConstraint == NULL ) { 03634 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03635 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03636 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03637 Clear(); 03638 #ifdef TAPs_DEBUG_MODE 03639 #ifdef TAPs_USE_WXWIDGETS 03640 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Relaxation Constraint)!" ) ); 03641 #else 03642 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Relaxation Constraint)!\n"; 03643 #endif 03644 #endif 03645 return -1500;//return false; 03646 } 03647 else { 03648 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03649 std::cout << " was successful\n"; 03650 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03651 m_glslProgramObjectForRelaxationConstraint->BeginGLSL(); 03652 //------------------------------------------------- 03653 //------------------------------------------------- 03654 m_glslProgramObjectForRelaxationConstraint->EndGLSL(); 03655 } 03656 //--------------------------------------------------------------- 03657 //=============================================================== 03658 03659 // DEBUG 03660 //std::cout << "AFTER Relaxation Constraint Shader" << std::endl; 03661 03662 //*************************************************************** 03663 // Collision Detection 03664 //*************************************************************** 03665 m_glslProgramObjectForDefModelCollisionDetection = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03666 "Resource/Shader/DefModelCollisionDetectionBySpheres.frag" 03667 ); 03668 //--------------------------------------------------------------- 03669 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03670 std::cout << "LOAD: \"Resource/Shader/DefModelCollisionDetectionBySpheres.frag\" "; 03671 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03672 if ( m_glslProgramObjectForDefModelCollisionDetection == NULL ) { 03673 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03674 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03675 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03676 Clear(); 03677 #ifdef TAPs_DEBUG_MODE 03678 #ifdef TAPs_USE_WXWIDGETS 03679 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Collision Detection)!" ) ); 03680 #else 03681 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Collision Detection)!\n"; 03682 #endif 03683 #endif 03684 return -1600;//return false; 03685 } 03686 else { 03687 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03688 std::cout << " was successful\n"; 03689 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03690 m_glslProgramObjectForDefModelCollisionDetection->BeginGLSL(); 03691 //------------------------------------------------- 03692 //------------------------------------------------- 03693 m_glslProgramObjectForDefModelCollisionDetection->EndGLSL(); 03694 } 03695 //--------------------------------------------------------------- 03696 //*************************************************************** 03697 03698 //* 03699 //*************************************************************** 03700 // Collision Detection --- Tool sphere tip and cylinder shaft 03701 //*************************************************************** 03702 m_glslProgramObjectForDefModelCDTooltipSphereCylinder = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03703 "Resource/Shader/DefModelCollisionDetectionBySpheresAndCylinder.frag" 03704 ); 03705 //--------------------------------------------------------------- 03706 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03707 std::cout << "LOAD: \"Resource/Shader/DefModelCollisionDetectionBySpheresAndCylinder.frag\" "; 03708 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03709 if ( m_glslProgramObjectForDefModelCDTooltipSphereCylinder == NULL ) { 03710 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03711 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03712 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03713 Clear(); 03714 #ifdef TAPs_DEBUG_MODE 03715 #ifdef TAPs_USE_WXWIDGETS 03716 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Collision Detection)!" ) ); 03717 #else 03718 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Collision Detection)!\n"; 03719 #endif 03720 #endif 03721 return -1610;//return false; 03722 } 03723 else { 03724 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03725 std::cout << " was successful\n"; 03726 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03727 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->BeginGLSL(); 03728 //------------------------------------------------- 03729 //------------------------------------------------- 03730 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->EndGLSL(); 03731 } 03732 //--------------------------------------------------------------- 03733 //*************************************************************** 03734 //*/ 03735 03736 // DEBUG 03737 //std::cout << "AFTER Collision Detection Shader" << std::endl; 03738 03739 //*************************************************************** 03740 // Remove Elements by Collision 03741 //*************************************************************** 03742 m_glslProgramObjectForRemovingElements = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03743 "Resource/Shader/DefModelRemoveElementsByCollidingWithSpheres.frag" 03744 ); 03745 //--------------------------------------------------------------- 03746 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03747 std::cout << "LOAD: \"Resource/Shader/DefModelRemoveElementsByCollidingWithSpheres.frag\" "; 03748 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03749 if ( m_glslProgramObjectForRemovingElements == NULL ) { 03750 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03751 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03752 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03753 Clear(); 03754 #ifdef TAPs_DEBUG_MODE 03755 #ifdef TAPs_USE_WXWIDGETS 03756 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Removing Elements by Collision Detection)!" ) ); 03757 #else 03758 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Removing Elements by Collision Detection)!\n"; 03759 #endif 03760 #endif 03761 return -1700;//return false; 03762 } 03763 else { 03764 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03765 std::cout << " was successful\n"; 03766 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03767 m_glslProgramObjectForRemovingElements->BeginGLSL(); 03768 //------------------------------------------------- 03769 //------------------------------------------------- 03770 m_glslProgramObjectForRemovingElements->EndGLSL(); 03771 } 03772 //--------------------------------------------------------------- 03773 //*************************************************************** 03774 03775 // DEBUG 03776 //std::cout << "AFTER Remove Elements by Collision Detection Shader" << std::endl; 03777 03778 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03779 //*************************************************************** 03780 // Remove Connections by Collision 03781 //*************************************************************** 03782 m_glslProgramObjectForRemovingConnections = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03783 "Resource/Shader/DefModelRemoveConnectionsByCollidingWithARectangle_ConnectivityOne.frag" 03784 ); 03785 //--------------------------------------------------------------- 03786 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03787 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03788 std::cout << "LOAD: \"Resource/Shader/DefModelRemoveConnectionsByCollidingWithARectangle_ConnectivityOne.frag\" "; 03789 std::cout << "#endif\n"; 03790 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03791 if ( m_glslProgramObjectForRemovingConnections == NULL ) { 03792 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03793 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03794 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03795 Clear(); 03796 #ifdef TAPs_DEBUG_MODE 03797 #ifdef TAPs_USE_WXWIDGETS 03798 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Removing Connections by Collision Detection)!" ) ); 03799 #else 03800 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Removing Connections by Collision Detection)!\n"; 03801 #endif 03802 #endif 03803 return -1800;//return false; 03804 } 03805 else { 03806 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03807 std::cout << " was successful\n"; 03808 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03809 m_glslProgramObjectForRemovingConnections->BeginGLSL(); 03810 //------------------------------------------------- 03811 //------------------------------------------------- 03812 m_glslProgramObjectForRemovingConnections->EndGLSL(); 03813 } 03814 //--------------------------------------------------------------- 03815 //*************************************************************** 03816 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03817 03818 // DEBUG 03819 //std::cout << "AFTER Remove Connections by Collision Detection Shader" << std::endl; 03820 03821 //*************************************************************** 03822 // Update Connectivity 03823 //*************************************************************** 03824 m_glslProgramObjectForUpdateConnectivity = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03825 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03826 "Resource/Shader/DefModelUpdateConnectivity3x3.frag" 03827 #endif 03828 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03829 "Resource/Shader/DefModelUpdateConnectivityOne.frag" 03830 #endif 03831 ); 03832 //--------------------------------------------------------------- 03833 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03834 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 03835 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3\n"; 03836 std::cout << "LOAD: \"Resource/Shader/DefModelUpdateConnectivity3x3.frag\" "; 03837 std::cout << "#endif\n"; 03838 #endif 03839 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 03840 std::cout << "#ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE\n"; 03841 std::cout << "LOAD: \"Resource/Shader/DefModelUpdateConnectivityOne.frag\" "; 03842 std::cout << "#endif\n"; 03843 #endif 03844 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03845 if ( m_glslProgramObjectForUpdateConnectivity == NULL ) { 03846 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03847 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03848 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03849 Clear(); 03850 #ifdef TAPs_DEBUG_MODE 03851 #ifdef TAPs_USE_WXWIDGETS 03852 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Update Connectivity)!" ) ); 03853 #else 03854 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Update Connectivity)!\n"; 03855 #endif 03856 #endif 03857 return -2000;//return false; 03858 } 03859 else { 03860 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03861 std::cout << " was successful\n"; 03862 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03863 m_glslProgramObjectForUpdateConnectivity->BeginGLSL(); 03864 //------------------------------------------------- 03865 //------------------------------------------------- 03866 m_glslProgramObjectForUpdateConnectivity->EndGLSL(); 03867 } 03868 //--------------------------------------------------------------- 03869 //*************************************************************** 03870 03871 //*************************************************************** 03872 // Collision Detection --- Grabbing 03873 //*************************************************************** 03874 //----------------------------------------------------- 03875 // Grab Start 03876 m_glslProgramObjectForDefModelCDGrabStart = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03877 "Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingStart.frag" 03878 ); 03879 //--------------------------------------------------------------- 03880 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03881 std::cout << "LOAD: \"Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingStart.frag\" "; 03882 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03883 if ( m_glslProgramObjectForDefModelCDGrabStart == NULL ) { 03884 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03885 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03886 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03887 Clear(); 03888 #ifdef TAPs_DEBUG_MODE 03889 #ifdef TAPs_USE_WXWIDGETS 03890 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!" ) ); 03891 #else 03892 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!\n"; 03893 #endif 03894 #endif 03895 return -2100;//return false; 03896 } 03897 else { 03898 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03899 std::cout << " was successful\n"; 03900 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03901 m_glslProgramObjectForDefModelCDGrabStart->BeginGLSL(); 03902 //------------------------------------------------- 03903 //------------------------------------------------- 03904 m_glslProgramObjectForDefModelCDGrabStart->EndGLSL(); 03905 } 03906 //----------------------------------------------------- 03907 // Grab Move 03908 m_glslProgramObjectForDefModelCDGrabMove = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03909 "Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingMove.frag" 03910 ); 03911 //--------------------------------------------------------------- 03912 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03913 std::cout << "LOAD: \"Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingMove.frag\" "; 03914 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03915 if ( m_glslProgramObjectForDefModelCDGrabMove == NULL ) { 03916 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03917 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03918 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03919 Clear(); 03920 #ifdef TAPs_DEBUG_MODE 03921 #ifdef TAPs_USE_WXWIDGETS 03922 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!" ) ); 03923 #else 03924 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!\n"; 03925 #endif 03926 #endif 03927 return -2101;//return false; 03928 } 03929 else { 03930 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03931 std::cout << " was successful\n"; 03932 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03933 m_glslProgramObjectForDefModelCDGrabMove->BeginGLSL(); 03934 //------------------------------------------------- 03935 //------------------------------------------------- 03936 m_glslProgramObjectForDefModelCDGrabMove->EndGLSL(); 03937 } 03938 //----------------------------------------------------- 03939 // Grab End 03940 m_glslProgramObjectForDefModelCDGrabEnd = m_glslShaderManager.LoadOnlyAFragmentShaderFromFile( 03941 "Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingEnd.frag" 03942 ); 03943 //--------------------------------------------------------------- 03944 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03945 std::cout << "LOAD: \"Resource/Shader/DefModelCollisionDetectionBySpheresForGrabbingEnd.frag\" "; 03946 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03947 if ( m_glslProgramObjectForDefModelCDGrabEnd == NULL ) { 03948 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03949 std::cout << " was UNSUCCESSFUL!!!" << std::endl; 03950 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03951 Clear(); 03952 #ifdef TAPs_DEBUG_MODE 03953 #ifdef TAPs_USE_WXWIDGETS 03954 wxLogError( wxT( "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!" ) ); 03955 #else 03956 std::cerr << "ERROR: Cannot Load The Shaders for Simulation (Collision Detection for Grabbing)!\n"; 03957 #endif 03958 #endif 03959 return -2102;//return false; 03960 } 03961 else { 03962 #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03963 std::cout << " was successful\n"; 03964 #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS 03965 m_glslProgramObjectForDefModelCDGrabEnd->BeginGLSL(); 03966 //------------------------------------------------- 03967 //------------------------------------------------- 03968 m_glslProgramObjectForDefModelCDGrabEnd->EndGLSL(); 03969 } 03970 //--------------------------------------------------------------- 03971 //*************************************************************** 03972 03973 03974 // DEBUG 03975 //std::cout << "AFTER Update Connectivity Shader" << std::endl; 03976 03977 // DEBUG 03978 //std::cout << "AFTER Update Parameters for Shaders" << std::endl; 03979 03980 // DEBUG 03981 //std::cout << "DONE with SetupBuffersAndShaders Fn" << std::endl; 03982 03983 return 0; 03984 } 03985 //----------------------------------------------------------------------------- 03986 //============================================================================= 03987 03988 03989 03990 03991 //***************************************************************************** 03992 // BEGIN: CollisionDetection (void) 03993 //----------------------------------------------------------------------------- 03994 // Collision Detection by GLSL 03995 template <typename T> 03996 Vector3<T> ModelDeformableGLSL<T>::CollisionDetection () 03997 { 03998 //assert( m_glslProgramObjectForDefModelCollisionDetection ); 03999 if ( !m_glslProgramObjectForDefModelCollisionDetection ) return Vector3<T>(0,0,0); 04000 //--------------------------------------------------------------- 04001 m_3DTexturePosition->EnableTextureTarget(); 04002 m_glslProgramObjectForDefModelCollisionDetection->BeginGLSL(); 04003 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04004 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04005 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04006 glPushAttrib( GL_ALL_ATTRIB_BITS ); 04007 { 04008 //------------------------------------------------- 04009 // Send Stream of Data (one texture at a time in a for loop) 04010 glMatrixMode( GL_PROJECTION ); 04011 glPushMatrix(); 04012 glLoadIdentity(); 04013 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 04014 0, m_3DTexturePosition->GetMaxCoordT() ); 04015 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04016 // 04017 glMatrixMode( GL_MODELVIEW ); 04018 glPushMatrix(); 04019 glLoadIdentity(); 04020 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04021 // 04022 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 04023 m_3DTexturePosition->GetHeight() ); 04024 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04025 // 04026 //================================================= 04027 //------------------------------------------------- 04028 // Uniform Variables 04029 //-------------------- 04030 // Threshold 04031 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1f( "threshold", m_tSimThreshold ); 04032 // 04033 GLfloat Tooltip[4]; 04034 Tooltip[0] = 1000.0f; 04035 Tooltip[1] = 1000.0f; 04036 Tooltip[2] = 1000.0f; 04037 Tooltip[3] = 0.5f; 04038 #ifdef TAPs_USE_HAPTIC 04039 HLdouble proxyPosition[3]; 04040 hlGetDoublev( HL_PROXY_POSITION, proxyPosition ); 04041 Tooltip[0] = proxyPosition[0]; 04042 Tooltip[1] = proxyPosition[1]; 04043 Tooltip[2] = proxyPosition[2]; 04044 #endif 04045 04046 const GLint numberOfSpheres = 1; 04047 GLfloat sphere[numberOfSpheres * 4]; // 4 for Center (x,y,z) and Radius (w) 04048 // 04049 sphere[0] = -1.0f; 04050 sphere[1] = -1.0f; 04051 sphere[2] = 0.0f; 04052 sphere[3] = 1.0f; 04053 //sphere[4] = 1.0f; 04054 //sphere[5] = 1.0f; 04055 //sphere[6] = -1.0f; 04056 //sphere[7] = 1.0f; 04057 // 04058 04059 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1i( "NumberOfSpheres", numberOfSpheres ); 04060 04061 m_glslProgramObjectForDefModelCollisionDetection->SetUniform4fv( "Sphere", numberOfSpheres, sphere ); 04062 //m_glslProgramObjectForDefModelCollisionDetection->SetUniform1fv( "Sphere", numberOfSpheres*4, sphere ); 04063 04064 m_glslProgramObjectForDefModelCollisionDetection->SetUniform4fv( "ToolTip", numberOfSpheres, Tooltip ); 04065 04066 //m_3DTexturePosition->EnableTextureTarget(); 04067 //------------------------------------------------- 04068 // Set PositionTexture to Texture Unit 0 04069 glActiveTexture( GL_TEXTURE0 ); 04070 m_3DTexturePosition->BindTexture(0); 04071 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1i( "PositionTexture", 0 ); 04072 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04073 04074 //------------------------------------------------- 04075 //================================================= 04076 T offsetRCoord = offsetCoordRPosition / 2.0; 04077 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 04078 //------------------------------------------------- 04079 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04080 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 04081 glFramebufferTexture3DEXT( 04082 GL_FRAMEBUFFER_EXT, // target 04083 GL_COLOR_ATTACHMENT0_EXT, // attached frame 04084 m_3DTexturePosition->GetTarget(), // texture target 04085 m_3DTexturePosition->GetTexture(1), // texture id -- next position 04086 0, // level 04087 i // zoffset 04088 ); 04089 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04090 //------------------------------------------------- 04091 glFramebufferTexture3DEXT( 04092 GL_FRAMEBUFFER_EXT, // target 04093 GL_COLOR_ATTACHMENT1_EXT, // attached frame 04094 m_3DTextureCollisionDetection->GetTarget(), // texture target 04095 m_3DTextureCollisionDetection->GetTexture(0), // texture id 04096 0, // level 04097 i // zoffset 04098 ); 04099 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04100 //------------------------------------------------- 04101 //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 04102 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 04103 //glDrawBuffers( 2, MRT ); 04104 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 04105 glDrawBuffers( 2, drawBuffers ); 04106 //------------------------------------------------- 04107 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04108 //------------------------------------------------- 04109 // Send data stream to GPU 04110 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04111 // 04112 glClearColor( 0, 0, 0, 0 ); 04113 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 04114 glClear( GL_COLOR_BUFFER_BIT ); 04115 // 04116 T coordR = offsetCoordRPosition * i + offsetRCoord; 04117 glPolygonMode( GL_FRONT, GL_FILL ); 04118 glBegin( GL_QUADS ); 04119 glTexCoord3f( 0, 0, coordR ); 04120 glVertex3f ( 0, 0, 0 ); 04121 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 04122 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 04123 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 04124 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 04125 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 04126 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 04127 glEnd(); 04128 } 04129 glPopMatrix(); 04130 glMatrixMode( GL_PROJECTION ); 04131 glPopMatrix(); 04132 glMatrixMode( GL_MODELVIEW ); 04133 } 04134 glPopAttrib(); 04135 m_3DTexturePosition->DisableTextureTarget(); 04136 m_3DTexturePosition->UnbindTexture(); 04137 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 04138 // 04139 m_glslProgramObjectForDefModelCollisionDetection->EndGLSL(); 04140 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04141 //--------------------------------------------------------------- 04142 // Swap Textures 04143 SwapTextures(); 04144 04145 //=============================================================== 04146 // Read collision data from a texture to memory 04147 //--------------------------------------------------------------- 04148 GLsizei sizeCD = 04149 m_3DTextureCollisionDetection->GetWidth() * 04150 m_3DTextureCollisionDetection->GetHeight() * 04151 m_3DTextureCollisionDetection->GetDepth() * 04152 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 04153 GLfloat * dataCD = new GLfloat[ sizeCD ]; 04154 int i = 0; 04155 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 04156 m_3DTextureCollisionDetection->BindTexture(0); 04157 glGetTexImage( 04158 m_3DTextureCollisionDetection->GetTarget(), 04159 m_3DTextureCollisionDetection->GetLevel(), 04160 m_3DTextureCollisionDetection->GetPixelFormat(), 04161 m_3DTextureCollisionDetection->GetDataType(), 04162 dataCD 04163 ); 04164 Vector3<T> totalCD( 0, 0, 0 ); 04165 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04166 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 04167 for ( int i = 0; i < sizeCD; i+=4 ) { 04168 //std::cout << dataCD[i] << ", "; 04169 totalCD[0] += dataCD[i]; 04170 totalCD[1] += dataCD[i+1]; 04171 totalCD[2] += dataCD[i+2]; 04172 } 04173 //if ( totalCD.Length() > 0.0 ) { 04174 // std::cout << "Total CD: " << totalCD << "\n"; 04175 //} 04176 delete [] dataCD; 04177 //--------------------------------------------------------------- 04178 //=============================================================== 04179 //} 04180 //*/ 04181 //*/ 04182 04183 //----------------------------------------------------- 04184 // Update simulation state(s) 04185 UpdateCollisionStatus( totalCD.Length() ); 04186 //----------------------------------------------------- 04187 return totalCD; 04188 //*/ 04189 } 04190 //----------------------------------------------------------------------------- 04191 // END: CollisionDetection (void) 04192 //***************************************************************************** 04193 04194 04195 //***************************************************************************** 04196 // BEGIN: CollisionDetection ( ... ) 04197 //----------------------------------------------------------------------------- 04198 // Collision Detection by GLSL 04199 template <typename T> 04200 Vector3<T> ModelDeformableGLSL<T>::CollisionDetection ( 04201 int NumOfTooltips, GLfloat Tooltips[8], 04202 int NumOfSpheres, GLfloat CollidableSpheres[32] 04203 ) 04204 { 04205 #ifdef TAPs_DEBUG_MODE 04206 if ( NumOfTooltips > 2 ) NumOfTooltips = 2; 04207 if ( NumOfSpheres > 8 ) NumOfSpheres = 8; 04208 #endif 04209 04210 //assert( m_glslProgramObjectForDefModelCollisionDetection ); 04211 if ( !m_glslProgramObjectForDefModelCollisionDetection ) return Vector3<T>(0,0,0); 04212 04213 //UpdateParametersForCollisionDetection(); 04214 //--------------------------------------------------------------- 04215 m_3DTexturePosition->EnableTextureTarget(); 04216 m_glslProgramObjectForDefModelCollisionDetection->BeginGLSL(); 04217 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04218 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04219 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04220 glPushAttrib( GL_ALL_ATTRIB_BITS ); 04221 { 04222 //------------------------------------------------- 04223 // Send Stream of Data (one texture at a time in a for loop) 04224 glMatrixMode( GL_PROJECTION ); 04225 glPushMatrix(); 04226 glLoadIdentity(); 04227 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 04228 0, m_3DTexturePosition->GetMaxCoordT() ); 04229 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04230 // 04231 glMatrixMode( GL_MODELVIEW ); 04232 glPushMatrix(); 04233 glLoadIdentity(); 04234 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04235 // 04236 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 04237 m_3DTexturePosition->GetHeight() ); 04238 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04239 // 04240 //================================================= 04241 //------------------------------------------------- 04242 // Uniform Variables 04243 //------------------------------------------------- 04244 // Set Tool Tips and Collidable Spheres 04245 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1i( "NumberOfSpheres", NumOfSpheres ); 04246 m_glslProgramObjectForDefModelCollisionDetection->SetUniform4fv( "Sphere", NumOfSpheres, CollidableSpheres ); 04247 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1i( "NumberOfToolTips", NumOfTooltips ); 04248 m_glslProgramObjectForDefModelCollisionDetection->SetUniform4fv( "ToolTip", NumOfTooltips, Tooltips ); 04249 //------------------------------------------------- 04250 04251 //m_3DTexturePosition->EnableTextureTarget(); 04252 //------------------------------------------------- 04253 // Set PositionTexture to Texture Unit 0 04254 glActiveTexture( GL_TEXTURE0 ); 04255 m_3DTexturePosition->BindTexture(0); 04256 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1i( "PositionTexture", 0 ); 04257 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04258 04259 //------------------------------------------------- 04260 //================================================= 04261 T offsetRCoord = offsetCoordRPosition / 2.0; 04262 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 04263 //------------------------------------------------- 04264 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04265 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 04266 glFramebufferTexture3DEXT( 04267 GL_FRAMEBUFFER_EXT, // target 04268 GL_COLOR_ATTACHMENT0_EXT, // attached frame 04269 m_3DTexturePosition->GetTarget(), // texture target 04270 m_3DTexturePosition->GetTexture(1), // texture id -- next position 04271 0, // level 04272 i // zoffset 04273 ); 04274 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04275 //------------------------------------------------- 04276 glFramebufferTexture3DEXT( 04277 GL_FRAMEBUFFER_EXT, // target 04278 GL_COLOR_ATTACHMENT1_EXT, // attached frame 04279 m_3DTextureCollisionDetection->GetTarget(), // texture target 04280 m_3DTextureCollisionDetection->GetTexture(0), // texture id 04281 0, // level 04282 i // zoffset 04283 ); 04284 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04285 //------------------------------------------------- 04286 //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 04287 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 04288 //glDrawBuffers( 2, MRT ); 04289 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 04290 glDrawBuffers( 2, drawBuffers ); 04291 //------------------------------------------------- 04292 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04293 //------------------------------------------------- 04294 // Send data stream to GPU 04295 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04296 // 04297 glClearColor( 0, 0, 0, 0 ); 04298 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 04299 glClear( GL_COLOR_BUFFER_BIT ); 04300 // 04301 T coordR = offsetCoordRPosition * i + offsetRCoord; 04302 glPolygonMode( GL_FRONT, GL_FILL ); 04303 glBegin( GL_QUADS ); 04304 glTexCoord3f( 0, 0, coordR ); 04305 glVertex3f ( 0, 0, 0 ); 04306 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 04307 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 04308 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 04309 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 04310 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 04311 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 04312 glEnd(); 04313 } 04314 glPopMatrix(); 04315 glMatrixMode( GL_PROJECTION ); 04316 glPopMatrix(); 04317 glMatrixMode( GL_MODELVIEW ); 04318 } 04319 glPopAttrib(); 04320 m_3DTexturePosition->DisableTextureTarget(); 04321 m_3DTexturePosition->UnbindTexture(); 04322 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 04323 // 04324 m_glslProgramObjectForDefModelCollisionDetection->EndGLSL(); 04325 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04326 //--------------------------------------------------------------- 04327 // Swap Textures 04328 SwapPositionTextures(); 04329 04330 //=============================================================== 04331 // Read collision data from a texture to memory 04332 //--------------------------------------------------------------- 04333 GLsizei sizeCD = 04334 m_3DTextureCollisionDetection->GetWidth() * 04335 m_3DTextureCollisionDetection->GetHeight() * 04336 m_3DTextureCollisionDetection->GetDepth() * 04337 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 04338 GLfloat * dataCD = new GLfloat[ sizeCD ]; 04339 int i = 0; 04340 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 04341 m_3DTextureCollisionDetection->BindTexture(0); 04342 glGetTexImage( 04343 m_3DTextureCollisionDetection->GetTarget(), 04344 m_3DTextureCollisionDetection->GetLevel(), 04345 m_3DTextureCollisionDetection->GetPixelFormat(), 04346 m_3DTextureCollisionDetection->GetDataType(), 04347 dataCD 04348 ); 04349 Vector3<T> totalCD( 0, 0, 0 ); 04350 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04351 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 04352 for ( int i = 0; i < sizeCD; i+=4 ) { 04353 //std::cout << dataCD[i] << ", "; 04354 totalCD[0] += dataCD[i]; 04355 totalCD[1] += dataCD[i+1]; 04356 totalCD[2] += dataCD[i+2]; 04357 } 04358 //if ( totalCD.Length() > 0.0 ) { 04359 // std::cout << "Total CD: " << totalCD << "\n"; 04360 //} 04361 delete [] dataCD; 04362 //--------------------------------------------------------------- 04363 //=============================================================== 04364 //} 04365 //*/ 04366 //*/ 04367 04368 //----------------------------------------------------- 04369 // Update simulation state(s) 04370 UpdateCollisionStatus( totalCD.Length() ); 04371 //----------------------------------------------------- 04372 return totalCD; 04373 //*/ 04374 } 04375 //----------------------------------------------------------------------------- 04376 // END: CollisionDetection ( ... ) 04377 //***************************************************************************** 04378 04379 04380 //***************************************************************************** 04381 // BEGIN: UpdateParametersForCollisionDetection 04382 //----------------------------------------------------------------------------- 04383 template <typename T> 04384 void ModelDeformableGLSL<T>::UpdateParametersForCollisionDetection () 04385 { 04386 m_glslProgramObjectForDefModelCollisionDetection->BeginGLSL(); 04387 //--------------------------------------------------------------- 04388 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1f( "threshold", m_tSimThreshold ); 04389 m_glslProgramObjectForDefModelCollisionDetection->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 04390 //--------------------------------------------------------------- 04391 m_glslProgramObjectForDefModelCollisionDetection->EndGLSL(); 04392 } 04393 //------------------------------------------------------------------------- 04394 // END: UpdateParametersForCollisionDetection 04395 //************************************************************************* 04396 04397 04398 //***************************************************************************** 04399 // BEGIN: CollisionDetectionForGrabbingStartOrEnd ( ... ) 04400 //----------------------------------------------------------------------------- 04401 // Collision Detection by GLSL 04402 template <typename T> 04403 Vector3<T> ModelDeformableGLSL<T>::CollisionDetectionForGrabbingStartOrEnd ( 04404 int NumOfTooltips, GLfloat Tooltips[8], bool bStart, 04405 int graspID // must be greater than one 04406 ) 04407 { 04408 #ifdef TAPs_DEBUG_MODE 04409 if ( NumOfTooltips > 2 ) NumOfTooltips = 2; 04410 #endif 04411 04412 //assert( m_glslProgramObjectForDefModelCDGrabStart ); 04413 //assert( m_glslProgramObjectForDefModelCDGrabEnd ); 04414 if ( !m_glslProgramObjectForDefModelCDGrabStart ) return Vector3<T>(0,0,0); 04415 if ( !m_glslProgramObjectForDefModelCDGrabEnd ) return Vector3<T>(0,0,0); 04416 04417 GLSLProgramObject * m_glslProgObjPtr = NULL; 04418 if ( bStart ) m_glslProgObjPtr = m_glslProgramObjectForDefModelCDGrabStart; 04419 else m_glslProgObjPtr = m_glslProgramObjectForDefModelCDGrabEnd; 04420 04421 //UpdateParametersForCollisionDetectionForGrabbing(); 04422 //--------------------------------------------------------------- 04423 m_3DTexturePosition->EnableTextureTarget(); 04424 m_glslProgObjPtr->BeginGLSL(); 04425 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04426 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04427 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04428 glPushAttrib( GL_ALL_ATTRIB_BITS ); 04429 { 04430 //------------------------------------------------- 04431 // Send Stream of Data (one texture at a time in a for loop) 04432 glMatrixMode( GL_PROJECTION ); 04433 glPushMatrix(); 04434 glLoadIdentity(); 04435 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 04436 0, m_3DTexturePosition->GetMaxCoordT() ); 04437 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04438 // 04439 glMatrixMode( GL_MODELVIEW ); 04440 glPushMatrix(); 04441 glLoadIdentity(); 04442 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04443 // 04444 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 04445 m_3DTexturePosition->GetHeight() ); 04446 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04447 // 04448 //================================================= 04449 //------------------------------------------------- 04450 // Uniform Variables 04451 //------------------------------------------------- 04452 // Set Tool Tips and Collidable Spheres 04453 m_glslProgObjPtr->SetUniform1i( "graspID", graspID ); 04454 m_glslProgObjPtr->SetUniform1i( "NumberOfToolTips", NumOfTooltips ); 04455 m_glslProgObjPtr->SetUniform4fv( "ToolTip", NumOfTooltips, Tooltips ); 04456 //------------------------------------------------- 04457 04458 //m_3DTexturePosition->EnableTextureTarget(); 04459 //------------------------------------------------- 04460 // Set PositionTexture to Texture Unit 0 04461 glActiveTexture( GL_TEXTURE0 ); 04462 m_3DTexturePosition->BindTexture(0); 04463 m_glslProgObjPtr->SetUniform1i( "PositionTexture", 0 ); 04464 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04465 04466 //------------------------------------------------- 04467 //================================================= 04468 T offsetRCoord = offsetCoordRPosition / 2.0; 04469 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 04470 //------------------------------------------------- 04471 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04472 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 04473 glFramebufferTexture3DEXT( 04474 GL_FRAMEBUFFER_EXT, // target 04475 GL_COLOR_ATTACHMENT0_EXT, // attached frame 04476 m_3DTexturePosition->GetTarget(), // texture target 04477 m_3DTexturePosition->GetTexture(1), // texture id -- next position 04478 0, // level 04479 i // zoffset 04480 ); 04481 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04482 //------------------------------------------------- 04483 glFramebufferTexture3DEXT( 04484 GL_FRAMEBUFFER_EXT, // target 04485 GL_COLOR_ATTACHMENT1_EXT, // attached frame 04486 m_3DTextureOffsetValues->GetTarget(), // texture target 04487 m_3DTextureOffsetValues->GetTexture(0), // texture id 04488 0, // level 04489 i // zoffset 04490 ); 04491 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04492 //------------------------------------------------- 04493 //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 04494 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 04495 //glDrawBuffers( 2, MRT ); 04496 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 04497 glDrawBuffers( 2, drawBuffers ); 04498 //------------------------------------------------- 04499 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04500 //------------------------------------------------- 04501 // Send data stream to GPU 04502 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04503 // 04504 glClearColor( 0, 0, 0, 0 ); 04505 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 04506 glClear( GL_COLOR_BUFFER_BIT ); 04507 // 04508 T coordR = offsetCoordRPosition * i + offsetRCoord; 04509 glPolygonMode( GL_FRONT, GL_FILL ); 04510 glBegin( GL_QUADS ); 04511 glTexCoord3f( 0, 0, coordR ); 04512 glVertex3f ( 0, 0, 0 ); 04513 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 04514 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 04515 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 04516 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 04517 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 04518 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 04519 glEnd(); 04520 } 04521 glPopMatrix(); 04522 glMatrixMode( GL_PROJECTION ); 04523 glPopMatrix(); 04524 glMatrixMode( GL_MODELVIEW ); 04525 } 04526 glPopAttrib(); 04527 m_3DTexturePosition->DisableTextureTarget(); 04528 m_3DTexturePosition->UnbindTexture(); 04529 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 04530 // 04531 m_glslProgObjPtr->EndGLSL(); 04532 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04533 //--------------------------------------------------------------- 04534 // Swap Textures 04535 SwapPositionTextures(); 04536 04537 //* 04538 //=============================================================== 04539 // Read collision data from a texture to memory 04540 //--------------------------------------------------------------- 04541 GLsizei sizeCD = 04542 m_3DTextureCollisionDetection->GetWidth() * 04543 m_3DTextureCollisionDetection->GetHeight() * 04544 m_3DTextureCollisionDetection->GetDepth() * 04545 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 04546 GLfloat * dataCD = new GLfloat[ sizeCD ]; 04547 int i = 0; 04548 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 04549 m_3DTextureCollisionDetection->BindTexture(0); 04550 glGetTexImage( 04551 m_3DTextureCollisionDetection->GetTarget(), 04552 m_3DTextureCollisionDetection->GetLevel(), 04553 m_3DTextureCollisionDetection->GetPixelFormat(), 04554 m_3DTextureCollisionDetection->GetDataType(), 04555 dataCD 04556 ); 04557 Vector3<T> totalCD( 0, 0, 0 ); 04558 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04559 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 04560 for ( int i = 0; i < sizeCD; i+=4 ) { 04561 //std::cout << dataCD[i] << ", "; 04562 totalCD[0] += dataCD[i]; 04563 totalCD[1] += dataCD[i+1]; 04564 totalCD[2] += dataCD[i+2]; 04565 } 04566 //if ( totalCD.Length() > 0.0 ) { 04567 // std::cout << "Total CD: " << totalCD << "\n"; 04568 //} 04569 delete [] dataCD; 04570 //----------------------------------------------------- 04571 // Update simulation state(s) 04572 UpdateCollisionStatus( totalCD.Length() ); 04573 //--------------------------------------------------------------- 04574 //=============================================================== 04575 //*/ 04576 04577 return totalCD; 04578 //return Vector3<T>( 0, 0, 0 ); 04579 //*/ 04580 } 04581 //----------------------------------------------------------------------------- 04582 // END: CollisionDetectionForGrabbingStartOrEnd ( ... ) 04583 //***************************************************************************** 04584 04585 04586 //***************************************************************************** 04587 // BEGIN: CollisionDetectionForGrabbingMove ( ... ) 04588 //----------------------------------------------------------------------------- 04589 // Collision Detection by GLSL 04590 template <typename T> 04591 Vector3<T> ModelDeformableGLSL<T>::CollisionDetectionForGrabbingMove ( 04592 int NumOfTooltips, GLfloat Tooltips[8], 04593 int graspID // must be greater than one 04594 ) 04595 { 04596 #ifdef TAPs_DEBUG_MODE 04597 if ( NumOfTooltips > 2 ) NumOfTooltips = 2; 04598 #endif 04599 04600 //assert( m_glslProgramObjectForDefModelCDGrabMove ); 04601 if ( !m_glslProgramObjectForDefModelCDGrabMove ) return Vector3<T>(0,0,0); 04602 04603 GLSLProgramObject * m_glslProgObjPtr = m_glslProgramObjectForDefModelCDGrabMove; 04604 04605 //UpdateParametersForCollisionDetectionForGrabbing(); 04606 //--------------------------------------------------------------- 04607 m_3DTexturePosition->EnableTextureTarget(); 04608 m_glslProgObjPtr->BeginGLSL(); 04609 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04610 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04611 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04612 glPushAttrib( GL_ALL_ATTRIB_BITS ); 04613 { 04614 //------------------------------------------------- 04615 // Send Stream of Data (one texture at a time in a for loop) 04616 glMatrixMode( GL_PROJECTION ); 04617 glPushMatrix(); 04618 glLoadIdentity(); 04619 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 04620 0, m_3DTexturePosition->GetMaxCoordT() ); 04621 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04622 // 04623 glMatrixMode( GL_MODELVIEW ); 04624 glPushMatrix(); 04625 glLoadIdentity(); 04626 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04627 // 04628 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 04629 m_3DTexturePosition->GetHeight() ); 04630 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04631 // 04632 //================================================= 04633 //------------------------------------------------- 04634 // Uniform Variables 04635 //------------------------------------------------- 04636 // Set Tool Tips and Collidable Spheres 04637 m_glslProgObjPtr->SetUniform1i( "graspID", graspID ); 04638 m_glslProgObjPtr->SetUniform1i( "NumberOfToolTips", NumOfTooltips ); 04639 m_glslProgObjPtr->SetUniform4fv( "ToolTip", NumOfTooltips, Tooltips ); 04640 //------------------------------------------------- 04641 04642 //m_3DTexturePosition->EnableTextureTarget(); 04643 //------------------------------------------------- 04644 // Set PositionTexture to Texture Unit 0 04645 glActiveTexture( GL_TEXTURE0 ); 04646 m_3DTexturePosition->BindTexture(0); 04647 m_glslProgObjPtr->SetUniform1i( "PositionTexture", 0 ); 04648 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04649 04650 //------------------------------------------------- 04651 // Set OffsetTexture to Texture Unit 1 04652 glActiveTexture( GL_TEXTURE1 ); 04653 m_3DTextureOffsetValues->BindTexture(0); 04654 m_glslProgObjPtr->SetUniform1i( "OffsetTexture", 1 ); 04655 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04656 04657 //------------------------------------------------- 04658 //================================================= 04659 T offsetRCoord = offsetCoordRPosition / 2.0; 04660 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 04661 //------------------------------------------------- 04662 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04663 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 04664 glFramebufferTexture3DEXT( 04665 GL_FRAMEBUFFER_EXT, // target 04666 GL_COLOR_ATTACHMENT0_EXT, // attached frame 04667 m_3DTexturePosition->GetTarget(), // texture target 04668 m_3DTexturePosition->GetTexture(1), // texture id -- next position 04669 0, // level 04670 i // zoffset 04671 ); 04672 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04673 //------------------------------------------------- 04674 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 04675 //------------------------------------------------- 04676 // Send data stream to GPU 04677 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04678 // 04679 glClearColor( 0, 0, 0, 0 ); 04680 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 04681 glClear( GL_COLOR_BUFFER_BIT ); 04682 // 04683 T coordR = offsetCoordRPosition * i + offsetRCoord; 04684 glPolygonMode( GL_FRONT, GL_FILL ); 04685 glBegin( GL_QUADS ); 04686 glTexCoord3f( 0, 0, coordR ); 04687 glVertex3f ( 0, 0, 0 ); 04688 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 04689 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 04690 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 04691 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 04692 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 04693 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 04694 glEnd(); 04695 } 04696 glPopMatrix(); 04697 glMatrixMode( GL_PROJECTION ); 04698 glPopMatrix(); 04699 glMatrixMode( GL_MODELVIEW ); 04700 } 04701 glPopAttrib(); 04702 m_3DTexturePosition->DisableTextureTarget(); 04703 m_3DTexturePosition->UnbindTexture(); 04704 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 04705 // 04706 m_glslProgObjPtr->EndGLSL(); 04707 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04708 //--------------------------------------------------------------- 04709 // Swap Textures 04710 SwapPositionTextures(); 04711 04712 /* 04713 //=============================================================== 04714 // Read collision data from a texture to memory 04715 //--------------------------------------------------------------- 04716 GLsizei sizeCD = 04717 m_3DTextureCollisionDetection->GetWidth() * 04718 m_3DTextureCollisionDetection->GetHeight() * 04719 m_3DTextureCollisionDetection->GetDepth() * 04720 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 04721 GLfloat * dataCD = new GLfloat[ sizeCD ]; 04722 int i = 0; 04723 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 04724 m_3DTextureCollisionDetection->BindTexture(0); 04725 glGetTexImage( 04726 m_3DTextureCollisionDetection->GetTarget(), 04727 m_3DTextureCollisionDetection->GetLevel(), 04728 m_3DTextureCollisionDetection->GetPixelFormat(), 04729 m_3DTextureCollisionDetection->GetDataType(), 04730 dataCD 04731 ); 04732 Vector3<T> totalCD( 0, 0, 0 ); 04733 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04734 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 04735 for ( int i = 0; i < sizeCD; i+=4 ) { 04736 //std::cout << dataCD[i] << ", "; 04737 totalCD[0] += dataCD[i]; 04738 totalCD[1] += dataCD[i+1]; 04739 totalCD[2] += dataCD[i+2]; 04740 } 04741 //if ( totalCD.Length() > 0.0 ) { 04742 // std::cout << "Total CD: " << totalCD << "\n"; 04743 //} 04744 delete [] dataCD; 04745 //----------------------------------------------------- 04746 // Update simulation state(s) 04747 UpdateCollisionStatus( totalCD.Length() ); 04748 //--------------------------------------------------------------- 04749 //=============================================================== 04750 //*/ 04751 04752 //return totalCD; 04753 return Vector3<T>( 0.0, 0.0, 0.0 ); 04754 //*/ 04755 } 04756 //----------------------------------------------------------------------------- 04757 // END: CollisionDetectionForGrabbingMove ( ... ) 04758 //***************************************************************************** 04759 04760 04761 //***************************************************************************** 04762 // BEGIN: UpdateParametersForCollisionDetectionForGrabbing 04763 //----------------------------------------------------------------------------- 04764 template <typename T> 04765 void ModelDeformableGLSL<T>::UpdateParametersForCollisionDetectionForGrabbing () 04766 { 04767 m_glslProgramObjectForDefModelCDGrabStart->BeginGLSL(); 04768 //--------------------------------------------------------------- 04769 m_glslProgramObjectForDefModelCDGrabStart->SetUniform1f( "threshold", m_tSimThreshold ); 04770 m_glslProgramObjectForDefModelCDGrabStart->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 04771 //--------------------------------------------------------------- 04772 m_glslProgramObjectForDefModelCDGrabStart->EndGLSL(); 04773 04774 m_glslProgramObjectForDefModelCDGrabMove->BeginGLSL(); 04775 //--------------------------------------------------------------- 04776 m_glslProgramObjectForDefModelCDGrabMove->SetUniform1f( "threshold", m_tSimThreshold ); 04777 m_glslProgramObjectForDefModelCDGrabMove->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 04778 //--------------------------------------------------------------- 04779 m_glslProgramObjectForDefModelCDGrabMove->EndGLSL(); 04780 04781 m_glslProgramObjectForDefModelCDGrabEnd->BeginGLSL(); 04782 //--------------------------------------------------------------- 04783 m_glslProgramObjectForDefModelCDGrabEnd->SetUniform1f( "threshold", m_tSimThreshold ); 04784 m_glslProgramObjectForDefModelCDGrabEnd->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 04785 //--------------------------------------------------------------- 04786 m_glslProgramObjectForDefModelCDGrabEnd->EndGLSL(); 04787 } 04788 //------------------------------------------------------------------------- 04789 // END: UpdateParametersForCollisionDetectionForGrabbing 04790 //************************************************************************* 04791 04792 04793 //***************************************************************************** 04794 // BEGIN: CollisionDetectionTooltipSphereCylinder ( ... ) 04795 //----------------------------------------------------------------------------- 04811 // Collision Detection by GLSL 04812 template <typename T> 04813 Vector3<T> ModelDeformableGLSL<T>::CollisionDetectionTooltipSphereCylinder ( 04814 int NumOfTooltips, GLfloat Tooltips[8], // # of tools and tooltip sphere (4 (xyz and raidus) per tool) 04815 GLfloat fCylLowPt, GLfloat fCylHighPt, GLfloat fCylRadius, // cylinder low pt, high pt, & radius 04816 GLfloat transformMatrix[16], // | 00 04 08 12 | 04817 // | 01 05 09 13 | 04818 // | 02 06 10 14 | 04819 // | 03 07 11 15 | 04820 GLfloat invTransformMatrix[16] // | 00 04 08 12 | 04821 // | 01 05 09 13 | 04822 // | 02 06 10 14 | 04823 // | 03 07 11 15 | 04824 ) 04825 { 04826 #ifdef TAPs_DEBUG_MODE 04827 if ( NumOfTooltips > 2 ) NumOfTooltips = 2; 04828 #endif 04829 04830 //assert( m_glslProgramObjectForDefModelCDTooltipSphereCylinder ); 04831 if ( !m_glslProgramObjectForDefModelCDTooltipSphereCylinder ) return Vector3<T>(0,0,0); 04832 04833 //UpdateParametersForCDTooltipSphereCylinder(); 04834 //--------------------------------------------------------------- 04835 m_3DTexturePosition->EnableTextureTarget(); 04836 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->BeginGLSL(); 04837 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04838 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04839 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04840 glPushAttrib( GL_ALL_ATTRIB_BITS ); 04841 { 04842 //------------------------------------------------- 04843 // Send Stream of Data (one texture at a time in a for loop) 04844 glMatrixMode( GL_PROJECTION ); 04845 glPushMatrix(); 04846 glLoadIdentity(); 04847 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 04848 0, m_3DTexturePosition->GetMaxCoordT() ); 04849 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04850 // 04851 glMatrixMode( GL_MODELVIEW ); 04852 glPushMatrix(); 04853 glLoadIdentity(); 04854 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04855 // 04856 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 04857 m_3DTexturePosition->GetHeight() ); 04858 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04859 // 04860 //================================================= 04861 //------------------------------------------------- 04862 // Uniform Variables 04863 //------------------------------------------------- 04864 // Set Tool Tips and Collidable Spheres 04865 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1i( "NumberOfToolTips", NumOfTooltips ); 04866 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform4fv( "ToolTip", NumOfTooltips, Tooltips ); 04867 // Set Tool shaft's cylinder height and radius and its inverse transformation matrix 04868 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1f( "CylLowPt", fCylLowPt ); 04869 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1f( "CylHighPt", fCylHighPt ); 04870 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1f( "CylRadius", fCylRadius ); 04871 // 4x4 matrix, 1 matrix, no transpose, GLfloat *matrix 04872 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniformMatrix4fv( "TransformMatrix", 1, false, transformMatrix ); 04873 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniformMatrix4fv( "InvTransformMatrix", 1, false, invTransformMatrix ); 04874 //------------------------------------------------- 04875 04876 //m_3DTexturePosition->EnableTextureTarget(); 04877 //------------------------------------------------- 04878 // Set PositionTexture to Texture Unit 0 04879 glActiveTexture( GL_TEXTURE0 ); 04880 m_3DTexturePosition->BindTexture(0); 04881 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1i( "PositionTexture", 0 ); 04882 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04883 04884 //------------------------------------------------- 04885 //================================================= 04886 T offsetRCoord = offsetCoordRPosition / 2.0; 04887 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 04888 //------------------------------------------------- 04889 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 04890 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 04891 glFramebufferTexture3DEXT( 04892 GL_FRAMEBUFFER_EXT, // target 04893 GL_COLOR_ATTACHMENT0_EXT, // attached frame 04894 m_3DTexturePosition->GetTarget(), // texture target 04895 m_3DTexturePosition->GetTexture(1), // texture id -- next position 04896 0, // level 04897 i // zoffset 04898 ); 04899 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04900 //------------------------------------------------- 04901 glFramebufferTexture3DEXT( 04902 GL_FRAMEBUFFER_EXT, // target 04903 GL_COLOR_ATTACHMENT1_EXT, // attached frame 04904 m_3DTextureCollisionDetection->GetTarget(), // texture target 04905 m_3DTextureCollisionDetection->GetTexture(0), // texture id 04906 0, // level 04907 i // zoffset 04908 ); 04909 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04910 //------------------------------------------------- 04911 //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 04912 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 04913 //glDrawBuffers( 2, MRT ); 04914 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 04915 glDrawBuffers( 2, drawBuffers ); 04916 //------------------------------------------------- 04917 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 04918 //------------------------------------------------- 04919 // Send data stream to GPU 04920 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04921 // 04922 glClearColor( 0, 0, 0, 0 ); 04923 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 04924 glClear( GL_COLOR_BUFFER_BIT ); 04925 // 04926 T coordR = offsetCoordRPosition * i + offsetRCoord; 04927 glPolygonMode( GL_FRONT, GL_FILL ); 04928 glBegin( GL_QUADS ); 04929 glTexCoord3f( 0, 0, coordR ); 04930 glVertex3f ( 0, 0, 0 ); 04931 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 04932 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 04933 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 04934 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 04935 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 04936 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 04937 glEnd(); 04938 } 04939 glPopMatrix(); 04940 glMatrixMode( GL_PROJECTION ); 04941 glPopMatrix(); 04942 glMatrixMode( GL_MODELVIEW ); 04943 } 04944 glPopAttrib(); 04945 m_3DTexturePosition->DisableTextureTarget(); 04946 m_3DTexturePosition->UnbindTexture(); 04947 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 04948 // 04949 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->EndGLSL(); 04950 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04951 //--------------------------------------------------------------- 04952 // Swap Textures 04953 SwapPositionTextures(); 04954 04955 //=============================================================== 04956 // Read collision data from a texture to memory 04957 //--------------------------------------------------------------- 04958 GLsizei sizeCD = 04959 m_3DTextureCollisionDetection->GetWidth() * 04960 m_3DTextureCollisionDetection->GetHeight() * 04961 m_3DTextureCollisionDetection->GetDepth() * 04962 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 04963 GLfloat * dataCD = new GLfloat[ sizeCD ]; 04964 int i = 0; 04965 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 04966 m_3DTextureCollisionDetection->BindTexture(0); 04967 glGetTexImage( 04968 m_3DTextureCollisionDetection->GetTarget(), 04969 m_3DTextureCollisionDetection->GetLevel(), 04970 m_3DTextureCollisionDetection->GetPixelFormat(), 04971 m_3DTextureCollisionDetection->GetDataType(), 04972 dataCD 04973 ); 04974 Vector3<T> totalCD( 0, 0, 0 ); 04975 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 04976 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 04977 for ( int i = 0; i < sizeCD; i+=4 ) { 04978 //std::cout << dataCD[i] << ", "; 04979 totalCD[0] += dataCD[i]; 04980 totalCD[1] += dataCD[i+1]; 04981 totalCD[2] += dataCD[i+2]; 04982 } 04983 //if ( totalCD.Length() > 0.0 ) { 04984 // std::cout << "Total CD: " << totalCD << "\n"; 04985 //} 04986 delete [] dataCD; 04987 //--------------------------------------------------------------- 04988 //=============================================================== 04989 //} 04990 //*/ 04991 //*/ 04992 04993 //----------------------------------------------------- 04994 // Update simulation state(s) 04995 UpdateCollisionStatus( totalCD.Length() ); 04996 //----------------------------------------------------- 04997 return totalCD; 04998 //*/ 04999 } 05000 //----------------------------------------------------------------------------- 05001 // END: CollisionDetectionTooltipSphereCylinder ( ... ) 05002 //***************************************************************************** 05003 05004 05005 //***************************************************************************** 05006 // BEGIN: UpdateParametersForCDTooltipSphereCylinder 05007 //----------------------------------------------------------------------------- 05008 template <typename T> 05009 void ModelDeformableGLSL<T>::UpdateParametersForCDTooltipSphereCylinder () 05010 { 05011 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->BeginGLSL(); 05012 //--------------------------------------------------------------- 05013 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1f( "threshold", m_tSimThreshold ); 05014 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 05015 //--------------------------------------------------------------- 05016 m_glslProgramObjectForDefModelCDTooltipSphereCylinder->EndGLSL(); 05017 } 05018 //------------------------------------------------------------------------- 05019 // END: UpdateParametersForCDTooltipSphereCylinder 05020 //************************************************************************* 05021 05022 05023 //***************************************************************************** 05024 // BEGIN: RemoveElementsByCollision (void) 05025 //----------------------------------------------------------------------------- 05026 // Remove Elements by Collision Detection by GLSL 05027 template <typename T> 05028 Vector3<T> ModelDeformableGLSL<T>::RemoveElementsByCollision () 05029 { 05030 //assert( m_glslProgramObjectForRemovingElements ); 05031 if ( !m_glslProgramObjectForRemovingElements ) return Vector3<T>(0,0,0); 05032 //--------------------------------------------------------------- 05033 m_3DTexturePosition->EnableTextureTarget(); 05034 m_glslProgramObjectForRemovingElements->BeginGLSL(); 05035 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05036 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05037 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05038 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05039 { 05040 //------------------------------------------------- 05041 // Send Stream of Data (one texture at a time in a for loop) 05042 glMatrixMode( GL_PROJECTION ); 05043 glPushMatrix(); 05044 glLoadIdentity(); 05045 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 05046 0, m_3DTexturePosition->GetMaxCoordT() ); 05047 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05048 // 05049 glMatrixMode( GL_MODELVIEW ); 05050 glPushMatrix(); 05051 glLoadIdentity(); 05052 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05053 // 05054 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 05055 m_3DTexturePosition->GetHeight() ); 05056 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05057 // 05058 //================================================= 05059 //------------------------------------------------- 05060 // Uniform Variables 05061 //-------------------- 05062 // Threshold 05063 m_glslProgramObjectForRemovingElements->SetUniform1f( "threshold", m_tSimThreshold ); 05064 // 05065 GLfloat Tooltip[4]; 05066 Tooltip[0] = 1000.0f; 05067 Tooltip[1] = 1000.0f; 05068 Tooltip[2] = 1000.0f; 05069 Tooltip[3] = 0.25f; 05070 #ifdef TAPs_USE_HAPTIC 05071 HLdouble proxyPosition[3]; 05072 hlGetDoublev( HL_PROXY_POSITION, proxyPosition ); 05073 Tooltip[0] = proxyPosition[0]; 05074 Tooltip[1] = proxyPosition[1]; 05075 Tooltip[2] = proxyPosition[2]; 05076 #endif 05077 05078 const GLint numberOfSpheres = 1; 05079 GLfloat sphere[numberOfSpheres * 4]; // 4 for Center (x,y,z) and Radius (w) 05080 // 05081 sphere[0] = -1.0f; 05082 sphere[1] = -1.0f; 05083 sphere[2] = 0.0f; 05084 sphere[3] = 1.0f; 05085 //sphere[4] = 1.0f; 05086 //sphere[5] = 1.0f; 05087 //sphere[6] = -1.0f; 05088 //sphere[7] = 1.0f; 05089 // 05090 05091 //----------------------------------------------------------- 05092 // Set Uniform Variables 05093 m_glslProgramObjectForRemovingElements->SetUniform1i( "NumberOfSpheres", numberOfSpheres ); 05094 05095 m_glslProgramObjectForRemovingElements->SetUniform4fv( "Sphere", numberOfSpheres, sphere ); 05096 //m_glslProgramObjectForRemovingElements->SetUniform1fv( "Sphere", numberOfSpheres*4, sphere ); 05097 05098 m_glslProgramObjectForRemovingElements->SetUniform4fv( "ToolTip", numberOfSpheres, Tooltip ); 05099 //----------------------------------------------------------- 05100 05101 //m_3DTexturePosition->EnableTextureTarget(); 05102 //------------------------------------------------- 05103 // Set PositionTexture to Texture Unit 0 05104 glActiveTexture( GL_TEXTURE0 ); 05105 m_3DTexturePosition->BindTexture(0); 05106 m_glslProgramObjectForRemovingElements->SetUniform1i( "PositionTexture", 0 ); 05107 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05108 05109 //------------------------------------------------- 05110 //================================================= 05111 T offsetRCoord = offsetCoordRPosition / 2.0; 05112 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 05113 //------------------------------------------------- 05114 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05115 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 05116 glFramebufferTexture3DEXT( 05117 GL_FRAMEBUFFER_EXT, // target 05118 GL_COLOR_ATTACHMENT0_EXT, // attached frame 05119 m_3DTexturePosition->GetTarget(), // texture target 05120 m_3DTexturePosition->GetTexture(1), // texture id -- next position 05121 0, // level 05122 i // zoffset 05123 ); 05124 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05125 //------------------------------------------------- 05126 glFramebufferTexture3DEXT( 05127 GL_FRAMEBUFFER_EXT, // target 05128 GL_COLOR_ATTACHMENT1_EXT, // attached frame 05129 m_3DTextureCollisionDetection->GetTarget(), // texture target 05130 m_3DTextureCollisionDetection->GetTexture(0), // texture id 05131 0, // level 05132 i // zoffset 05133 ); 05134 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05135 //------------------------------------------------- 05136 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 05137 glDrawBuffers( 2, drawBuffers ); 05138 //------------------------------------------------- 05139 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05140 //------------------------------------------------- 05141 // Send data stream to GPU 05142 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05143 // 05144 glClearColor( 0, 0, 0, 0 ); 05145 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 05146 glClear( GL_COLOR_BUFFER_BIT ); 05147 // 05148 T coordR = offsetCoordRPosition * i + offsetRCoord; 05149 glPolygonMode( GL_FRONT, GL_FILL ); 05150 glBegin( GL_QUADS ); 05151 glTexCoord3f( 0, 0, coordR ); 05152 glVertex3f ( 0, 0, 0 ); 05153 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 05154 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 05155 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 05156 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 05157 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 05158 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 05159 glEnd(); 05160 } 05161 glPopMatrix(); 05162 glMatrixMode( GL_PROJECTION ); 05163 glPopMatrix(); 05164 glMatrixMode( GL_MODELVIEW ); 05165 } 05166 glPopAttrib(); 05167 m_3DTexturePosition->DisableTextureTarget(); 05168 m_3DTexturePosition->UnbindTexture(); 05169 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 05170 // 05171 m_glslProgramObjectForRemovingElements->EndGLSL(); 05172 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05173 //--------------------------------------------------------------- 05174 // Swap Textures 05175 SwapPositionTextures(); 05176 05177 // Update Connectivity due to a change in topology 05178 UpdateConnectivity(); 05179 05180 //=============================================================== 05181 // Read collision data from a texture to memory 05182 //--------------------------------------------------------------- 05183 GLsizei sizeCD = 05184 m_3DTextureCollisionDetection->GetWidth() * 05185 m_3DTextureCollisionDetection->GetHeight() * 05186 m_3DTextureCollisionDetection->GetDepth() * 05187 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 05188 GLfloat * dataCD = new GLfloat[ sizeCD ]; 05189 int i = 0; 05190 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 05191 m_3DTextureCollisionDetection->BindTexture(0); 05192 glGetTexImage( 05193 m_3DTextureCollisionDetection->GetTarget(), 05194 m_3DTextureCollisionDetection->GetLevel(), 05195 m_3DTextureCollisionDetection->GetPixelFormat(), 05196 m_3DTextureCollisionDetection->GetDataType(), 05197 dataCD 05198 ); 05199 Vector3<T> totalCD( 0, 0, 0 ); 05200 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05201 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 05202 for ( int i = 0; i < sizeCD; i+=4 ) { 05203 //std::cout << dataCD[i] << ", "; 05204 totalCD[0] += dataCD[i]; 05205 totalCD[1] += dataCD[i+1]; 05206 totalCD[2] += dataCD[i+2]; 05207 } 05208 //if ( totalCD.Length() > 0.0 ) { 05209 // std::cout << "Total CD: " << totalCD << "\n"; 05210 //} 05211 delete [] dataCD; 05212 //--------------------------------------------------------------- 05213 //=============================================================== 05214 05215 //----------------------------------------------------- 05216 // Update simulation state(s) 05217 UpdateCollisionStatus( totalCD.Length() ); 05218 //----------------------------------------------------- 05219 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05220 m_Visualization_RTGenMesh->UpdateCubeTrackingTexture(); 05221 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05222 05223 return totalCD; 05224 //*/ 05225 } 05226 //----------------------------------------------------------------------------- 05227 // END: RemoveElementsByCollision (void) 05228 //***************************************************************************** 05229 05230 05231 //***************************************************************************** 05232 // BEGIN: RemoveElementsByCollision ( ... ) 05233 //----------------------------------------------------------------------------- 05234 // Remove Elements by Collision Detection by GLSL 05235 template <typename T> 05236 Vector3<T> ModelDeformableGLSL<T>::RemoveElementsByCollision ( 05237 int NumOfTooltips, GLfloat Tooltips[8], 05238 int NumOfSpheres, GLfloat CollidableSpheres[32] 05239 ) 05240 { 05241 #ifdef TAPs_DEBUG_MODE 05242 if ( NumOfTooltips > 2 ) NumOfTooltips = 2; 05243 if ( NumOfSpheres > 8 ) NumOfSpheres = 8; 05244 #endif 05245 05246 //assert( m_glslProgramObjectForRemovingElements ); 05247 if ( !m_glslProgramObjectForRemovingElements ) return Vector3<T>(0,0,0); 05248 05249 //UpdateRemoveElementsByCollisionParameters(); 05250 //--------------------------------------------------------------- 05251 m_3DTexturePosition->EnableTextureTarget(); 05252 m_glslProgramObjectForRemovingElements->BeginGLSL(); 05253 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05254 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05255 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05256 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05257 { 05258 //------------------------------------------------- 05259 // Send Stream of Data (one texture at a time in a for loop) 05260 glMatrixMode( GL_PROJECTION ); 05261 glPushMatrix(); 05262 glLoadIdentity(); 05263 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 05264 0, m_3DTexturePosition->GetMaxCoordT() ); 05265 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05266 // 05267 glMatrixMode( GL_MODELVIEW ); 05268 glPushMatrix(); 05269 glLoadIdentity(); 05270 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05271 // 05272 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 05273 m_3DTexturePosition->GetHeight() ); 05274 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05275 // 05276 //================================================= 05277 // Uniform Variables 05278 //------------------------------------------------- 05279 // Set Tool Tips and Collidable Spheres 05280 m_glslProgramObjectForRemovingElements->SetUniform1i( "NumberOfSpheres", NumOfSpheres ); 05281 m_glslProgramObjectForRemovingElements->SetUniform4fv( "Sphere", NumOfSpheres, CollidableSpheres ); 05282 m_glslProgramObjectForRemovingElements->SetUniform1i( "NumberOfToolTips", NumOfTooltips ); 05283 m_glslProgramObjectForRemovingElements->SetUniform4fv( "ToolTip", NumOfTooltips, Tooltips ); 05284 //------------------------------------------------- 05285 //m_3DTexturePosition->EnableTextureTarget(); 05286 //------------------------------------------------- 05287 // Set PositionTexture to Texture Unit 0 05288 glActiveTexture( GL_TEXTURE0 ); 05289 m_3DTexturePosition->BindTexture(0); 05290 m_glslProgramObjectForRemovingElements->SetUniform1i( "PositionTexture", 0 ); 05291 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05292 05293 //------------------------------------------------- 05294 //================================================= 05295 T offsetRCoord = offsetCoordRPosition / 2.0; 05296 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 05297 //------------------------------------------------- 05298 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05299 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 05300 glFramebufferTexture3DEXT( 05301 GL_FRAMEBUFFER_EXT, // target 05302 GL_COLOR_ATTACHMENT0_EXT, // attached frame 05303 m_3DTexturePosition->GetTarget(), // texture target 05304 m_3DTexturePosition->GetTexture(1), // texture id -- next position 05305 0, // level 05306 i // zoffset 05307 ); 05308 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05309 //------------------------------------------------- 05310 glFramebufferTexture3DEXT( 05311 GL_FRAMEBUFFER_EXT, // target 05312 GL_COLOR_ATTACHMENT1_EXT, // attached frame 05313 m_3DTextureCollisionDetection->GetTarget(), // texture target 05314 m_3DTextureCollisionDetection->GetTexture(0), // texture id 05315 0, // level 05316 i // zoffset 05317 ); 05318 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05319 //------------------------------------------------- 05320 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 05321 glDrawBuffers( 2, drawBuffers ); 05322 //------------------------------------------------- 05323 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05324 //------------------------------------------------- 05325 // Send data stream to GPU 05326 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05327 // 05328 glClearColor( 0, 0, 0, 0 ); 05329 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 05330 glClear( GL_COLOR_BUFFER_BIT ); 05331 // 05332 T coordR = offsetCoordRPosition * i + offsetRCoord; 05333 glPolygonMode( GL_FRONT, GL_FILL ); 05334 glBegin( GL_QUADS ); 05335 glTexCoord3f( 0, 0, coordR ); 05336 glVertex3f ( 0, 0, 0 ); 05337 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 05338 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 05339 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 05340 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 05341 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 05342 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 05343 glEnd(); 05344 } 05345 glPopMatrix(); 05346 glMatrixMode( GL_PROJECTION ); 05347 glPopMatrix(); 05348 glMatrixMode( GL_MODELVIEW ); 05349 } 05350 glPopAttrib(); 05351 m_3DTexturePosition->DisableTextureTarget(); 05352 m_3DTexturePosition->UnbindTexture(); 05353 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 05354 // 05355 m_glslProgramObjectForRemovingElements->EndGLSL(); 05356 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05357 //--------------------------------------------------------------- 05358 // Swap Textures 05359 SwapPositionTextures(); 05360 05361 // Update Connectivity due to a change in topology 05362 UpdateConnectivity(); 05363 05364 //=============================================================== 05365 // Read collision data from a texture to memory 05366 //--------------------------------------------------------------- 05367 GLsizei sizeCD = 05368 m_3DTextureCollisionDetection->GetWidth() * 05369 m_3DTextureCollisionDetection->GetHeight() * 05370 m_3DTextureCollisionDetection->GetDepth() * 05371 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 05372 GLfloat * dataCD = new GLfloat[ sizeCD ]; 05373 int i = 0; 05374 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 05375 m_3DTextureCollisionDetection->BindTexture(0); 05376 glGetTexImage( 05377 m_3DTextureCollisionDetection->GetTarget(), 05378 m_3DTextureCollisionDetection->GetLevel(), 05379 m_3DTextureCollisionDetection->GetPixelFormat(), 05380 m_3DTextureCollisionDetection->GetDataType(), 05381 dataCD 05382 ); 05383 Vector3<T> totalCD( 0, 0, 0 ); 05384 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05385 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 05386 for ( int i = 0; i < sizeCD; i+=4 ) { 05387 //std::cout << dataCD[i] << ", "; 05388 totalCD[0] += dataCD[i]; 05389 totalCD[1] += dataCD[i+1]; 05390 totalCD[2] += dataCD[i+2]; 05391 } 05392 //if ( totalCD.Length() > 0.0 ) { 05393 // std::cout << "Total CD: " << totalCD << "\n"; 05394 //} 05395 delete [] dataCD; 05396 //--------------------------------------------------------------- 05397 //=============================================================== 05398 05399 //----------------------------------------------------- 05400 // Update simulation state(s) 05401 UpdateCollisionStatus( totalCD.Length() ); 05402 //----------------------------------------------------- 05403 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05404 m_Visualization_RTGenMesh->UpdateCubeTrackingTexture(); 05405 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05406 05407 return totalCD; 05408 //*/ 05409 } 05410 //----------------------------------------------------------------------------- 05411 // END: RemoveElementsByCollision ( ... ) 05412 //***************************************************************************** 05413 05414 05415 //***************************************************************************** 05416 // BEGIN: UpdateRemoveElementsByCollisionParameters 05417 //----------------------------------------------------------------------------- 05418 template <typename T> 05419 void ModelDeformableGLSL<T>::UpdateParametersForRemoveElementsByCollision () 05420 { 05421 m_glslProgramObjectForRemovingElements->BeginGLSL(); 05422 //--------------------------------------------------------------- 05423 m_glslProgramObjectForRemovingElements->SetUniform1f( "threshold", m_tSimThreshold ); 05424 m_glslProgramObjectForRemovingElements->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 05425 //--------------------------------------------------------------- 05426 m_glslProgramObjectForRemovingElements->EndGLSL(); 05427 } 05428 //------------------------------------------------------------------------- 05429 // END: UpdateParametersForRemoveElementsByCollision 05430 //************************************************************************* 05431 05432 05433 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05434 //***************************************************************************** 05435 // BEGIN: RemoveConnectionsByCollision ( ... ) 05436 //----------------------------------------------------------------------------- 05437 // Remove Connections by Collision Detection by GLSL 05450 template <typename T> 05451 Vector3<T> ModelDeformableGLSL<T>::RemoveConnectionsByCollision ( 05452 GLfloat width, GLfloat height, // rectangle width and height 05453 05454 GLfloat transformMatrix[16], // | 00 04 08 12 | 05455 // | 01 05 09 13 | 05456 // | 02 06 10 14 | 05457 // | 03 07 11 15 | 05458 05459 GLfloat invTransformMatrix[16] // | 00 04 08 12 | 05460 // | 01 05 09 13 | 05461 // | 02 06 10 14 | 05462 // | 03 07 11 15 | 05463 ) 05464 { 05465 //assert( m_glslProgramObjectForRemovingElements ); 05466 if ( !m_glslProgramObjectForRemovingConnections ) return Vector3<T>(0,0,0); 05467 05468 //UpdateRemoveConnectionsByCollisionParameters(); 05469 //--------------------------------------------------------------- 05470 m_3DTexturePosition->EnableTextureTarget(); 05471 05472 m_glslProgramObjectForRemovingConnections->BeginGLSL(); 05473 05474 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05475 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05476 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05477 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05478 { 05479 //------------------------------------------------- 05480 // Send Stream of Data (one texture at a time in a for loop) 05481 glMatrixMode( GL_PROJECTION ); 05482 glPushMatrix(); 05483 glLoadIdentity(); 05484 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 05485 0, m_3DTexturePosition->GetMaxCoordT() ); 05486 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05487 // 05488 glMatrixMode( GL_MODELVIEW ); 05489 glPushMatrix(); 05490 glLoadIdentity(); 05491 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05492 // 05493 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 05494 m_3DTexturePosition->GetHeight() ); 05495 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05496 // 05497 //================================================= 05498 //------------------------------------------------- 05499 // Uniform Variables 05500 //----------------------------- 05501 // Set Tool Tip's rectangle width and height and its inverse transformation matrix 05502 m_glslProgramObjectForRemovingConnections->SetUniform1f( "RectWidth", width ); 05503 m_glslProgramObjectForRemovingConnections->SetUniform1f( "RectHeight", height ); 05504 // 4x4 matrix, 1 matrix, no transpose, GLfloat *matrix 05505 m_glslProgramObjectForRemovingConnections->SetUniformMatrix4fv( "TransformMatrix", 1, false, transformMatrix ); 05506 m_glslProgramObjectForRemovingConnections->SetUniformMatrix4fv( "InvTransformMatrix", 1, false, invTransformMatrix ); 05507 //------------------------------------------------- 05508 //m_3DTexturePosition->EnableTextureTarget(); 05509 //------------------------------------------------- 05510 // Set PositionTexture to Texture Unit 0 05511 glActiveTexture( GL_TEXTURE0 ); 05512 m_3DTexturePosition->BindTexture(0); 05513 m_glslProgramObjectForRemovingConnections->SetUniform1i( "PositionTexture", 0 ); 05514 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05515 //------------------------------------------------- 05516 // Set ConnectivityTexture to Texture Unit 1 05517 glActiveTexture( GL_TEXTURE1 ); 05518 m_3DTextureConnectivity->BindTexture(0); 05519 m_glslProgramObjectForRemovingConnections->SetUniform1i( "ConnectivityTexture", 1 ); 05520 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05521 05522 //------------------------------------------------- 05523 //================================================= 05524 T offsetRCoord = offsetCoordRPosition / 2.0; 05525 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 05526 //------------------------------------------------- 05527 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05528 //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vCollisionDetection ); 05529 glFramebufferTexture3DEXT( 05530 GL_FRAMEBUFFER_EXT, // target 05531 GL_COLOR_ATTACHMENT0_EXT, // attached frame 05532 m_3DTexturePosition->GetTarget(), // texture target 05533 m_3DTexturePosition->GetTexture(1), // texture id -- next position 05534 0, // level 05535 i // zoffset 05536 ); 05537 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05538 //------------------------------------------------- 05539 glFramebufferTexture3DEXT( 05540 GL_FRAMEBUFFER_EXT, // target 05541 GL_COLOR_ATTACHMENT1_EXT, // attached frame 05542 m_3DTextureConnectivity->GetTarget(), // texture target 05543 m_3DTextureConnectivity->GetTexture(1), // texture id 05544 0, // level 05545 i // zoffset 05546 ); 05547 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05548 //------------------------------------------------- 05549 glFramebufferTexture3DEXT( 05550 GL_FRAMEBUFFER_EXT, // target 05551 GL_COLOR_ATTACHMENT2_EXT, // attached frame 05552 m_3DTextureCollisionDetection->GetTarget(), // texture target 05553 m_3DTextureCollisionDetection->GetTexture(0), // texture id 05554 0, // level 05555 i // zoffset 05556 ); 05557 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05558 //------------------------------------------------- 05559 GLenum drawBuffers[3] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT }; 05560 glDrawBuffers( 3, drawBuffers ); 05561 //------------------------------------------------- 05562 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05563 //------------------------------------------------- 05564 // Send data stream to GPU 05565 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05566 // 05567 glClearColor( 0, 0, 0, 0 ); 05568 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 05569 glClear( GL_COLOR_BUFFER_BIT ); 05570 // 05571 T coordR = offsetCoordRPosition * i + offsetRCoord; 05572 glPolygonMode( GL_FRONT, GL_FILL ); 05573 glBegin( GL_QUADS ); 05574 glTexCoord3f( 0, 0, coordR ); 05575 glVertex3f ( 0, 0, 0 ); 05576 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 05577 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 05578 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 05579 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 05580 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 05581 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 05582 glEnd(); 05583 } 05584 glPopMatrix(); 05585 glMatrixMode( GL_PROJECTION ); 05586 glPopMatrix(); 05587 glMatrixMode( GL_MODELVIEW ); 05588 } 05589 glPopAttrib(); 05590 m_3DTexturePosition->DisableTextureTarget(); 05591 m_3DTexturePosition->UnbindTexture(); 05592 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 05593 // 05594 m_glslProgramObjectForRemovingElements->EndGLSL(); 05595 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05596 //--------------------------------------------------------------- 05597 // Swap Textures 05598 SwapPositionTextures(); 05599 SwapConnectivityTextures(); 05600 05601 // Update Connectivity due to a change in topology 05602 UpdateConnectivity(); 05603 05604 //=============================================================== 05605 // Read collision data from a texture to memory 05606 //--------------------------------------------------------------- 05607 GLsizei sizeCD = 05608 m_3DTextureCollisionDetection->GetWidth() * 05609 m_3DTextureCollisionDetection->GetHeight() * 05610 m_3DTextureCollisionDetection->GetDepth() * 05611 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(); 05612 GLfloat * dataCD = new GLfloat[ sizeCD ]; 05613 int i = 0; 05614 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 05615 m_3DTextureCollisionDetection->BindTexture(0); 05616 glGetTexImage( 05617 m_3DTextureCollisionDetection->GetTarget(), 05618 m_3DTextureCollisionDetection->GetLevel(), 05619 m_3DTextureCollisionDetection->GetPixelFormat(), 05620 m_3DTextureCollisionDetection->GetDataType(), 05621 dataCD 05622 ); 05623 Vector3<T> totalCD( 0, 0, 0 ); 05624 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05625 //std::cout << "sizeCD: " << sizeCD/4 << "\n"; 05626 for ( int i = 0; i < sizeCD; i+=4 ) { 05627 //std::cout << dataCD[i] << ", "; 05628 totalCD[0] += dataCD[i]; 05629 totalCD[1] += dataCD[i+1]; 05630 totalCD[2] += dataCD[i+2]; 05631 } 05632 //if ( totalCD.Length() > 0.0 ) { 05633 // std::cout << "Total CD: " << totalCD << "\n"; 05634 //} 05635 delete [] dataCD; 05636 //--------------------------------------------------------------- 05637 //=============================================================== 05638 05639 //----------------------------------------------------- 05640 // Update simulation state(s) 05641 UpdateCollisionStatus( totalCD.Length() ); 05642 //----------------------------------------------------- 05643 05644 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05645 m_Visualization_RTGenMesh->UpdateCubeTrackingTexture(); 05646 #endif // TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 05647 05648 return totalCD; 05649 //*/ 05650 } 05651 //----------------------------------------------------------------------------- 05652 // END: RemoveConnectionsByCollision ( ... ) 05653 //***************************************************************************** 05654 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05655 05656 05657 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05658 //***************************************************************************** 05659 // BEGIN: UpdateParametersForRemoveConnectionsByCollision 05660 //----------------------------------------------------------------------------- 05661 template <typename T> 05662 void ModelDeformableGLSL<T>::UpdateParametersForRemoveConnectionsByCollision () 05663 { 05664 m_glslProgramObjectForRemovingConnections->BeginGLSL(); 05665 //--------------------------------------------------------------- 05666 //------------------------------------------------- 05667 // Coordinate Offsets 05668 m_glslProgramObjectForRemovingConnections->SetUniform3f( 05669 "offsetCoordsPosition", 05670 offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition 05671 ); 05672 //------------------------------------------------- 05673 m_glslProgramObjectForRemovingConnections->SetUniform1f( "threshold", m_tSimThreshold ); 05674 m_glslProgramObjectForRemovingConnections->SetUniform1f( "elementApproxRadius", m_tElementApproxRadius ); 05675 //--------------------------------------------------------------- 05676 m_glslProgramObjectForRemovingConnections->EndGLSL(); 05677 } 05678 //------------------------------------------------------------------------- 05679 // END: UpdateParametersForRemoveConnectionsByCollision 05680 //************************************************************************* 05681 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05682 05683 05684 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 05685 //***************************************************************************** 05686 // BEGIN: UpdateConnectivity 05687 //----------------------------------------------------------------------------- 05688 template <typename T> 05689 void ModelDeformableGLSL<T>::UpdateConnectivity () 05690 { 05691 //assert( m_glslProgramObjectForUpdateConnectivity ); 05692 if ( !m_glslProgramObjectForUpdateConnectivity ) return; 05693 05694 //UpdateConnectivityParameters(); 05695 //--------------------------------------------------------------- 05696 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05697 m_3DTextureConnectivity->EnableTextureTarget(); 05698 m_glslProgramObjectForUpdateConnectivity->BeginGLSL(); 05699 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05700 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05701 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05702 { 05703 //------------------------------------------------- 05704 // Send Stream of Data (one texture at a time in a for loop) 05705 glMatrixMode( GL_PROJECTION ); 05706 glPushMatrix(); 05707 glLoadIdentity(); 05708 gluOrtho2D( 0, m_3DTextureConnectivity->GetMaxCoordS(), 05709 0, m_3DTextureConnectivity->GetMaxCoordT() ); 05710 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05711 // 05712 glMatrixMode( GL_MODELVIEW ); 05713 glPushMatrix(); 05714 glLoadIdentity(); 05715 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05716 // 05717 glViewport( 0, 0, m_3DTextureConnectivity->GetWidth(), 05718 m_3DTextureConnectivity->GetHeight() ); 05719 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05720 05721 //----------------------------------------------------------- 05722 // Set Uniform Variables for Textures 05723 m_3DTextureConnectivity->EnableTextureTarget(); 05724 // 05725 // Set PositionTexture to Texture Unit 0 05726 glActiveTexture( GL_TEXTURE0 ); 05727 m_3DTexturePosition->BindTexture(0); 05728 m_glslProgramObjectForUpdateConnectivity->SetUniform1i( "PositionTexture", 0 ); 05729 // 05730 // Set ConnectivityTexture to Texture Unit 1 05731 glActiveTexture( GL_TEXTURE1 ); 05732 m_3DTextureConnectivity->BindTexture(0); 05733 m_glslProgramObjectForUpdateConnectivity->SetUniform1i( "ConnectivityTexture", 1 ); 05734 //----------------------------------------------------------- 05735 05736 //------------------------------------------------- 05737 // For each xy plane on the model 05738 T offsetRCoord = offsetCoordRPosition / 2.0; // for z-offset 05739 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 05740 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vConnectivity ); 05741 glFramebufferTexture3DEXT( 05742 GL_FRAMEBUFFER_EXT, // target 05743 GL_COLOR_ATTACHMENT0_EXT, // attached frame 05744 m_3DTextureConnectivity->GetTarget(), // texture target 05745 m_3DTextureConnectivity->GetTexture(1), 05746 0, // level 05747 i // zoffset 05748 ); 05749 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 05750 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05751 //------------------------------------------------- 05752 // Send data stream to GPU 05753 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05754 // 05755 glClearColor( 0, 0, 0, 0 ); 05756 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 05757 glClear( GL_COLOR_BUFFER_BIT ); 05758 // 05759 T coordR = offsetCoordRPosition * i + offsetRCoord; 05760 glPolygonMode( GL_FRONT, GL_FILL ); 05761 glBegin( GL_QUADS ); 05762 glTexCoord3f( 0, 0, coordR ); 05763 glVertex3f ( 0, 0, 0 ); 05764 glTexCoord3f( m_3DTextureConnectivity->GetMaxCoordS(), 0, coordR ); 05765 glVertex3f ( m_3DTextureConnectivity->GetMaxCoordS(), 0, 0 ); 05766 glTexCoord3f( m_3DTextureConnectivity->GetMaxCoordS(), m_3DTextureConnectivity->GetMaxCoordT(), coordR ); 05767 glVertex3f ( m_3DTextureConnectivity->GetMaxCoordS(), m_3DTextureConnectivity->GetMaxCoordT(), 0 ); 05768 glTexCoord3f( 0, m_3DTextureConnectivity->GetMaxCoordT(), coordR ); 05769 glVertex3f ( 0, m_3DTextureConnectivity->GetMaxCoordT(), 0 ); 05770 glEnd(); 05771 } // END: for loop 05772 //------------------------------------------------- 05773 glPopMatrix(); 05774 glMatrixMode( GL_PROJECTION ); 05775 glPopMatrix(); 05776 glMatrixMode( GL_MODELVIEW ); 05777 } 05778 m_3DTexturePosition->DisableTextureTarget(); 05779 m_3DTexturePosition->UnbindTexture(); 05780 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 05781 m_glslProgramObjectForUpdateConnectivity->EndGLSL(); 05782 glPopAttrib(); 05783 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05784 //--------------------------------------------------------------- 05785 // Swap Textures 05786 SwapConnectivityTextures(); 05787 } 05788 //----------------------------------------------------------------------------- 05789 // END: UpdateConnectivity 05790 //***************************************************************************** 05791 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 05792 05793 05794 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05795 //***************************************************************************** 05796 // BEGIN: UpdateConnectivity 05797 //----------------------------------------------------------------------------- 05798 template <typename T> 05799 void ModelDeformableGLSL<T>::UpdateConnectivity () 05800 { 05801 //assert( m_glslProgramObjectForUpdateConnectivity ); 05802 if ( !m_glslProgramObjectForUpdateConnectivity ) return; 05803 05804 //UpdateConnectivityParameters(); 05805 //--------------------------------------------------------------- 05806 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05807 m_3DTextureConnectivity->EnableTextureTarget(); 05808 m_glslProgramObjectForUpdateConnectivity->BeginGLSL(); 05809 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05810 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05811 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05812 { 05813 //------------------------------------------------- 05814 // Send Stream of Data (one texture at a time in a for loop) 05815 glMatrixMode( GL_PROJECTION ); 05816 glPushMatrix(); 05817 glLoadIdentity(); 05818 gluOrtho2D( 0, m_3DTextureConnectivity->GetMaxCoordS(), 05819 0, m_3DTextureConnectivity->GetMaxCoordT() ); 05820 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05821 // 05822 glMatrixMode( GL_MODELVIEW ); 05823 glPushMatrix(); 05824 glLoadIdentity(); 05825 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05826 // 05827 glViewport( 0, 0, m_3DTextureConnectivity->GetWidth(), 05828 m_3DTextureConnectivity->GetHeight() ); 05829 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05830 05831 //----------------------------------------------------------- 05832 // Set Uniform Variables for Textures 05833 m_3DTextureConnectivity->EnableTextureTarget(); 05834 // 05835 // Set PositionTexture to Texture Unit 0 05836 glActiveTexture( GL_TEXTURE0 ); 05837 m_3DTexturePosition->BindTexture(0); 05838 m_glslProgramObjectForUpdateConnectivity->SetUniform1i( "PositionTexture", 0 ); 05839 // 05840 // Set ConnectivityTexture to Texture Unit 1 05841 glActiveTexture( GL_TEXTURE1 ); 05842 m_3DTextureConnectivity->BindTexture(0); 05843 m_glslProgramObjectForUpdateConnectivity->SetUniform1i( "ConnectivityTexture", 1 ); 05844 //----------------------------------------------------------- 05845 05846 //------------------------------------------------- 05847 // For each xy plane on the model 05848 T offsetRCoord = offsetCoordRPosition / 2.0; // for z-offset 05849 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 05850 //------------------------------------------------- 05851 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vConnectivity ); 05852 glFramebufferTexture3DEXT( 05853 GL_FRAMEBUFFER_EXT, // target 05854 GL_COLOR_ATTACHMENT0_EXT, // attached frame 05855 m_3DTextureConnectivity->GetTarget(), // texture target 05856 m_3DTextureConnectivity->GetTexture(1), 05857 0, // level 05858 i // zoffset 05859 ); 05860 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05861 //------------------------------------------------- 05862 glFramebufferTexture3DEXT( 05863 GL_FRAMEBUFFER_EXT, // target 05864 GL_COLOR_ATTACHMENT1_EXT, // attached frame 05865 m_3DTexturePosition->GetTarget(), // texture target 05866 m_3DTexturePosition->GetTexture(1), 05867 0, // level 05868 i // zoffset 05869 ); 05870 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05871 //------------------------------------------------- 05872 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 05873 //glDrawBuffers( 2, MRT ); 05874 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 05875 glDrawBuffers( 2, drawBuffers ); 05876 //------------------------------------------------- 05877 // Send data stream to GPU 05878 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05879 // 05880 glClearColor( 0, 0, 0, 0 ); 05881 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 05882 glClear( GL_COLOR_BUFFER_BIT ); 05883 // 05884 T coordR = offsetCoordRPosition * i + offsetRCoord; 05885 glPolygonMode( GL_FRONT, GL_FILL ); 05886 glBegin( GL_QUADS ); 05887 glTexCoord3f( 0, 0, coordR ); 05888 glVertex3f ( 0, 0, 0 ); 05889 glTexCoord3f( m_3DTextureConnectivity->GetMaxCoordS(), 0, coordR ); 05890 glVertex3f ( m_3DTextureConnectivity->GetMaxCoordS(), 0, 0 ); 05891 glTexCoord3f( m_3DTextureConnectivity->GetMaxCoordS(), m_3DTextureConnectivity->GetMaxCoordT(), coordR ); 05892 glVertex3f ( m_3DTextureConnectivity->GetMaxCoordS(), m_3DTextureConnectivity->GetMaxCoordT(), 0 ); 05893 glTexCoord3f( 0, m_3DTextureConnectivity->GetMaxCoordT(), coordR ); 05894 glVertex3f ( 0, m_3DTextureConnectivity->GetMaxCoordT(), 0 ); 05895 glEnd(); 05896 } // END: for loop 05897 //------------------------------------------------- 05898 glPopMatrix(); 05899 glMatrixMode( GL_PROJECTION ); 05900 glPopMatrix(); 05901 glMatrixMode( GL_MODELVIEW ); 05902 } 05903 m_3DTexturePosition->DisableTextureTarget(); 05904 m_3DTexturePosition->UnbindTexture(); 05905 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 05906 m_glslProgramObjectForUpdateConnectivity->EndGLSL(); 05907 glPopAttrib(); 05908 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 05909 //--------------------------------------------------------------- 05910 // Swap Textures 05911 SwapPositionTextures(); 05912 SwapConnectivityTextures(); 05913 } 05914 //----------------------------------------------------------------------------- 05915 // END: UpdateConnectivity 05916 //***************************************************************************** 05917 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 05918 05919 05920 //***************************************************************************** 05921 // BEGIN: UpdateConnectivityParameters 05922 //----------------------------------------------------------------------------- 05923 template <typename T> 05924 void ModelDeformableGLSL<T>::UpdateParametersForConnectivity () 05925 { 05926 m_glslProgramObjectForUpdateConnectivity->BeginGLSL(); 05927 //=========================================================== 05928 //----------------------------------------------------------- 05929 // Coordinate Offsets 05930 m_glslProgramObjectForUpdateConnectivity->SetUniform3f( 05931 "offsetCoordsPosition", 05932 offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition 05933 ); 05934 //=========================================================== 05935 //----------------------------------------------------------- 05936 // Coordinate Offsets 05937 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 05938 m_glslProgramObjectForUpdateConnectivity->SetUniform3f( 05939 "offsetCoordsConnection", 05940 offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection 05941 ); 05942 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 05943 //----------------------------------------------------------- 05944 m_glslProgramObjectForUpdateConnectivity->EndGLSL(); 05945 } 05946 //----------------------------------------------------------------------------- 05947 // END: UpdateParametersForConnectivity 05948 //***************************************************************************** 05949 05950 05951 //***************************************************************************** 05952 // BEGIN: SimStep (Explicit Euler Integration) 05953 //----------------------------------------------------------------------------- 05954 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 05955 template <typename T> 05956 void ModelDeformableGLSL<T>::SimStep () 05957 { 05958 } 05959 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 05960 //------------------------------------------------------------------------- 05961 // END: SimStep (Explicit Euler Integration) 05962 //************************************************************************* 05963 05964 05965 //***************************************************************************** 05966 // BEGIN: SimStep (Verlet Integration) 05967 //----------------------------------------------------------------------------- 05968 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 05969 template <typename T> 05970 void ModelDeformableGLSL<T>::SimStep () 05971 { 05972 //assert( m_glslProgramObjectForDefModelStep ); 05973 if ( !m_glslProgramObjectForDefModelStep ) return; 05974 05979 /* 05980 if ( GetCollisionStatus() ) { 05981 if ( SPRING_PROP.GetHomeSpringStiffness() == SPRING_PROP.GetStoreHomeSpringStiffness() ) { 05982 SPRING_PROP.SetHomeSpringStiffnessWithoutStoreItsCurrentValue( 0 ); 05983 UpdateParametersForSimStep(); 05984 } 05985 } 05986 else { 05987 if ( SPRING_PROP.GetHomeSpringStiffness() != SPRING_PROP.GetStoreHomeSpringStiffness() ) { 05988 SPRING_PROP.RestoreHomeSpringStiffness(); 05989 UpdateParametersForSimStep(); 05990 } 05991 } 05992 //*/ 05993 //--------------------------------------------------------------- 05994 glPushAttrib( GL_ALL_ATTRIB_BITS ); 05995 m_3DTexturePosition->EnableTextureTarget(); 05996 m_glslProgramObjectForDefModelStep->BeginGLSL(); 05997 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 05998 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 05999 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06000 { 06001 //------------------------------------------------- 06002 // Send Stream of Data (one texture at a time in a for loop) 06003 glMatrixMode( GL_PROJECTION ); 06004 glPushMatrix(); 06005 glLoadIdentity(); 06006 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 06007 0, m_3DTexturePosition->GetMaxCoordT() ); 06008 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06009 // 06010 glMatrixMode( GL_MODELVIEW ); 06011 glPushMatrix(); 06012 glLoadIdentity(); 06013 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06014 // 06015 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 06016 m_3DTexturePosition->GetHeight() ); 06017 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06018 //------------------------------------------------- 06019 // Set Uniform Variables for Textures 06020 m_3DTexturePosition->EnableTextureTarget(); 06021 // 06022 // Set PositionTexture to Texture Unit 0 06023 glActiveTexture( GL_TEXTURE0 ); 06024 m_3DTexturePosition->BindTexture(0); 06025 m_glslProgramObjectForDefModelStep->SetUniform1i( "PositionTexture", 0 ); 06026 // 06027 // Set PrevPositionTexture to Texture Unit 1 06028 glActiveTexture( GL_TEXTURE1 ); 06029 m_3DTexturePosition->BindTexture(2); 06030 m_glslProgramObjectForDefModelStep->SetUniform1i( "PrevPositionTexture", 1 ); 06031 // 06032 // Set ConnectivityTexture to Texture Unit 2 06033 glActiveTexture( GL_TEXTURE2 ); 06034 m_3DTextureConnectivity->BindTexture(0); 06035 m_glslProgramObjectForDefModelStep->SetUniform1i( "ConnectivityTexture", 2 ); 06036 // 06037 // Set HomePositionTexture to Texture Unit 3 06038 glActiveTexture( GL_TEXTURE3 ); 06039 m_3DTextureHomePosition->BindTexture(0); 06040 m_glslProgramObjectForDefModelStep->SetUniform1i( "HomePositionTexture", 3 ); 06041 //------------------------------------------------- 06042 06043 //------------------------------------------------- 06044 // For each xy plane on the model 06045 T offsetRCoord = offsetCoordRPosition / 2.0; // for z-offset 06046 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 06047 // The Simulation is by Verlet integration. 06048 // Hence, no velocity but need previous positions. 06049 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 06050 glFramebufferTexture3DEXT( 06051 GL_FRAMEBUFFER_EXT, // target 06052 GL_COLOR_ATTACHMENT0_EXT, // attached frame 06053 m_3DTexturePosition->GetTarget(), // texture target 06054 m_3DTexturePosition->GetTexture(1), // texture id -- next position 06055 0, // level 06056 i // zoffset 06057 ); 06058 //------------------------------------------------- 06059 06060 // WITHOUT GRADIENT TEXTURE 06061 //=========================================================== 06062 #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 06063 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 06064 #endif // TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 06065 //=========================================================== 06066 06067 // WITH GRADIENT TEXTURE 06068 //=========================================================== 06069 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 06070 glFramebufferTexture3DEXT( 06071 GL_FRAMEBUFFER_EXT, // target 06072 GL_COLOR_ATTACHMENT1_EXT, // attached frame 06073 m_3DTextureGradient->GetTarget(), // texture target 06074 m_3DTextureGradient->GetTexture(0), // texture id 06075 0, // level 06076 i // zoffset 06077 ); 06078 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 06079 //------------------------------------------------- 06080 //GLenum MRT[2] = { GL_FRONT_LEFT, GL_FRONT_LEFT }; 06081 //glDrawBuffers( 2, MRT ); 06082 GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; 06083 glDrawBuffers( 2, drawBuffers ); 06084 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 06085 //=========================================================== 06086 06087 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 06088 //------------------------------------------------- 06089 // Send data stream to GPU 06090 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06091 // 06092 glClearColor( 0, 0, 0, 0 ); 06093 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 06094 glClear( GL_COLOR_BUFFER_BIT ); 06095 // 06096 T coordR = offsetCoordRPosition * i + offsetRCoord; 06097 glPolygonMode( GL_FRONT, GL_FILL ); 06098 glBegin( GL_QUADS ); 06099 glTexCoord3f( 0, 0, coordR ); 06100 glVertex3f ( 0, 0, 0 ); 06101 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 06102 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 06103 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 06104 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 06105 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 06106 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 06107 glEnd(); 06108 } // END: for loop 06109 //------------------------------------------------- 06110 glPopMatrix(); 06111 glMatrixMode( GL_PROJECTION ); 06112 glPopMatrix(); 06113 glMatrixMode( GL_MODELVIEW ); 06114 } 06115 m_3DTexturePosition->DisableTextureTarget(); 06116 m_3DTexturePosition->UnbindTexture(); 06117 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 06118 m_glslProgramObjectForDefModelStep->EndGLSL(); 06119 glPopAttrib(); 06120 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06121 //--------------------------------------------------------------- 06122 // Swap Textures 06123 SwapPositionTextures(); 06124 } 06125 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 06126 //----------------------------------------------------------------------------- 06127 // END: SimStep (Verlet Integration) 06128 //***************************************************************************** 06129 06130 06131 //***************************************************************************** 06132 // BEGIN: UpdateSimStepParameters 06133 //----------------------------------------------------------------------------- 06134 template <typename T> 06135 void ModelDeformableGLSL<T>::UpdateParametersForSimStep () 06136 { 06137 m_glslProgramObjectForDefModelStep->BeginGLSL(); 06138 //--------------------------------------------------------------- 06139 //================================================= 06140 //------------------------------------------------- 06141 // Uniform Variables 06142 //-------------------- 06143 // Resolution (Size) & Dimension (Spacing) 06144 // m_glslProgramObjectForDefModelStep->SetUniform3f( "resolution", m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 06145 //m_glslProgramObjectForDefModelStep->SetUniform3f( "dimension", m_vGridDimension[0], m_vGridDimension[1], m_vGridDimension[2] ); 06146 //-------------------- 06147 // Threshold 06148 m_glslProgramObjectForDefModelStep->SetUniform1f( "threshold", m_tSimThreshold ); 06149 //-------------------- 06150 // Coordinate Offsets 06151 m_glslProgramObjectForDefModelStep->SetUniform3f( 06152 "offsetCoordsPosition", 06153 offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition 06154 ); 06155 06156 //======================================================================== 06157 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 06158 //-------------------- 06159 // Coordinate Offsets 06160 m_glslProgramObjectForDefModelStep->SetUniform3f( 06161 "offsetCoordsConnection", 06162 offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection 06163 ); 06164 //-------------------- 06165 // Spring Properties 06166 //-------------------- 06167 // map to GLSL with 06168 // Texture Coordinates: 06169 // 0,0 -------> 1,0 06170 // | | 06171 // | | 06172 // | | 06173 // 0,1 -------> 1,1 06174 // S [0,1] is X [lowest,highest] 06175 // S [0,1] is Y [lowest,highest] 06176 // So North from CPU is in the last row 06177 // ---------------------------------------------------------------------- 06178 // | FRONT(x) | CENTER(y) | BACK(z) | 06179 // | 00(NW) 01(N) 02(NE) | 09(NW) 10(N) 11(NE) | 18(NW) 19(N) 20(NE) | 06180 // | 03(W) 04(C) 05(E) | 12(W) 13(C) 14(E) | 21(W) 22(C) 23(E) | 06181 // | 06(SW) 07(S) 08(SE) | 15(SW) 16(S) 17(SE) | 24(SW) 25(S) 26(SE) | 06182 // ---------------------------------------------------------------------- 06183 GLfloat RL[27] = { 06184 // 06185 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ], 06186 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ], 06187 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ], 06188 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ], 06189 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ], 06190 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ], 06191 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ], 06192 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ], 06193 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ], 06194 // 06195 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ], 06196 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ], 06197 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ], 06198 SPRING_PROP.REST_LENGTH[ SpringProp::WEST ], 06199 SPRING_PROP.REST_LENGTH[ SpringProp::HOME ], 06200 SPRING_PROP.REST_LENGTH[ SpringProp::EAST ], 06201 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ], 06202 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ], 06203 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ], 06204 // 06205 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ], 06206 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ], 06207 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ], 06208 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ], 06209 SPRING_PROP.REST_LENGTH[ SpringProp::BACK ], 06210 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ], 06211 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ], 06212 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ], 06213 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ] 06214 // 06215 }; 06216 GLfloat Ks[27] = { 06217 // 06218 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ], 06219 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ], 06220 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ], 06221 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ], 06222 SPRING_PROP.STIFFNESS[ SpringProp::FRONT ], 06223 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ], 06224 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ], 06225 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ], 06226 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ], 06227 // 06228 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ], 06229 SPRING_PROP.STIFFNESS[ SpringProp::NORTH ], 06230 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ], 06231 SPRING_PROP.STIFFNESS[ SpringProp::WEST ], 06232 SPRING_PROP.STIFFNESS[ SpringProp::HOME ], 06233 SPRING_PROP.STIFFNESS[ SpringProp::EAST ], 06234 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ], 06235 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ], 06236 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ], 06237 // 06238 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ], 06239 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ], 06240 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ], 06241 SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ], 06242 SPRING_PROP.STIFFNESS[ SpringProp::BACK ], 06243 SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ], 06244 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ], 06245 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ], 06246 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ] 06247 // 06248 }; 06249 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06250 GLfloat Kd[27] = { 06251 // 06252 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_WEST ], 06253 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH ], 06254 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_EAST ], 06255 SPRING_PROP.DAMPER[ SpringProp::FRONT_WEST ], 06256 SPRING_PROP.DAMPER[ SpringProp::FRONT ], 06257 SPRING_PROP.DAMPER[ SpringProp::FRONT_EAST ], 06258 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_WEST ], 06259 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH ], 06260 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_EAST ], 06261 // 06262 SPRING_PROP.DAMPER[ SpringProp::NORTH_WEST ], 06263 SPRING_PROP.DAMPER[ SpringProp::NORTH ], 06264 SPRING_PROP.DAMPER[ SpringProp::NORTH_EAST ], 06265 SPRING_PROP.DAMPER[ SpringProp::WEST ], 06266 SPRING_PROP.DAMPER[ SpringProp::HOME ], 06267 SPRING_PROP.DAMPER[ SpringProp::EAST ], 06268 SPRING_PROP.DAMPER[ SpringProp::SOUTH_WEST ], 06269 SPRING_PROP.DAMPER[ SpringProp::SOUTH ], 06270 SPRING_PROP.DAMPER[ SpringProp::SOUTH_EAST ], 06271 // 06272 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_WEST ], 06273 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH ], 06274 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_EAST ], 06275 SPRING_PROP.DAMPER[ SpringProp::BACK_WEST ], 06276 SPRING_PROP.DAMPER[ SpringProp::BACK ], 06277 SPRING_PROP.DAMPER[ SpringProp::BACK_EAST ], 06278 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_WEST ], 06279 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH ], 06280 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_EAST ] 06281 // 06282 }; 06283 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06284 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 06285 //======================================================================== 06286 //======================================================================== 06287 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 06288 //-------------------- 06289 // Spring Properties 06290 //-------------------- 06291 // map to GLSL with 06292 // Texture Coordinates: 06293 // 0,0 -------> 1,0 06294 // | | 06295 // | | 06296 // | | 06297 // 0,1 -------> 1,1 06298 // S [0,1] is X [lowest,highest] 06299 // S [0,1] is Y [lowest,highest] 06300 // So North from CPU is in the last row 06301 // ---------------------------------------------------------------------- 06302 // x for Front, except the front center 06303 // y for Center, except the center 06304 // z for back, except the back center 06305 // w for front center, center, and back center 06306 // ---------------------------------------------------------------------- 06307 //------------------------------------------------- 06308 // Identification Numbers (for front, center, and back planes) 06309 // from connectionPattern 06310 // -------------------------------- 06311 // | FRONT CENTER BACK | 06312 // | 07 06 05 15 14 13 23 22 21 | 06313 // | 04 25 03 12 26 11 20 24 19 | 06314 // | 02 01 00 10 09 08 18 17 16 | 06315 // -------------------------------- 06316 //------------------------------------------------- 06317 // RGBA Components Represent 06318 // ------------------------------------------- 06319 // 8-bit ubyte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 06320 // ------------------------------------------- 06321 // R --> Front | NW| N | NE| W | E | SW| S | SE| 06322 // G --> Center | NW| N | NE| W | E | SW| S | SE| 06323 // B --> Back | NW| N | NE| W | E | SW| S | SE| 06324 // A --> Misc | | | | | | C | F | B | 06325 //------------------------------------------------- 06326 // ---------------------------------------------------------------------- 06327 // Connectivities 06328 // (The group is arranged in one texel of 4 components.) 06329 // ---------------------------------------------------------------------- 06330 // | FRONT | CENTER | BACK | 06331 // | 07(NW) 06(N) 05(NE) | 15(NW) 14(N) 13(NE) | 23(NW) 22(N) 21(NE) | 06332 // | 04(W) 25(F) 03(E) | 12(W) 26(C) 11(E) | 20(W) 24(B) 19(E) | 06333 // | 02(SW) 01(S) 00(SE) | 10(SW) 09(S) 08(SE) | 18(SW) 17(S) 16(SE) | 06334 // ---------------------------------------------------------------------- 06335 GLfloat RL[27] = { 06336 // R 06337 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ], 06338 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ], 06339 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ], 06340 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ], 06341 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ], 06342 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ], 06343 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ], 06344 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ], 06345 // G 06346 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ], 06347 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ], 06348 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ], 06349 SPRING_PROP.REST_LENGTH[ SpringProp::EAST ], 06350 SPRING_PROP.REST_LENGTH[ SpringProp::WEST ], 06351 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ], 06352 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ], 06353 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ], 06354 // B 06355 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ], 06356 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ], 06357 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ], 06358 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ], 06359 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ], 06360 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ], 06361 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ], 06362 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ], 06363 // A --> Misc | | | | | | C | F | B | 06364 SPRING_PROP.REST_LENGTH[ SpringProp::BACK ], 06365 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ], 06366 SPRING_PROP.REST_LENGTH[ SpringProp::HOME ] // Center 06367 }; 06368 GLfloat Ks[27] = { 06369 // R 06370 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ], 06371 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ], 06372 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ], 06373 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ], 06374 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ], 06375 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ], 06376 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ], 06377 SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ], 06378 // G 06379 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ], 06380 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ], 06381 SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ], 06382 SPRING_PROP.STIFFNESS[ SpringProp::EAST ], 06383 SPRING_PROP.STIFFNESS[ SpringProp::WEST ], 06384 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ], 06385 SPRING_PROP.STIFFNESS[ SpringProp::NORTH ], 06386 SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ], 06387 // B 06388 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ], 06389 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ], 06390 SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ], 06391 SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ], 06392 SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ], 06393 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ], 06394 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ], 06395 SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ], 06396 // A --> Misc | | | | | | C | F | B | 06397 SPRING_PROP.STIFFNESS[ SpringProp::BACK ], 06398 SPRING_PROP.STIFFNESS[ SpringProp::FRONT ], 06399 SPRING_PROP.STIFFNESS[ SpringProp::HOME ] 06400 }; 06401 06402 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06403 GLfloat Kd[27] = { 06404 // R 06405 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_EAST ], 06406 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH ], 06407 SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_WEST ], 06408 SPRING_PROP.DAMPER[ SpringProp::FRONT_EAST ], 06409 SPRING_PROP.DAMPER[ SpringProp::FRONT_WEST ], 06410 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_EAST ], 06411 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH ], 06412 SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_WEST ], 06413 // G 06414 SPRING_PROP.DAMPER[ SpringProp::SOUTH_EAST ], 06415 SPRING_PROP.DAMPER[ SpringProp::SOUTH ], 06416 SPRING_PROP.DAMPER[ SpringProp::SOUTH_WEST ], 06417 SPRING_PROP.DAMPER[ SpringProp::EAST ], 06418 SPRING_PROP.DAMPER[ SpringProp::WEST ], 06419 SPRING_PROP.DAMPER[ SpringProp::NORTH_EAST ], 06420 SPRING_PROP.DAMPER[ SpringProp::NORTH ], 06421 SPRING_PROP.DAMPER[ SpringProp::NORTH_WEST ], 06422 // B 06423 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_EAST ], 06424 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH ], 06425 SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_WEST ], 06426 SPRING_PROP.DAMPER[ SpringProp::BACK_EAST ], 06427 SPRING_PROP.DAMPER[ SpringProp::BACK_WEST ], 06428 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_EAST ], 06429 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH ], 06430 SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_WEST ], 06431 // A --> Misc | | | | | | C | F | B | 06432 SPRING_PROP.DAMPER[ SpringProp::BACK ], 06433 SPRING_PROP.DAMPER[ SpringProp::FRONT ], 06434 SPRING_PROP.DAMPER[ SpringProp::HOME ] 06435 }; 06436 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06437 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 06438 //======================================================================== 06439 m_glslProgramObjectForDefModelStep->SetUniform1fv( "Ks", 27, Ks ); 06440 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06441 m_glslProgramObjectForDefModelStep->SetUniform1fv( "Kd", 27, Kd ); 06442 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06443 m_glslProgramObjectForDefModelStep->SetUniform1fv( "RL", 27, RL ); 06444 m_glslProgramObjectForDefModelStep->SetUniform1f( "mass", m_tElementMass ); 06445 m_glslProgramObjectForDefModelStep->SetUniform1f( "dt", m_tTimeStep ); 06446 //--------------------------------------------------------------- 06447 m_glslProgramObjectForDefModelStep->EndGLSL(); 06448 06449 // DEBUG 06450 //for ( int i = 0; i < 27; ++i ) { 06451 // std::cout << "Stiffness[" << i << "]: " << Ks[i] << "\n"; 06452 //} 06453 } 06454 //----------------------------------------------------------------------------- 06455 // END: UpdateParametersForSimStep 06456 //***************************************************************************** 06457 06458 06459 //***************************************************************************** 06460 // BEGIN: RelaxationConstraint 06461 //----------------------------------------------------------------------------- 06462 template <typename T> 06463 void ModelDeformableGLSL<T>::RelaxationConstraint () 06464 { 06465 //assert( m_glslProgramObjectForRelaxationConstraint ); 06466 if ( !m_glslProgramObjectForRelaxationConstraint ) return; 06467 06468 //UpdateRelaxationConstraintParameters(); 06469 //--------------------------------------------------------------- 06470 glPushAttrib( GL_ALL_ATTRIB_BITS ); 06471 m_3DTexturePosition->EnableTextureTarget(); 06472 m_glslProgramObjectForRelaxationConstraint->BeginGLSL(); 06473 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 06474 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 06475 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06476 { 06477 //------------------------------------------------- 06478 // Send Stream of Data (one texture at a time in a for loop) 06479 glMatrixMode( GL_PROJECTION ); 06480 glPushMatrix(); 06481 glLoadIdentity(); 06482 gluOrtho2D( 0, m_3DTexturePosition->GetMaxCoordS(), 06483 0, m_3DTexturePosition->GetMaxCoordT() ); 06484 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06485 // 06486 glMatrixMode( GL_MODELVIEW ); 06487 glPushMatrix(); 06488 glLoadIdentity(); 06489 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06490 // 06491 glViewport( 0, 0, m_3DTexturePosition->GetWidth(), 06492 m_3DTexturePosition->GetHeight() ); 06493 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06494 //----------------------------------------------------------- 06495 // Set Uniform Variables for Textures 06496 m_3DTexturePosition->EnableTextureTarget(); 06497 // 06498 // Set PositionTexture to Texture Unit 0 06499 glActiveTexture( GL_TEXTURE0 ); 06500 m_3DTexturePosition->BindTexture(0); 06501 m_glslProgramObjectForRelaxationConstraint->SetUniform1i( "PositionTexture", 0 ); 06502 // 06503 // Set PrevPositionTexture to Texture Unit 1 06504 //glActiveTexture( GL_TEXTURE1 ); 06505 //m_3DTexturePosition->BindTexture(2); 06506 //m_glslProgramObjectForRelaxationConstraint->SetUniform1i( "PrevPositionTexture", 1 ); 06507 // 06508 // Set ConnectivityTexture to Texture Unit 1 06509 glActiveTexture( GL_TEXTURE1 ); 06510 m_3DTextureConnectivity->BindTexture(0); 06511 m_glslProgramObjectForRelaxationConstraint->SetUniform1i( "ConnectivityTexture", 1 ); 06512 //----------------------------------------------------------- 06513 06514 //------------------------------------------------- 06515 // For each xy plane on the model 06516 T offsetRCoord = offsetCoordRPosition / 2.0; // for z-offset 06517 for ( int i = 0; i < m_vGridResolution[2]; ++i ) { 06518 // The Simulation is by Verlet integration. 06519 // Hence, no velocity but need previous positions. 06520 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_vPosition ); 06521 glFramebufferTexture3DEXT( 06522 GL_FRAMEBUFFER_EXT, // target 06523 GL_COLOR_ATTACHMENT0_EXT, // attached frame 06524 m_3DTexturePosition->GetTarget(), // texture target 06525 m_3DTexturePosition->GetTexture(1), 06526 0, // level 06527 i // zoffset 06528 ); 06529 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT ); 06530 TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS(); 06531 //------------------------------------------------- 06532 // Send data stream to GPU 06533 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06534 // 06535 glClearColor( 0, 0, 0, 0 ); 06536 //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 06537 glClear( GL_COLOR_BUFFER_BIT ); 06538 // 06539 T coordR = offsetCoordRPosition * i + offsetRCoord; 06540 glPolygonMode( GL_FRONT, GL_FILL ); 06541 glBegin( GL_QUADS ); 06542 glTexCoord3f( 0, 0, coordR ); 06543 glVertex3f ( 0, 0, 0 ); 06544 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), 0, coordR ); 06545 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), 0, 0 ); 06546 glTexCoord3f( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), coordR ); 06547 glVertex3f ( m_3DTexturePosition->GetMaxCoordS(), m_3DTexturePosition->GetMaxCoordT(), 0 ); 06548 glTexCoord3f( 0, m_3DTexturePosition->GetMaxCoordT(), coordR ); 06549 glVertex3f ( 0, m_3DTexturePosition->GetMaxCoordT(), 0 ); 06550 glEnd(); 06551 } // END: for loop 06552 //------------------------------------------------- 06553 glPopMatrix(); 06554 glMatrixMode( GL_PROJECTION ); 06555 glPopMatrix(); 06556 glMatrixMode( GL_MODELVIEW ); 06557 } 06558 m_3DTexturePosition->DisableTextureTarget(); 06559 m_3DTexturePosition->UnbindTexture(); 06560 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 06561 m_glslProgramObjectForRelaxationConstraint->EndGLSL(); 06562 glPopAttrib(); 06563 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06564 //--------------------------------------------------------------- 06565 // Swap Textures 06566 SwapPositionTextures(); 06567 //*/ 06568 } 06569 //------------------------------------------------------------------------- 06570 // END: RelaxationConstraint 06571 //************************************************************************* 06572 06573 06574 //***************************************************************************** 06575 // BEGIN: UpdateRelaxationConstraintParameters 06576 //----------------------------------------------------------------------------- 06577 template <typename T> 06578 void ModelDeformableGLSL<T>::UpdateParametersForRelaxationConstraint () 06579 { 06580 m_glslProgramObjectForRelaxationConstraint->BeginGLSL(); 06581 //--------------------------------------------------------------- 06582 //================================================= 06583 //------------------------------------------------- 06584 // Uniform Variables 06585 //-------------------- 06586 // Resolution (Size) & Dimension (Spacing) 06587 // m_glslProgramObjectForRelaxationConstraint->SetUniform3f( "resolution", m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 06588 //m_glslProgramObjectForRelaxationConstraint->SetUniform3f( "dimension", m_vGridDimension[0], m_vGridDimension[1], m_vGridDimension[2] ); 06589 //-------------------- 06590 // Threshold 06591 m_glslProgramObjectForRelaxationConstraint->SetUniform1f( "threshold", m_tSimThreshold ); 06592 //-------------------- 06593 // Coordinate Offsets 06594 m_glslProgramObjectForRelaxationConstraint->SetUniform3f( 06595 "offsetCoordsPosition", 06596 offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition 06597 ); 06598 06599 //======================================================================== 06600 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 06601 //-------------------- 06602 // Coordinate Offsets 06603 m_glslProgramObjectForRelaxationConstraint->SetUniform3f( 06604 "offsetCoordsConnection", 06605 offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection 06606 ); 06607 //-------------------- 06608 // Spring Properties 06609 //-------------------- 06610 // map to GLSL with 06611 // Texture Coordinates: 06612 // 0,0 -------> 1,0 06613 // | | 06614 // | | 06615 // | | 06616 // 0,1 -------> 1,1 06617 // S [0,1] is X [lowest,highest] 06618 // S [0,1] is Y [lowest,highest] 06619 // So North from CPU is in the last row 06620 // ---------------------------------------------------------------------- 06621 // | FRONT(x) | CENTER(y) | BACK(z) | 06622 // | 00(NW) 01(N) 02(NE) | 09(NW) 10(N) 11(NE) | 18(NW) 19(N) 20(NE) | 06623 // | 03(W) 04(C) 05(E) | 12(W) 13(C) 14(E) | 21(W) 22(C) 23(E) | 06624 // | 06(SW) 07(S) 08(SE) | 15(SW) 16(S) 17(SE) | 24(SW) 25(S) 26(SE) | 06625 // ---------------------------------------------------------------------- 06626 GLfloat RL[27] = { 06627 // 06628 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ], 06629 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ], 06630 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ], 06631 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ], 06632 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ], 06633 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ], 06634 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ], 06635 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ], 06636 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ], 06637 // 06638 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ], 06639 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ], 06640 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ], 06641 SPRING_PROP.REST_LENGTH[ SpringProp::WEST ], 06642 SPRING_PROP.REST_LENGTH[ SpringProp::HOME ], 06643 SPRING_PROP.REST_LENGTH[ SpringProp::EAST ], 06644 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ], 06645 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ], 06646 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ], 06647 // 06648 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ], 06649 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ], 06650 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ], 06651 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ], 06652 SPRING_PROP.REST_LENGTH[ SpringProp::BACK ], 06653 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ], 06654 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ], 06655 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ], 06656 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ] 06657 // 06658 }; 06659 //GLfloat Ks[27] = { 06660 // // 06661 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ], 06662 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ], 06663 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ], 06664 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ], 06665 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT ], 06666 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ], 06667 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ], 06668 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ], 06669 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ], 06670 // // 06671 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ], 06672 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH ], 06673 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ], 06674 // SPRING_PROP.STIFFNESS[ SpringProp::WEST ], 06675 // SPRING_PROP.STIFFNESS[ SpringProp::HOME ], 06676 // SPRING_PROP.STIFFNESS[ SpringProp::EAST ], 06677 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ], 06678 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ], 06679 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ], 06680 // // 06681 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ], 06682 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ], 06683 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ], 06684 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ], 06685 // SPRING_PROP.STIFFNESS[ SpringProp::BACK ], 06686 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ], 06687 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ], 06688 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ], 06689 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ] 06690 // // 06691 //}; 06692 //GLfloat Kd[27] = { 06693 // // 06694 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_WEST ], 06695 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH ], 06696 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_EAST ], 06697 // SPRING_PROP.DAMPER[ SpringProp::FRONT_WEST ], 06698 // SPRING_PROP.DAMPER[ SpringProp::FRONT ], 06699 // SPRING_PROP.DAMPER[ SpringProp::FRONT_EAST ], 06700 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_WEST ], 06701 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH ], 06702 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_EAST ], 06703 // // 06704 // SPRING_PROP.DAMPER[ SpringProp::NORTH_WEST ], 06705 // SPRING_PROP.DAMPER[ SpringProp::NORTH ], 06706 // SPRING_PROP.DAMPER[ SpringProp::NORTH_EAST ], 06707 // SPRING_PROP.DAMPER[ SpringProp::WEST ], 06708 // SPRING_PROP.DAMPER[ SpringProp::HOME ], 06709 // SPRING_PROP.DAMPER[ SpringProp::EAST ], 06710 // SPRING_PROP.DAMPER[ SpringProp::SOUTH_WEST ], 06711 // SPRING_PROP.DAMPER[ SpringProp::SOUTH ], 06712 // SPRING_PROP.DAMPER[ SpringProp::SOUTH_EAST ], 06713 // // 06714 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_WEST ], 06715 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH ], 06716 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_EAST ], 06717 // SPRING_PROP.DAMPER[ SpringProp::BACK_WEST ], 06718 // SPRING_PROP.DAMPER[ SpringProp::BACK ], 06719 // SPRING_PROP.DAMPER[ SpringProp::BACK_EAST ], 06720 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_WEST ], 06721 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH ], 06722 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_EAST ] 06723 // // 06724 //}; 06725 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 06726 //======================================================================== 06727 //======================================================================== 06728 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 06729 //-------------------- 06730 // Spring Properties 06731 //-------------------- 06732 // map to GLSL with 06733 // Texture Coordinates: 06734 // 0,0 -------> 1,0 06735 // | | 06736 // | | 06737 // | | 06738 // 0,1 -------> 1,1 06739 // S [0,1] is X [lowest,highest] 06740 // S [0,1] is Y [lowest,highest] 06741 // So North from CPU is in the last row 06742 // ---------------------------------------------------------------------- 06743 // x for Front, except the front center 06744 // y for Center, except the center 06745 // z for back, except the back center 06746 // w for front center, center, and back center 06747 // ---------------------------------------------------------------------- 06748 //------------------------------------------------- 06749 // Identification Numbers (for front, center, and back planes) 06750 // from connectionPattern 06751 // -------------------------------- 06752 // | FRONT CENTER BACK | 06753 // | 07 06 05 15 14 13 23 22 21 | 06754 // | 04 25 03 12 26 11 20 24 19 | 06755 // | 02 01 00 10 09 08 18 17 16 | 06756 // -------------------------------- 06757 //------------------------------------------------- 06758 // RGBA Components Represent 06759 // ------------------------------------------- 06760 // 8-bit ubyte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 06761 // ------------------------------------------- 06762 // R --> Front | NW| N | NE| W | E | SW| S | SE| 06763 // G --> Center | NW| N | NE| W | E | SW| S | SE| 06764 // B --> Back | NW| N | NE| W | E | SW| S | SE| 06765 // A --> Misc | | | | | | C | F | B | 06766 //------------------------------------------------- 06767 // ---------------------------------------------------------------------- 06768 // Connectivities 06769 // (The group is arranged in one texel of 4 components.) 06770 // ---------------------------------------------------------------------- 06771 // | FRONT | CENTER | BACK | 06772 // | 07(NW) 06(N) 05(NE) | 15(NW) 14(N) 13(NE) | 23(NW) 22(N) 21(NE) | 06773 // | 04(W) 25(F) 03(E) | 12(W) 26(C) 11(E) | 20(W) 24(B) 19(E) | 06774 // | 02(SW) 01(S) 00(SE) | 10(SW) 09(S) 08(SE) | 18(SW) 17(S) 16(SE) | 06775 // ---------------------------------------------------------------------- 06776 GLfloat RL[27] = { 06777 // R 06778 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_EAST ], 06779 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH ], 06780 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_SOUTH_WEST ], 06781 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_EAST ], 06782 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_WEST ], 06783 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_EAST ], 06784 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH ], 06785 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT_NORTH_WEST ], 06786 // G 06787 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_EAST ], 06788 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH ], 06789 SPRING_PROP.REST_LENGTH[ SpringProp::SOUTH_WEST ], 06790 SPRING_PROP.REST_LENGTH[ SpringProp::EAST ], 06791 SPRING_PROP.REST_LENGTH[ SpringProp::WEST ], 06792 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_EAST ], 06793 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH ], 06794 SPRING_PROP.REST_LENGTH[ SpringProp::NORTH_WEST ], 06795 // B 06796 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_EAST ], 06797 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH ], 06798 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_SOUTH_WEST ], 06799 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_EAST ], 06800 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_WEST ], 06801 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_EAST ], 06802 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH ], 06803 SPRING_PROP.REST_LENGTH[ SpringProp::BACK_NORTH_WEST ], 06804 // A --> Misc | | | | | | C | F | B | 06805 SPRING_PROP.REST_LENGTH[ SpringProp::BACK ], 06806 SPRING_PROP.REST_LENGTH[ SpringProp::FRONT ], 06807 SPRING_PROP.REST_LENGTH[ SpringProp::HOME ] // Center 06808 }; 06809 //GLfloat Ks[27] = { 06810 // // R 06811 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_EAST ], 06812 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH ], 06813 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_SOUTH_WEST ], 06814 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_EAST ], 06815 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_WEST ], 06816 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_EAST ], 06817 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH ], 06818 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT_NORTH_WEST ], 06819 // // G 06820 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_EAST ], 06821 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH ], 06822 // SPRING_PROP.STIFFNESS[ SpringProp::SOUTH_WEST ], 06823 // SPRING_PROP.STIFFNESS[ SpringProp::EAST ], 06824 // SPRING_PROP.STIFFNESS[ SpringProp::WEST ], 06825 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH_EAST ], 06826 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH ], 06827 // SPRING_PROP.STIFFNESS[ SpringProp::NORTH_WEST ], 06828 // // B 06829 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_EAST ], 06830 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH ], 06831 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_SOUTH_WEST ], 06832 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_EAST ], 06833 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_WEST ], 06834 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_EAST ], 06835 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH ], 06836 // SPRING_PROP.STIFFNESS[ SpringProp::BACK_NORTH_WEST ], 06837 // // A --> Misc | | | | | | C | F | B | 06838 // SPRING_PROP.STIFFNESS[ SpringProp::BACK ], 06839 // SPRING_PROP.STIFFNESS[ SpringProp::FRONT ], 06840 // SPRING_PROP.STIFFNESS[ SpringProp::HOME ] 06841 //}; 06842 06843 //#ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 06844 //GLfloat Kd[27] = { 06845 // // R 06846 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_EAST ], 06847 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH ], 06848 // SPRING_PROP.DAMPER[ SpringProp::FRONT_SOUTH_WEST ], 06849 // SPRING_PROP.DAMPER[ SpringProp::FRONT_EAST ], 06850 // SPRING_PROP.DAMPER[ SpringProp::FRONT_WEST ], 06851 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_EAST ], 06852 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH ], 06853 // SPRING_PROP.DAMPER[ SpringProp::FRONT_NORTH_WEST ], 06854 // // G 06855 // SPRING_PROP.DAMPER[ SpringProp::SOUTH_EAST ], 06856 // SPRING_PROP.DAMPER[ SpringProp::SOUTH ], 06857 // SPRING_PROP.DAMPER[ SpringProp::SOUTH_WEST ], 06858 // SPRING_PROP.DAMPER[ SpringProp::EAST ], 06859 // SPRING_PROP.DAMPER[ SpringProp::WEST ], 06860 // SPRING_PROP.DAMPER[ SpringProp::NORTH_EAST ], 06861 // SPRING_PROP.DAMPER[ SpringProp::NORTH ], 06862 // SPRING_PROP.DAMPER[ SpringProp::NORTH_WEST ], 06863 // // B 06864 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_EAST ], 06865 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH ], 06866 // SPRING_PROP.DAMPER[ SpringProp::BACK_SOUTH_WEST ], 06867 // SPRING_PROP.DAMPER[ SpringProp::BACK_EAST ], 06868 // SPRING_PROP.DAMPER[ SpringProp::BACK_WEST ], 06869 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_EAST ], 06870 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH ], 06871 // SPRING_PROP.DAMPER[ SpringProp::BACK_NORTH_WEST ], 06872 // // A --> Misc | | | | | | C | F | B | 06873 // SPRING_PROP.DAMPER[ SpringProp::BACK ], 06874 // SPRING_PROP.DAMPER[ SpringProp::FRONT ], 06875 // SPRING_PROP.DAMPER[ SpringProp::HOME ] 06876 //}; 06877 #endif // #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 06878 //======================================================================== 06879 m_glslProgramObjectForRelaxationConstraint->SetUniform1fv( "RL", 27, RL ); 06880 m_glslProgramObjectForRelaxationConstraint->SetUniform1f( "MaxRelaxConst", m_tMaxRelaxation ); 06881 m_glslProgramObjectForRelaxationConstraint->SetUniform1f( "MinRelaxConst", m_tMinRelaxation ); 06882 //------------------------------------------------- 06883 //--------------------------------------------------------------- 06884 m_glslProgramObjectForRelaxationConstraint->EndGLSL(); 06885 } 06886 //------------------------------------------------------------------------- 06887 // END: UpdateParametersForRelaxationConstraint 06888 //************************************************************************* 06889 06890 06891 //***************************************************************************** 06892 // BEGIN: SetupA3DTexture 06893 //----------------------------------------------------------------------------- 06894 template <typename T> 06895 Texture * ModelDeformableGLSL<T>::SetupA3DTexture ( 06896 GLenum target, 06897 GLint level, 06898 GLint internalFormat, 06899 GLsizei width, 06900 GLsizei height, 06901 GLsizei depth, 06902 GLint border, 06903 GLenum pixelFormat, 06904 GLenum dataType, 06905 //----------------------------- 06906 GLvoid * texels, // texel data 06907 //----------------------------- 06908 unsigned short numOfTextures, // number of 2D textures 06909 //----------------------------- 06910 GLint magFilter, 06911 GLint minFilter, 06912 GLint wrapS, 06913 GLint wrapT, 06914 GLint wrapR 06915 ) 06916 { 06917 //std::cout << "START SetupA3DTexture()" << std::endl; 06918 06919 Texture * newTexture = new Texture( 06920 target, level, internalFormat, 06921 width, height, depth, 06922 border, pixelFormat, dataType, 06923 NULL, 06924 numOfTextures, 06925 magFilter, minFilter, 06926 wrapS, wrapT, wrapR 06927 ); 06928 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 06929 //--------------------------------------------------------------- 06930 06931 //std::cout << "New Texture: " << *newTexture << std::endl; 06932 //std::cout << "\tAFTER new Texture(...)" << std::endl; 06933 06934 //----------------------------------------------------- 06935 // Current Collision Info (index [0]) 06936 06937 //=========================================================================================== 06938 // DEBUG 06939 /* 06940 std::cout << "\tnumOfTextures: " << numOfTextures << std::endl; 06941 std::cout << "\tnewTexture->GetWidth()" << newTexture->GetWidth() << std::endl; 06942 std::cout << "\tnewTexture->GetHeight()" << newTexture->GetHeight() << std::endl; 06943 std::cout << "\tnewTexture->GetDepth()" << newTexture->GetDepth() << std::endl; 06944 06945 int m = 0; 06946 06947 GLfloat * vertexData = (GLfloat *) texels; 06948 for ( int i = 0; i < newTexture->GetWidth(); ++i ) { 06949 for ( int j = 0; j < newTexture->GetHeight(); ++j ) { 06950 for ( int k = 0; k < newTexture->GetDepth(); ++k ) { 06951 std::cout << "vertexData(" << i << "," << j << "," << k << "): "; 06952 std::cout 06953 << vertexData[m ] << "\t" 06954 << vertexData[m+1] << "\t" 06955 << vertexData[m+2] << "\t" 06956 << vertexData[m+3] << "\n"; 06957 m += 4; 06958 } 06959 } 06960 } 06961 //*/ 06962 //=========================================================================================== 06963 06964 for ( int i = 0; i < numOfTextures; ++i ) { 06965 GLuint texName = newTexture->GetTexture( i ); 06966 06967 //std::cout << "texName: " << texName << std::endl; 06968 06969 //glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); 06970 06971 //glEnable( GL_TEXTURE_3D ); 06972 06973 glBindTexture( target, texName ); 06974 //glBindTexture( newTexture->GetTarget(), texName ); 06975 06976 //glTexParameterf( target, GL_TEXTURE_MAG_FILTER, magFilter ); 06977 //glTexParameterf( target, GL_TEXTURE_MIN_FILTER, minFilter ); 06978 //glTexParameterf( target, GL_TEXTURE_WRAP_S, wrapS ); 06979 //glTexParameterf( target, GL_TEXTURE_WRAP_T, wrapT ); 06980 //glTexParameterf( target, GL_TEXTURE_WRAP_R, wrapR ); 06981 06982 //std::cout << "After bind texture" << std::endl; 06983 06984 glTexImage3D( 06985 newTexture->GetTarget(), 06986 newTexture->GetLevel(), 06987 newTexture->GetInternalFormat(), 06988 newTexture->GetWidth(), 06989 newTexture->GetHeight(), 06990 newTexture->GetDepth(), 06991 newTexture->GetBorder(), 06992 newTexture->GetPixelFormat(), 06993 newTexture->GetDataType(), 06994 texels 06995 ); 06996 06997 //std::cout << "Before CHECK_GL_ERROR" << std::endl; 06998 06999 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 07000 07001 //std::cout << "After CHECK_GL_ERROR" << std::endl; 07002 07003 //std::cout << "Before glTexSubImage3D" << std::endl; 07004 07005 glTexSubImage3D( 07006 newTexture->GetTarget(), 07007 newTexture->GetLevel(), 07008 0, 0, 0, // x,y,z offset 07009 newTexture->GetWidth(), 07010 newTexture->GetHeight(), 07011 newTexture->GetDepth(), 07012 newTexture->GetPixelFormat(), 07013 newTexture->GetDataType(), 07014 texels 07015 ); 07016 //std::cout << "Before CHECK_GL_ERROR" << std::endl; 07017 07018 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 07019 07020 //std::cout << "After CHECK_GL_ERROR" << std::endl; 07021 } 07022 //--------------------------------------------------------------- 07023 07024 //std::cout << "END SetupA3DTexture()" << std::endl; 07025 07026 return newTexture; 07027 } 07028 //------------------------------------------------------------------------- 07029 // END: SetupA3DTexture 07030 //************************************************************************* 07031 07032 07033 //***************************************************************************** 07034 // BEGIN: Setup3DTexturesForSimulation 07035 /* 07036 I/P: resolution of xyz 07037 I/P: ptElementPosition (xyz of all positions) 07038 I/P: pcElementFlag (flag of all positions) 07039 I/P (option): ptElementVertexInterpolation (in range of [0,1]) 07040 If NULL, a global default value (0.5) is used. 07041 07042 This fn setups: 07043 1 Gradient Texture 07044 1 Home Position Texture 07045 3 Position Textures (previous, current, and next) 07046 1 Ellipsoid Influence Texture (for ptElementVertexInterpolation) 07047 1 Collision Detection Texture 07048 1 Offset Texture 07049 Call Setup3DTextureForConnectivities(...) Fn (see the cpp file for 3X3 or One texture) 07050 //*/ 07051 //----------------------------------------------------------------------------- 07052 template <typename T> 07053 bool ModelDeformableGLSL<T>::Setup3DTexturesForSimulation ( 07054 int resolutionX, int resolutionY, int resolutionZ, 07055 T **** ptElementPosition, 07056 enum GridGenerator<T>::VertexFlag *** pcElementFlag, 07057 T **** ptElementVertexInterpolation, 07058 T tPressureValue 07059 ) 07060 { 07061 //std::cout << "START Setup3DTexturesForSimulation()" << std::endl; 07062 07063 //--------------------------------------------------------------- 07064 // Default Values of Textures for Positions 07065 GLenum target = GL_TEXTURE_3D; 07066 GLint level = 0; 07067 GLint internalFormat = GL_RGBA32F_ARB; 07068 GLint border = 0; 07069 //GLenum pixelFormat = GL_RGB; 07070 GLenum pixelFormat = GL_RGBA; 07071 GLenum dataType = GL_FLOAT; 07072 //----------------------- 07073 unsigned char internalFormatNumOfComponents = 4; 07074 unsigned char pixelFormatNumOfComponents = 4; 07075 if ( internalFormat == GL_RGB32F_ARB ) { 07076 internalFormatNumOfComponents = 3; 07077 } 07078 else if ( internalFormat == GL_RGBA32F_ARB ) { 07079 internalFormatNumOfComponents = 4; 07080 } 07081 else if ( internalFormat == GL_RGB ) { 07082 internalFormatNumOfComponents = 3; 07083 } 07084 else if ( internalFormat == GL_RGBA ) { 07085 internalFormatNumOfComponents = 4; 07086 } 07087 //----------------------- 07088 if ( pixelFormat == GL_RGB ) { 07089 pixelFormatNumOfComponents = 3; 07090 } 07091 else if ( pixelFormat == GL_RGBA ) { 07092 pixelFormatNumOfComponents = 4; 07093 } 07094 //--------------------------------------- 07095 unsigned char numberOfTextures = 1; 07096 //--------------------------------------------------------------- 07097 07098 //std::cout << "\tSTART GPU Setup" << std::endl; 07099 07100 //=============================================================== 07101 // GPU 07102 //--------------------------------------------------------------- 07103 int iMemorySizeForDataAsColor; 07104 int iMemorySizeForTotalElements; 07105 //--------------------------------------------------------------- 07106 // Position is XYZ only 07107 if ( 3 == internalFormatNumOfComponents ) { 07108 int iTotalElements = resolutionX * resolutionY * resolutionZ; 07109 iMemorySizeForDataAsColor = iTotalElements * 4; 07110 iMemorySizeForTotalElements = iTotalElements * 3; 07111 GLfloat * origObjectDataAsColor = new GLfloat[ iMemorySizeForDataAsColor ]; // RGBA in 1D Array 07112 GLfloat * vertexData = new GLfloat[ iMemorySizeForTotalElements ]; // XYZ in 1D Array 07113 int n = 0; // RGBA Counter 07114 int m = 0; // XYZ Counter 07115 //------------------------------------------------- 07116 // Data from pGridGenerator is arrenged in x, y, and z order. 07117 // To switch it to z, y, and x order for ordering planes in z-direction. 07118 for ( int k = 0; k < resolutionZ; ++k ) { 07119 for ( int j = 0; j < resolutionY; ++j ) { 07120 for ( int i = 0; i < resolutionX; ++i ) { 07121 vertexData[m ] = ptElementPosition[i][j][k][0]; 07122 vertexData[m+1] = ptElementPosition[i][j][k][1]; 07123 vertexData[m+2] = ptElementPosition[i][j][k][2]; 07124 //--------------------------- 07125 if ( pcElementFlag[i][j][k] >= GridGenerator<T>::INSIDE_MODEL ) { 07126 //vertexData[m+3] = IC_Thresholds::INSIDE_MODEL; 07127 //------------- 07128 origObjectDataAsColor[n ] = 1; 07129 origObjectDataAsColor[n+1] = 1; 07130 origObjectDataAsColor[n+2] = 0; 07131 //------------- 07132 origObjectDataAsColor[n+3] = IC_Thresholds::INSIDE_MODEL; 07133 } 07134 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_INSIDE_BOUNDARY ) { 07135 //vertexData[m+3] = IC_Thresholds::RIGHT_INSIDE_BOUNDARY; 07136 //------------- 07137 origObjectDataAsColor[n ] = 0; 07138 origObjectDataAsColor[n+1] = 1; 07139 origObjectDataAsColor[n+2] = 0; 07140 //------------- 07141 origObjectDataAsColor[n+3] = IC_Thresholds::RIGHT_INSIDE_BOUNDARY; 07142 } 07143 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::ON_BOUNDARY ) { 07144 //vertexData[m+3] = IC_Thresholds::ON_BOUNDARY; 07145 //------------- 07146 origObjectDataAsColor[n ] = 1; 07147 origObjectDataAsColor[n+1] = 1; 07148 origObjectDataAsColor[n+2] = 1; 07149 //------------- 07150 origObjectDataAsColor[n+3] = IC_Thresholds::ON_BOUNDARY; 07151 } 07152 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_OUTSIDE_BOUNDARY ) { 07153 //vertexData[m+3] = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY; 07154 //------------- 07155 origObjectDataAsColor[n ] = 1; 07156 origObjectDataAsColor[n+1] = 0; 07157 origObjectDataAsColor[n+2] = 0; 07158 //------------- 07159 origObjectDataAsColor[n+3] = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY; 07160 } 07161 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::OUTSIDE_MODEL ) { 07162 //vertexData[m+3] = IC_Thresholds::OUTSIDE_MODEL; 07163 //------------- 07164 origObjectDataAsColor[n ] = 0; 07165 origObjectDataAsColor[n+1] = 0; 07166 origObjectDataAsColor[n+2] = 0; 07167 //------------- 07168 origObjectDataAsColor[n+3] = IC_Thresholds::OUTSIDE_MODEL; 07169 } 07170 else { 07171 //vertexData[m+3] = IC_Thresholds::UNSET; 07172 //------------- 07173 origObjectDataAsColor[n ] = 0; 07174 origObjectDataAsColor[n+1] = 0; 07175 origObjectDataAsColor[n+2] = 0; 07176 //------------- 07177 origObjectDataAsColor[n+3] = IC_Thresholds::UNSET; 07178 } 07179 n += 4; 07180 m += 3; 07181 } 07182 } 07183 } 07184 m_glpTexelForObjectOrigData = origObjectDataAsColor; 07185 m_glpTexelForVertexPos = vertexData; 07186 } 07187 //--------------------------------------------------------------- 07188 // Position XYZ with Flag indicating void or occupied 07189 else if ( 4 == internalFormatNumOfComponents ) { 07190 int iTotalElements = resolutionX * resolutionY * resolutionZ; 07191 iMemorySizeForTotalElements = iTotalElements * 4; 07192 GLfloat * origObjectDataAsColor = new GLfloat[ iMemorySizeForTotalElements ]; // RGBA in 1D Array 07193 GLfloat * vertexData = new GLfloat[ iMemorySizeForTotalElements ]; // XYZ & Flag in 1D Array 07194 int n = 0; // RGBA Counter 07195 int m = 0; // XYZ & Flag Counter 07196 //------------------------------------------------- 07197 // Data from pGridGenerator is arrenged in x, y, and z order. 07198 // To switch it to z, y, and x order for ordering planes in z-direction. 07199 int iX, iY = 1, iZ; 07200 //if ( m_iGPUInfo == 1 ) // ATI 07201 //{ 07202 // // BGR 07203 // iX = 2; 07204 // iZ = 0; 07205 //} 07206 //else // NVIDIA 07207 { 07208 // RGB 07209 iX = 0; 07210 iZ = 2; 07211 } 07212 //--------------------------------------- 07213 for ( int k = 0; k < resolutionZ; ++k ) { 07214 for ( int j = 0; j < resolutionY; ++j ) { 07215 for ( int i = 0; i < resolutionX; ++i ) { 07216 vertexData[m ] = ptElementPosition[i][j][k][iX]; 07217 vertexData[m+1] = ptElementPosition[i][j][k][iY]; 07218 vertexData[m+2] = ptElementPosition[i][j][k][iZ]; 07219 //--------------------------- 07220 if ( pcElementFlag[i][j][k] >= GridGenerator<T>::INSIDE_MODEL ) { 07221 vertexData[m+3] = IC_Thresholds::INSIDE_MODEL; 07222 //------------- 07223 origObjectDataAsColor[n ] = 1; 07224 origObjectDataAsColor[n+1] = 1; 07225 origObjectDataAsColor[n+2] = 0; 07226 //------------- 07227 origObjectDataAsColor[n+3] = IC_Thresholds::INSIDE_MODEL; 07228 } 07229 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_INSIDE_BOUNDARY ) { 07230 vertexData[m+3] = IC_Thresholds::RIGHT_INSIDE_BOUNDARY; 07231 //------------- 07232 origObjectDataAsColor[n ] = 0; 07233 origObjectDataAsColor[n+1] = 1; 07234 origObjectDataAsColor[n+2] = 0; 07235 //------------- 07236 origObjectDataAsColor[n+3] = IC_Thresholds::RIGHT_INSIDE_BOUNDARY; 07237 } 07238 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::ON_BOUNDARY ) { 07239 vertexData[m+3] = IC_Thresholds::ON_BOUNDARY; 07240 //------------- 07241 origObjectDataAsColor[n ] = 1; 07242 origObjectDataAsColor[n+1] = 1; 07243 origObjectDataAsColor[n+2] = 1; 07244 //------------- 07245 origObjectDataAsColor[n+3] = IC_Thresholds::ON_BOUNDARY; 07246 } 07247 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_OUTSIDE_BOUNDARY ) { 07248 vertexData[m+3] = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY; 07249 07250 // DEBUG 07251 //vertexData[m+3] = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY + IC_Thresholds::FIXED_THRESHOLD_ADD; 07252 07253 //------------- 07254 origObjectDataAsColor[n ] = 1; 07255 origObjectDataAsColor[n+1] = 0; 07256 origObjectDataAsColor[n+2] = 0; 07257 //------------- 07258 origObjectDataAsColor[n+3] = IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY; 07259 07260 // Make this point move to expand the def model 07261 // Expansion is based on a sphere 07262 vertexData[m ] = ptElementPosition[i][j][k][0] * tPressureValue;// * DEBUG_PressureValue; 07263 vertexData[m+1] = ptElementPosition[i][j][k][1] * tPressureValue;// * DEBUG_PressureValue; 07264 vertexData[m+2] = ptElementPosition[i][j][k][2] * tPressureValue;// * DEBUG_PressureValue; 07265 } 07266 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::OUTSIDE_MODEL ) { 07267 vertexData[m+3] = IC_Thresholds::OUTSIDE_MODEL; 07268 //------------- 07269 origObjectDataAsColor[n ] = 0; 07270 origObjectDataAsColor[n+1] = 0; 07271 origObjectDataAsColor[n+2] = 0; 07272 //------------- 07273 origObjectDataAsColor[n+3] = IC_Thresholds::OUTSIDE_MODEL; 07274 } 07275 else { 07276 vertexData[m+3] = IC_Thresholds::UNSET; 07277 //------------- 07278 origObjectDataAsColor[n ] = 0; 07279 origObjectDataAsColor[n+1] = 0; 07280 origObjectDataAsColor[n+2] = 0; 07281 //------------- 07282 origObjectDataAsColor[n+3] = IC_Thresholds::UNSET; 07283 } 07284 n += 4; 07285 m += 4; 07286 } 07287 } 07288 } 07289 m_glpTexelForObjectOrigData = origObjectDataAsColor; // RGBA for Texture 07290 m_glpTexelForVertexPos = vertexData; // XYZ & Flag 07291 } 07292 /* 07293 //--------------------------------------------------------------- 07294 // Check Resources for Textures 07295 if ( false ) 07296 { 07297 GLint iWidth; 07298 glBindTexture( m_3DTexturePositionParameters.target, m_gluipNameTexturePosition[0] ); 07299 glTexImage3D( 07300 m_3DTexturePositionParameters.target, // target 07301 m_3DTexturePositionParameters.level, // level 07302 m_3DTexturePositionParameters.internalFormat, // internal format 07303 m_3DTexturePositionParameters.width, // width 07304 m_3DTexturePositionParameters.height, // height 07305 m_3DTexturePositionParameters.depth, // depth 07306 m_3DTexturePositionParameters.border, // border 07307 m_3DTexturePositionParameters.pixelFormat, // pixel format 07308 m_3DTexturePositionParameters.dataType, // data type 07309 NULL // texels 07310 ); 07311 // glGetTexLevelParameter{if}v( GLenum target, GLint level, GLenum pname, TYPE *params ); 07312 // If there aren't enough resources to accommodate the texture proxy, 07313 // then the texture state variables for width, height, boder width, 07314 // and component resolutions are set to 0. 07315 glGetTexLevelParameteriv( m_3DTexturePositionParameters.target, 0, GL_TEXTURE_WIDTH, &iWidth ); 07316 if ( iWidth == 0 ) { 07317 #ifdef TAPs_DEBUG_MODE 07318 #ifdef TAPs_USE_WXWIDGETS 07319 wxLogError( "ERROR: Cannot Reserve Resources for Textures!" ); 07320 //wxLogError( wxT( " w/ size: %i, %i, %i" ), m_auiGridSize[0], m_auiGridSize[1], m_auiGridSize[2] ); 07321 //wxLogError( wxT( " w/ dim: %g, %g, %g" ), m_atGridDimension[0], m_atGridDimension[1], m_atGridDimension[2] ); 07322 #else 07323 std::cerr << "ERROR: Cannot Reserve Resources for Textures!" << std::endl; 07324 #endif 07325 #endif 07326 return false; 07327 } 07328 } 07329 //*/ 07330 07331 //std::cout << "\tSTART Setup 3D Textures for Positions" << std::endl; 07332 07333 //=============================================================== 07334 // Setup 3D Textures for Positions (& Velocities) 07335 //--------------------------------------------------------------- 07336 #ifdef TAPs_DEBUG_MODE 07337 std::cout << "Setup 3D Textures for Positions (& Velocities)" << std::endl; 07338 #endif 07339 //----------------------------------------------------- 07340 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 07341 //----------------------------------------------------- 07342 // Current [0], Next [1], & Previous [2] Positions 07343 07344 //std::cout << "START SetupA3DTexture(...)" << std::endl; 07345 //std::cout << "resolutionX: " << resolutionX << std::endl; 07346 //std::cout << "resolutionY: " << resolutionY << std::endl; 07347 //std::cout << "resolutionZ: " << resolutionZ << std::endl; 07348 07349 //=========================================================================================== 07350 // DEBUG 07351 /* 07352 if( GLEW_OK != ::glewInit() ) { 07353 assert( false ); 07354 } 07355 else { 07356 if ( GLEW_VERSION_1_1 ) { 07357 std::cout << "GL Version 1.1 is supported!\n"; 07358 } 07359 if ( GLEW_VERSION_1_2 ) { 07360 std::cout << "GL Version 1.2 is supported!\n"; 07361 } 07362 if ( GLEW_VERSION_1_3 ) { 07363 std::cout << "GL Version 1.3 is supported!\n"; 07364 } 07365 if ( GLEW_VERSION_1_4 ) { 07366 std::cout << "GL Version 1.4 is supported!\n"; 07367 } 07368 if ( GLEW_VERSION_1_5 ) { 07369 std::cout << "GL Version 1.5 is supported!\n"; 07370 } 07371 if ( GLEW_VERSION_2_0 ) { 07372 std::cout << "GL Version 2.0 is supported!\n"; 07373 } 07374 if ( GLEW_VERSION_2_1 ) { 07375 std::cout << "GL Version 2.1 is supported!\n"; 07376 } 07377 } 07378 Generate3DTexture(); 07379 //*/ 07380 //=========================================================================================== 07381 07382 // Setup a 3D Texture for Gradients 07383 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 07384 m_3DTextureGradient = SetupA3DTexture( 07385 target, level, GL_RGB16F_ARB, 07386 resolutionX, resolutionY, resolutionZ, 07387 border, GL_RGB, GL_FLOAT, 07388 m_glpTexelForVertexPos, 07389 1, // gradeint needs only one 3D texture 07390 GL_NEAREST, GL_NEAREST, 07391 GL_CLAMP, GL_CLAMP, GL_CLAMP 07392 ); 07393 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 07394 07395 // Setup a 3D Texture for Home Positions 07396 m_3DTextureHomePosition = SetupA3DTexture( 07397 target, level, internalFormat, 07398 resolutionX, resolutionY, resolutionZ, 07399 border, pixelFormat, dataType, 07400 m_glpTexelForVertexPos, 07401 1, // home position needs only one 3D texture 07402 GL_NEAREST, GL_NEAREST, 07403 GL_CLAMP, GL_CLAMP, GL_CLAMP 07404 ); 07405 07406 // Setup 3D Textures for Positions -- current, next, and previous 07407 m_3DTexturePosition = SetupA3DTexture( 07408 target, level, internalFormat, 07409 resolutionX, resolutionY, resolutionZ, 07410 border, pixelFormat, dataType, 07411 m_glpTexelForVertexPos, 07412 3, // current, next, and previous 07413 //GL_NEAREST, GL_NEAREST, 07414 GL_LINEAR, GL_LINEAR, 07415 GL_CLAMP, GL_CLAMP, GL_CLAMP 07416 ); 07417 //--------------------------------------------------------------- 07418 //=============================================================== 07419 #endif 07420 07421 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 07422 //=============================================================== 07423 // Texture Objects for Velocities 07424 //--------------------------------------------------------------- 07425 // Very Old Code -- No longer usable 07426 // m_gluipNameTextureVelocity = new GLuint[ m_TexturePositionParameters.num2DTextures ]; 07427 // glGenTextures( m_TexturePositionParameters.num2DTextures, m_gluipNameTextureVelocity ); 07428 // m_gluipNameTextureVelocityNext = new GLuint[ m_TexturePositionParameters.num2DTextures ]; 07429 // glGenTextures( m_TexturePositionParameters.num2DTextures, m_gluipNameTextureVelocityNext ); 07430 // TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 07431 //--------------------------------------------------------------- 07432 //=============================================================== 07433 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 07434 07435 //std::cout << "\tSTART Setup a 3D Texture for Connectivities" << std::endl; 07436 07437 //=============================================================== 07438 // Setup a 3D Texture for Connectivities 07439 //--------------------------------------------------------------- 07440 #ifdef TAPs_DEBUG_MODE 07441 std::cout << "Setup a 3D Texture for Connectivities" << std::endl; 07442 #endif 07443 //----------------------------------------------------- 07444 if ( !Setup3DTextureForConnectivities( 07445 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 07446 ptElementPosition, pcElementFlag ) 07447 ) 07448 { 07449 #ifdef TAPs_USE_WXWIDGETS 07450 wxLogError( wxT( "ERROR: ModelDeformableGLSL::Setup3DTexture Fn --> Cannot create 3D texture (connectivity) of size (%i, %i, %i)!" ), 07451 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 07452 #else 07453 std::cerr << "ERROR: ModelDeformableGLSL::Setup3DTexture Fn --> Cannot create 3D texture (connectivity) of size (" 07454 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 07455 << ")!" << std::endl; 07456 #endif 07457 return false; 07458 } 07459 //--------------------------------------------------------------- 07460 //=============================================================== 07461 07462 //std::cout << "\tSTART Setup a 3D Texture for Ellisoid Influence Volume" << std::endl; 07463 07464 //=============================================================== 07465 // Setup a 3D Texture for Ellisoid Influence Volume 07466 // Current Ellisoid Influence is (index [0]) 07467 //--------------------------------------------------------------- 07468 // Create Data for Ellipsoid Influence Volume 07469 int numOfComponents = resolutionX * resolutionY * resolutionZ * 3; 07470 GLfloat * dataForEllipsoidInfluence = new GLfloat[ numOfComponents ]; 07471 07472 // DEBUG 07473 //srand( time( NULL ) ); 07474 //T interpolationVal = static_cast<T>( rand() / static_cast<T>( RAND_MAX ) ); 07475 //std::cout << "interpolationVal: " << interpolationVal << "\n"; 07476 07477 if ( ptElementVertexInterpolation ) { 07478 int count = 0; 07479 for ( int z = 0; z < resolutionZ; ++z ) { 07480 for ( int y = 0; y < resolutionY; ++y ) { 07481 for ( int x = 0; x < resolutionX; ++x ) { 07482 dataForEllipsoidInfluence[count++] = ptElementVertexInterpolation[x][y][z][0]; 07483 dataForEllipsoidInfluence[count++] = ptElementVertexInterpolation[x][y][z][1]; 07484 dataForEllipsoidInfluence[count++] = ptElementVertexInterpolation[x][y][z][2]; 07485 } 07486 } 07487 } 07488 } 07489 else { 07490 for ( int i = 0; i < numOfComponents; ++i ) { 07491 dataForEllipsoidInfluence[i] = 0.5f; 07492 } 07493 } 07494 //----------------------------------------------------- 07495 m_3DTextureEllipsoidInfluence = SetupA3DTexture( 07496 //target, level, internalFormat, 07497 target, level, GL_RGB, 07498 //target, level, GL_RGB32F_ARB, 07499 resolutionX, resolutionY, resolutionZ, 07500 //border, pixelFormat, dataType, 07501 border, GL_RGB, GL_FLOAT, 07502 dataForEllipsoidInfluence, 07503 1, 07504 GL_NEAREST, GL_NEAREST, 07505 GL_CLAMP, GL_CLAMP, GL_CLAMP 07506 ); 07507 //--------------------------------------------------------------- 07508 //=============================================================== 07509 07510 //std::cout << "\tSTART Setup a 3D Texture for Collision Detection" << std::endl; 07511 07512 //=============================================================== 07513 // Setup a 3D Texture for Collision Detection 07514 // Current Collision Info is (index [0]) 07515 //--------------------------------------------------------------- 07516 #ifdef TAPs_DEBUG_MODE 07517 std::cout << "Setup a 3D Texture for Collision Detection" << std::endl; 07518 #endif 07519 //----------------------------------------------------- 07520 // Clear data for collision detection texture 07521 for ( int i = 0; i < iMemorySizeForTotalElements; ++i ) { 07522 m_glpTexelForVertexPos[i] = 0; 07523 } 07524 //----------------------------------------------------- 07525 m_3DTextureCollisionDetection = SetupA3DTexture( 07526 target, level, internalFormat, 07527 resolutionX, resolutionY, resolutionZ, 07528 border, pixelFormat, dataType, 07529 m_glpTexelForVertexPos, 07530 1, 07531 GL_NEAREST, GL_NEAREST, 07532 GL_CLAMP, GL_CLAMP, GL_CLAMP 07533 ); 07534 //--------------------------------------------------------------- 07535 //=============================================================== 07536 07537 //std::cout << "\tSTART Setup a 3D Texture for Offset Values" << std::endl; 07538 07539 //=============================================================== 07540 // Setup a 3D Texture for Offset Values 07541 // Current Offset Values is (index [0]) 07542 //--------------------------------------------------------------- 07543 #ifdef TAPs_DEBUG_MODE 07544 std::cout << "Setup a 3D Texture for Offset Values" << std::endl; 07545 #endif 07546 //----------------------------------------------------- 07547 // Clear data for offset values texture 07548 //for ( int i = 0; i < iMemorySizeForTotalElements; ++i ) { 07549 // m_glpTexelForVertexPos[i] = 0; 07550 //} 07551 //----------------------------------------------------- 07552 m_3DTextureOffsetValues = SetupA3DTexture( 07553 target, level, internalFormat, 07554 resolutionX, resolutionY, resolutionZ, 07555 border, pixelFormat, dataType, 07556 m_glpTexelForVertexPos, 07557 1, 07558 GL_NEAREST, GL_NEAREST, 07559 GL_CLAMP, GL_CLAMP, GL_CLAMP 07560 ); 07561 //--------------------------------------------------------------- 07562 //=============================================================== 07563 07564 //* 07565 //--------------------------------------------------------------- 07566 // DEBUG: Print out the Collision Info after setup 07567 assert( m_3DTextureCollisionDetection ); 07568 #ifdef TAPs_DEBUG_MODE 07569 for ( int i = 0; i < m_3DTextureCollisionDetection->GetNumberOfTextures(); ++i ) { 07570 std::cout << "\nm_3DTextureCollisionDetection -- Texture#" << i << ":\n"; 07571 DebugTextureData( 07572 m_3DTextureCollisionDetection->GetWidth(), 07573 m_3DTextureCollisionDetection->GetHeight(), 07574 m_3DTextureCollisionDetection->GetDepth(), 07575 m_3DTextureCollisionDetection->GetInternalFormatNumberOfComponents(), 07576 m_3DTextureCollisionDetection->GetTarget(), 07577 m_3DTextureCollisionDetection->GetPixelFormat(), 07578 m_3DTextureCollisionDetection->GetDataType(), 07579 m_3DTextureCollisionDetection->GetTexture(0) 07580 ); 07581 } 07582 #endif 07583 //--------------------------------------------------------------- 07584 //*/ 07585 07586 //* 07587 //--------------------------------------------------------------- 07588 // DEBUG: Print out the Offset Values Info after setup 07589 assert( m_3DTextureOffsetValues ); 07590 #ifdef TAPs_DEBUG_MODE 07591 for ( int i = 0; i < m_3DTextureOffsetValues->GetNumberOfTextures(); ++i ) { 07592 std::cout << "m_3DTextureOffsetValues -- Texture#" << i << ":\n"; 07593 DebugTextureData( 07594 m_3DTextureOffsetValues->GetWidth(), 07595 m_3DTextureOffsetValues->GetHeight(), 07596 m_3DTextureOffsetValues->GetDepth(), 07597 m_3DTextureOffsetValues->GetInternalFormatNumberOfComponents(), 07598 m_3DTextureOffsetValues->GetTarget(), 07599 m_3DTextureOffsetValues->GetPixelFormat(), 07600 m_3DTextureOffsetValues->GetDataType(), 07601 m_3DTextureOffsetValues->GetTexture(0) 07602 ); 07603 } 07604 #endif 07605 //--------------------------------------------------------------- 07606 //*/ 07607 07608 //--------------------------------------------------------------- 07609 // Return to Unnamed Default (3D) Texture 07610 m_3DTexturePosition->UnbindTexture(); 07611 //--------------------------------------------------------------- 07612 //=============================================================== 07613 //--------------------------------------------------------------- 07614 // Clear Temp Data 07615 delete [] m_glpTexelForVertexPos; 07616 m_glpTexelForVertexPos = NULL; 07617 delete [] m_glpTexelForObjectOrigData; 07618 m_glpTexelForObjectOrigData = NULL; 07619 //--------------------------------------------------------------- 07620 07621 //std::cout << "END Setup3DTexturesForSimulation()" << std::endl; 07622 07623 return true; 07624 } 07625 //----------------------------------------------------------------------------- 07626 // END: Setup3DTexturesForSimulation 07627 //***************************************************************************** 07628 07629 07631 // START DRAWING FNs 07633 //***************************************************************************** 07634 // BEGIN: DrawByGL_AllElementsWithConnectivities_GPU_AsQuads 07635 //----------------------------------------------------------------------------- 07636 template <typename T> 07637 void ModelDeformableGLSL<T>::DrawByGL_AllElementsWithConnectivities_GPU_AsQuads () 07638 { 07639 //* 07640 //--------------------------------------------------------------- 07641 if ( !m_3DTexturePosition ) return; 07642 //--------------------------------------------------------------- 07643 glPushAttrib( GL_ALL_ATTRIB_BITS ); 07644 //----------------------------------------------------- 07645 GLsizei sizeForPosition = 07646 m_3DTexturePosition->GetWidth() * 07647 m_3DTexturePosition->GetHeight() * 07648 m_3DTexturePosition->GetDepth() * 07649 m_3DTexturePosition->GetInternalFormatNumberOfComponents(); 07650 GLfloat * dataForPosition = new GLfloat[ sizeForPosition ]; 07651 { 07652 int i = 0; 07653 //================================================= 07654 // Read data for positions from a texture to memory 07655 glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 ); 07656 m_3DTexturePosition->BindTexture(0); 07657 glGetTexImage( 07658 m_3DTexturePosition->GetTarget(), 07659 m_3DTexturePosition->GetLevel(), 07660 m_3DTexturePosition->GetPixelFormat(), 07661 m_3DTexturePosition->GetDataType(), 07662 dataForPosition 07663 ); 07664 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 07665 //================================================= 07666 } 07667 //--------------------------------------------------------------- 07668 TAPs::OpenGL::Fn::CHECK_GL_ERROR(); 07669 //----------------------------------------------------- 07670 glPopAttrib(); 07671 //--------------------------------------------------------------- 07672 07673 //=============================================================== 07674 // Drawing 07675 //--------------------------------------------------------------- 07676 // Draw as Spheres 07677 m_OGLUsefulObj.SetColor( 0.1, 0.3, 0.25, 0.25 ); 07678 //----------------------------------------------------- 07679 glPushAttrib( GL_ALL_ATTRIB_BITS ); 07680 glEnable( GL_LIGHTING ); 07681 glEnable( GL_COLOR_MATERIAL ); 07682 //glLineWidth( 3 ); 07683 //glPointSize( 11 ); 07684 glColor3f( 0.25, 0.35, 0.45 ); 07685 int voxel[8]; // = { 0, 0, 0, 0, 0, 0, 0, 0 }; 07686 int quad[6][4] = { 07687 3, 2, 1, 0, 07688 4, 5, 6, 7, 07689 5, 1, 2, 6, 07690 0, 4, 7, 3, 07691 7, 6, 2, 3, 07692 5, 1, 0, 4 07693 }; 07694 //GLfloat normals[6][3] = { 07695 // 07696 //} 07697 //********************************* 07698 // voxel 07699 // 3-----2 07700 // /| /| 07701 // 7-----6 | 07702 // | 0---|-1 y^ -z 07703 // |/ |/ |/ 07704 // 4-----5 +--->x 07705 //********************************* 07706 //int Z = 1, Y = 1, X = 1; { { { 07707 int threshold = 300; 07708 for ( int Z = 0; Z < m_vGridResolution[2]-1; ++Z ) { 07709 int idxZ = Z * m_vGridResolution[1] * m_vGridResolution[0]; 07710 int idxZinc = m_vGridResolution[1] * m_vGridResolution[0] * 4; 07711 for ( int Y = 0; Y < m_vGridResolution[1]-1; ++Y ) { 07712 int idxY = Y * m_vGridResolution[0]; 07713 int idxYinc = m_vGridResolution[0] * 4; 07714 for ( int X = 0; X < m_vGridResolution[0]-1; ++X ) { 07715 // indices 07716 voxel[0] = (idxZ + idxY + X) * 4; 07717 voxel[1] = voxel[0] + 4; 07718 voxel[3] = voxel[0] + idxYinc; 07719 voxel[2] = voxel[3] + 4; 07720 voxel[4] = voxel[0] + idxZinc; 07721 voxel[5] = voxel[1] + idxZinc; 07722 voxel[6] = voxel[2] + idxZinc; 07723 voxel[7] = voxel[3] + idxZinc; 07724 07725 //if ( dataForPosition[count+3] > threshold ) { 07726 //glBegin( GL_POINTS ); 07727 //{ 07728 // for ( int v = 0; v < 8; ++v ) { 07729 // float f = (float)v/10.0f; 07730 // glColor3f( 0.2+f, 0.2+2*f, 0.2+3*f ); 07731 // glVertex3f( 07732 // dataForPosition[voxel[v] ], 07733 // dataForPosition[voxel[v]+1], 07734 // dataForPosition[voxel[v]+2] 07735 // ); 07736 // } 07737 //} 07738 //glEnd(); 07739 //------------------------------- 07740 07741 glBegin( GL_QUADS ); 07742 for ( int q = 0; q < 6; ++q ) { 07743 if ( dataForPosition[voxel[quad[q][0]]+3] > threshold && 07744 dataForPosition[voxel[quad[q][1]]+3] > threshold && 07745 dataForPosition[voxel[quad[q][2]]+3] > threshold && 07746 dataForPosition[voxel[quad[q][3]]+3] > threshold ) 07747 { 07748 for ( int s = 0; s < 4; ++s ) { 07749 glVertex3f( 07750 dataForPosition[voxel[quad[q][s]] ], 07751 dataForPosition[voxel[quad[q][s]]+1], 07752 dataForPosition[voxel[quad[q][s]]+2] 07753 ); 07754 } 07755 } 07756 } 07757 glEnd(); 07758 } 07759 } 07760 } 07761 glPopAttrib(); 07762 //--------------------------------------------------------------- 07763 //=============================================================== 07764 delete [] dataForPosition; 07765 //*/ 07766 } 07767 //----------------------------------------------------------------------------- 07768 // END: DrawByGL_AllElementsWithConnectivities_GPU_AsQuads 07769 //***************************************************************************** 07771 // END DRAWING FNs 07773 07774 07775 //***************************************************************************** 07776 // BEGIN DEBUG: GetTextureFloatData 07777 //----------------------------------------------------------------------------- 07778 //----------------------------------------------------------------------------- 07779 // END: GetTextureFloatData 07780 //***************************************************************************** 07781 07782 07783 //***************************************************************************** 07784 // BEGIN DEBUG: DebugTextureData 07785 //----------------------------------------------------------------------------- 07786 // Print out texture data using a Buffer object and a Framebuffer object 07787 template <typename T> 07788 void ModelDeformableGLSL<T>::DebugTextureData ( 07789 GLsizei width, 07790 GLsizei height, 07791 GLsizei depth, 07792 GLint iComponents, 07793 GLenum target, 07794 GLenum pixelFormat, 07795 GLenum dataType, 07796 GLuint pTextureObject 07797 ) 07798 { 07799 glBindTexture( target, pTextureObject ); 07800 //----------------------------------------------------- 07801 GLint size = width * height * depth * iComponents; 07802 GLfloat * data = new GLfloat[size]; 07803 07804 std::cout << "SIZE: " << size << std::endl; 07805 //----------------------------------------------------- 07806 glGetTexImage( target, 0, pixelFormat, dataType, data ); 07807 //----------------------------------------------------- 07808 int count = 0; 07809 int line = 0; 07810 int sizeWH = width * height * iComponents; 07811 int index = 0; 07812 for ( int d = 0; d < depth; ++d ) { 07813 std::cout << "Texture Position[" << d << "]:\n"; 07814 std::cout << "SIZE: " << sizeWH << "\n"; 07815 std::cout << "("; 07816 for ( int i = 0; i < sizeWH; ++i ) { 07817 std::cout << data[index++]; 07818 if ( ++line == width * 4 ) { 07819 std::cout << ")\n("; 07820 line = 0; 07821 count = 0; 07822 continue; 07823 } 07824 if ( ++count % 4 != 0 ) std::cout << ", "; 07825 else std::cout << ")\t("; 07826 } 07827 } 07828 //----------------------------------------------------- 07829 glBindTexture( target, 0 ); 07830 delete [] data; 07831 } 07832 //----------------------------------------------------------------------------- 07833 // END DEBUG: DebugTextureData 07834 //***************************************************************************** 07835 07837 // START FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 07839 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 07840 //***************************************************************************** 07841 // BEGIN DEBUG: DebugTextureDataInConnectivityFormat 07842 //----------------------------------------------------------------------------- 07843 // Print out texture data using a Buffer object and a Framebuffer object 07844 template <typename T> 07845 void ModelDeformableGLSL<T>::DebugTextureDataInConnectivityFormat ( 07846 GLsizei width, 07847 GLsizei height, 07848 GLsizei depth, 07849 GLint iComponents, 07850 GLenum target, 07851 GLenum pixelFormat, 07852 GLenum dataType, 07853 GLuint pTextureObject 07854 ) 07855 { 07856 glBindTexture( target, pTextureObject ); 07857 //----------------------------------------------------- 07858 GLint size = width * height * depth * iComponents; 07859 GLfloat * data = new GLfloat[size]; 07860 //----------------------------------------------------- 07861 glGetTexImage( target, 0, pixelFormat, dataType, data ); 07862 //----------------------------------------------------- 07863 int nextOffsetIdx = 3 * 3 * 4; // 3x3 * 4 components 07864 // One group has (3x3x4 =) 36 components (3 x 3 x (XYZW)) 07865 // Ignore the fourth components 07866 // Group X into 3x3 07867 // Group Y into 3x3 07868 // Group Z into 3x3 07869 // Ignore W 07870 //------------------------------------------- 07871 // Index: 07872 // 00 04 08 01 05 09 02 06 10 07873 // 12 16 20 13 17 21 14 18 22 07874 // 24 28 32 25 29 33 26 30 34 07875 //------------------------------------------- 07876 width /= 3; 07877 height /= 3; 07878 int idx = 0; 07879 int idxMain = 0; 07880 for ( int d = 0; d < depth; ++d ) { 07881 std::cout << "Texture Connectivity[" << d << "]:\n"; 07882 for ( int h = 0; h < height; ++h ) { 07883 idx = idxMain; 07884 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 07885 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 07886 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 07887 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 07888 } 07889 std::cout << "\n"; 07890 idx = idxMain + 3*4*width; 07891 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 07892 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 07893 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 07894 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 07895 } 07896 std::cout << "\n"; 07897 idx = idxMain + 2*3*4*width; 07898 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 07899 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 07900 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 07901 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 07902 } 07903 std::cout << "\n\n"; 07904 idxMain += nextOffsetIdx * width; 07905 } 07906 } 07907 //----------------------------------------------------- 07908 glBindTexture( target, 0 ); 07909 delete [] data; 07910 } 07911 //----------------------------------------------------------------------------- 07912 // END DEBUG: DebugTextureDataInConnectivityFormat 07913 //***************************************************************************** 07914 #endif 07915 07916 // END FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 07918 07919 07921 // START FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 07923 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 07924 //***************************************************************************** 07925 // BEGIN DEBUG: DebugTextureDataInConnectivityFormat 07926 //----------------------------------------------------------------------------- 07927 // Print out texture data using a Buffer object and a Framebuffer object 07928 template <typename T> 07929 void ModelDeformableGLSL<T>::DebugTextureDataInConnectivityFormat ( 07930 GLsizei width, 07931 GLsizei height, 07932 GLsizei depth, 07933 GLint iComponents, 07934 GLenum target, 07935 GLenum pixelFormat, 07936 GLenum dataType, 07937 GLuint pTextureObject 07938 ) 07939 { 07940 /* 07941 glBindTexture( target, pTextureObject ); 07942 //----------------------------------------------------- 07943 GLint size = width * height * depth * iComponents; 07944 GLfloat * data = new GLfloat[size]; 07945 //----------------------------------------------------- 07946 glGetTexImage( target, 0, pixelFormat, dataType, data ); 07947 //----------------------------------------------------- 07948 int nextOffsetIdx = 4; // 4 components = 32 bits 07949 // One group has (4 =) 36 components (XYZW) 07950 // x component -- front group, exclude front 07951 // y component -- center group, exclude center 07952 // z component -- back group, exclude back 07953 // w component -- misc group, include front, center, and back 07954 //------------------------------------------- 07955 // Index: 07956 // -------------------------------- 07957 // | FRONT CENTER BACK | 07958 // | 07 06 05 15 14 13 23 22 21 | 07959 // | 04 25 03 12 26 11 20 24 19 | 07960 // | 02 01 00 10 09 08 18 17 16 | 07961 // -------------------------------- 07962 //------------------------------------------------- 07963 // RGBA Components Represent 07964 // ------------------------------------------- 07965 // 8-bit ubyte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 07966 // ------------------------------------------- 07967 // R --> Front | NW| N | NE| W | E | SW| S | SE| 07968 // G --> Center | NW| N | NE| W | E | SW| S | SE| 07969 // B --> Back | NW| N | NE| W | E | SW| S | SE| 07970 // A --> Misc | | | | | | C | F | B | 07971 //------------------------------------------------- 07972 // ---------------------------------------------------------------------- 07973 // Connectivities 07974 // (The group is arranged in one texel of 4 components.) 07975 // ---------------------------------------------------------------------- 07976 // | FRONT | CENTER | BACK | 07977 // | 07(NW) 06(N) 05(NE) | 15(NW) 14(N) 13(NE) | 23(NW) 22(N) 21(NE) | 07978 // | 04(W) 25(F) 03(E) | 12(W) 26(C) 11(E) | 20(W) 24(B) 19(E) | 07979 // | 02(SW) 01(S) 00(SE) | 10(SW) 09(S) 08(SE) | 18(SW) 17(S) 16(SE) | 07980 // ---------------------------------------------------------------------- 07981 int idx = 0; 07982 int idxMain = 0; 07983 for ( int d = 0; d < depth; ++d ) { 07984 std::cout << "Texture Connectivity[" << d << "]:\n"; 07985 for ( int h = 0; h < height; ++h ) { 07986 idx = idxMain; 07987 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 07988 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 07989 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 07990 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 07991 } 07992 std::cout << "\n"; 07993 idx = idxMain + 3*4*width; 07994 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 07995 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 07996 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 07997 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 07998 } 07999 std::cout << "\n"; 08000 idx = idxMain + 2*3*4*width; 08001 for ( int w = 0; w < width; ++w, idx += 3*4 ) { 08002 std::cout << "|" << data[idx ] << " " << data[idx+ 4] << " " << data[idx+ 8] 08003 << " " << data[idx+ 1] << " " << data[idx+ 5] << " " << data[idx+ 9] 08004 << " " << data[idx+ 2] << " " << data[idx+ 6] << " " << data[idx+10] << "| "; 08005 } 08006 std::cout << "\n\n"; 08007 idxMain += nextOffsetIdx * width; 08008 } 08009 } 08010 //----------------------------------------------------- 08011 glBindTexture( target, 0 ); 08012 delete [] data; 08013 //*/ 08014 } 08015 //----------------------------------------------------------------------------- 08016 // END DEBUG: DebugTextureDataInConnectivityFormat 08017 //***************************************************************************** 08018 #endif 08019 08020 // END FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 08022 08023 //----------------------------------------------------------------------------- 08024 //============================================================================= 08025 END_NAMESPACE_TAPs__OpenGL 08026 //----------------------------------------------------------------------------- 08027 //34567890123456789012345678901234567890123456789012345678901234567890123456789 08028 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----