void Camera::LookAtDirection(glm::vec3 a_v3Direction) { // Makes sure the new direction vector actually points somewhere. if (a_v3Direction.length() != 0) { m_v3Forward = glm::normalize(a_v3Direction); CalculateDirectionVectors(); CalculateView(); } }
float Viscosity::CalculateLaplacian(glm::vec3 distance) { float len = distance.length(); float lenpow2 = pow(len,2); float epsilon = ldexp(1.192092896,-7); if(lenpow2 > KernelSizeSquared) { return 0.0f; } if(lenpow2 < epsilon) { lenpow2 = epsilon; } float lenSqrt = sqrt(lenpow2); return kernelFactor * (6.0f/ kernelSizepow3) * (kernelSize - lenpow2); }
float Viscosity::Calculate(glm::vec3 distance) { float len = distance.length(); float lenpow2 = pow(len,2); float epsilon = ldexp(1.192092896,-7); if(lenpow2 > KernelSizeSquared) { return 0.0f; } if(lenpow2 < epsilon) { lenpow2 = epsilon; } float lenSqrt = sqrt(lenpow2); float lenpow3 = pow(lenSqrt,3); return kernelFactor * (((-lenpow3/(2.0f * kernelSizepow3)) * (lenSqrt/ KernelSizeSquared) + (kernelSize /(2.0f * lenSqrt))) - 1.0f); }
//-------------------------------------------------------------- void ofxBulletTriMeshShape::create( btDiscreteDynamicsWorld* a_world, ofMesh& aMesh, btTransform &a_bt_tr, float a_mass, glm::vec3 aAAbbMin, glm::vec3 aAAbbMax ) { if( aMesh.getMode() != OF_PRIMITIVE_TRIANGLES ) { ofLogWarning() << " ofxBulletTriMeshShape :: create : mesh must be using triangles, not creating!!" << endl; return; } if( aMesh.getNumIndices() < 3 ) { ofLogWarning() << " ofxBulletTriMeshShape :: create : mesh must have indices, not creating!" << endl; return; } if( !_bInited || _shape == NULL ) { int vertStride = sizeof(btVector3); int indexStride = 3*sizeof(int); totalVerts = (int)aMesh.getNumVertices(); totalIndices = (int)aMesh.getNumIndices(); const int totalTriangles = totalIndices / 3; if( bullet_indices != NULL ) { removeShape(); } if( bullet_vertices != NULL ) { removeShape(); } if( bullet_indexVertexArrays != NULL ) { removeShape(); } if( _shape != NULL ) { removeShape(); } bullet_vertices = new btVector3[ totalVerts ]; bullet_indices = new int[ totalIndices ]; auto& tverts = aMesh.getVertices(); auto& tindices = aMesh.getIndices(); for( int i = 0; i < totalVerts; i++ ) { bullet_vertices[i].setValue( tverts[i].x, tverts[i].y, tverts[i].z ); } for( int i = 0; i < totalIndices; i++ ) { bullet_indices[i] = (int)tindices[i]; } bullet_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles, bullet_indices, indexStride, totalVerts, (btScalar*) &bullet_vertices[0].x(), vertStride); // if you are having trouble with objects falling through, try passing in smaller or larger aabbMin and aabbMax // to something closer to the size of your object // // btVector3 aabbMin(-10000,-10000,-10000),aabbMax(10000,10000,10000); if( aAAbbMin.length() > 0 && aAAbbMax.length() > 0 ) { btVector3 aabbMin( aAAbbMin.x, aAAbbMin.y, aAAbbMin.z ); btVector3 aabbMax( aAAbbMax.x, aAAbbMax.y, aAAbbMax.z ); _shape = new btBvhTriangleMeshShape(bullet_indexVertexArrays, true, aabbMin, aabbMax ); } else { _shape = new btBvhTriangleMeshShape(bullet_indexVertexArrays, true, true ); } } ofxBulletRigidBody::create( a_world, _shape, a_bt_tr, a_mass ); createInternalUserData(); updateMesh( a_world, aMesh ); }