void Mesh::Update(bool drawNormals)
{
	this->StartRecording();

	glBegin(GL_TRIANGLES);
		for( unsigned int i = 0; i < this->_triangles.size(); ++i )
		{
			Triangle* triangle = this->_triangles.at(i);
			if( triangle )
			{
				triangle->Execute(false, true, true);
			}
		}
	glEnd();

	if( drawNormals )
	{
		glColor4f(1.0f, 0.0f, 1.0f, 0.75f);
		glBegin(GL_LINES);
			for( unsigned int i = 0; i < this->_vertices.size(); ++i )
			{
				Vertex* vertex = this->_vertices.at(i);
				if( vertex )
				{
					glVertex3fv((float*)vertex->GetPosition());
					glVertex3fv((float*)(vertex->GetPosition()+vertex->GetNormal()));
				}
			}
		glEnd();
	}

	this->StopRecording();
}
Example #2
0
Float ConvertDensity(const Vertex &cur, Float pdf, const Vertex &next) {
    // Return solid angle density if _next_ is an infinite area light
    if (next.IsInfiniteLight()) return pdf;
    Vector3f d = next.GetPosition() - cur.GetPosition();
    Float invL2 = 1.f / d.LengthSquared();
    if (next.IsOnSurface())
        pdf *= AbsDot(next.GetGeoNormal(), d * std::sqrt(invL2));
    return pdf * invL2;
}
Example #3
0
Spectrum GeometryTerm(const Scene &scene, Sampler &sampler, const Vertex &v0,
                      const Vertex &v1) {
    Vector3f d = v0.GetPosition() - v1.GetPosition();
    Float G = 1.f / d.LengthSquared();
    d *= std::sqrt(G);
    if (v0.IsOnSurface()) G *= Dot(v0.GetShadingNormal(), d);
    if (v1.IsOnSurface()) G *= Dot(v1.GetShadingNormal(), d);
    VisibilityTester vis(v0.GetInteraction(), v1.GetInteraction());
    return std::abs(G) * vis.T(scene, sampler);
}
void Mesh::TransformVertices(Matrix44f transform)
{
	for( unsigned int i = 0; i < this->_vertices.size(); ++i )
	{
		Vertex* vertex = this->_vertices.at(i);
		if( vertex )
		{
			vertex->Position() = (Vector3f)(transform*Vector4f(vertex->GetPosition(), 1.0f));
		}
	}
}
Example #5
0
void Skin::Draw(){
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    for(Triangle* t : triangles){
        glBegin(GL_TRIANGLES);
        Vertex* v = updatedVertices[t->GetVertex1()];
        glNormal3f(v->GetNormal().x, v->GetNormal().y, v->GetNormal().z);
        glVertex3f(v->GetPosition().x, v->GetPosition().y, v->GetPosition().z);
        
        v = updatedVertices[t->GetVertex2()];
        glNormal3f(v->GetNormal().x, v->GetNormal().y, v->GetNormal().z);
        glVertex3f(v->GetPosition().x, v->GetPosition().y, v->GetPosition().z);
        
        v = updatedVertices[t->GetVertex3()];
        glNormal3f(v->GetNormal().x, v->GetNormal().y, v->GetNormal().z);
        glVertex3f(v->GetPosition().x, v->GetPosition().y, v->GetPosition().z);
        glEnd();
    }
}
Example #6
0
D3DXVECTOR3 Vertex::CalMeanNeighborDir()
{
	D3DXVECTOR3 resultDir = D3DXVECTOR3(0,0,0);
	float tmpTotalCoverArea = 0;
	for (int i=0;i<mNeighborTriangleSurfaceCount;i++)
	{
		for (int j=0;j<3;j++)
		{
			Vertex* aVertex = mpNeighborTriangleSurface[i]->GetIthVertex(j);
			float tmpCoverArea = aVertex->GetCoverArea();
			D3DXVECTOR3 pos = aVertex->GetPosition();
			resultDir += (pos - mPosition);// * tmpCoverArea;
			tmpTotalCoverArea += tmpCoverArea;
		}
	}
	resultDir /= 2 * mNeighborTriangleSurfaceCount;// * tmpTotalCoverArea;
	return resultDir;
}
Example #7
0
void Skin::Update(){
    
    std::vector<Matrix34 *> skinningMatrices = std::vector<Matrix34 *>(numJoints);
    std::vector<Joint *> joints = Skel->GetJoints();
    for(Joint* j : joints){

        int jointNum = j->GetJointNumber();
        Matrix34 world = j->GetWorldMatrix();
        Matrix34 binv = *bindings[jointNum];
        skinningMatrices[jointNum] = new Matrix34();
        skinningMatrices[jointNum]->Dot(world, binv);
    }

    
    for(int c = 0; c < numVerts; c++){
        Vertex* v = vertices[c];
        Vector3 vTemp = Vector3();
        Vector3 nTemp = Vector3();
        Vector3 vFinal = Vector3();
        Vector3 nFinal = Vector3();
        
        for(int i = 0; i < v->numAttachments; i++){
            int jointNumber = v->joints[i];
            float weight = v->skinweights[i];
            
            skinningMatrices[jointNumber]->Transform(v->GetPosition(), vTemp);
            vFinal += weight*vTemp;
            
            skinningMatrices[jointNumber]->Transform(v->GetNormal(), nTemp);
            nFinal += weight*vTemp;
        }
        
        updatedVertices[c]->SetPosition(vFinal);
        nFinal.Normalize();
        updatedVertices[c]->SetNormal(nFinal);
    }
}