예제 #1
0
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();
	}
}
예제 #2
0
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);
}
예제 #3
0
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);
}
예제 #4
0
void GameCamera::updateLookAt(const glm::vec3 & position, const glm::vec3 & direction, float normalizedCaveDistance)
{
    const glm::vec3 defaultLookAt(0.0f, 0.0f, -1.0f);
    const glm::vec3 realDirection = (glm::length(direction) == 0.0f) ? glm::vec3(0.0f, 0.0f, -1.0f) : direction;
    
    float shakiness = calculateShakiness(normalizedCaveDistance);

    m_noise.setVolume(shakiness * 0.95);
    
    glm::vec3 shakeLookAt = glm::normalize(glm::vec3(glm::gaussRand(0.0f, 8.0f),
                                                     glm::gaussRand(0.0f, 8.0f),
                                                     glm::linearRand(0.1f, 0.3f)));
    
    glm::vec3 lookAt = glm::mix(defaultLookAt, shakeLookAt, shakiness);
    
    glm::vec3 centerOffset = glm::normalize(glm::normalize(realDirection) + lookAt);
    m_currentCenterOffset = glm::mix(centerOffset, m_currentCenterOffset, 0.91f);
    
    m_eye = glm::vec3(glm::mix(m_eye.xy(), position.xy(), 0.5f), position.z);
    m_center = m_eye + m_currentCenterOffset;
    m_up = Util::toCartesian(glm::mat4(m_currentRotation) * glm::vec4(0.0f, 1.0f, 0.0f, 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 );
}