예제 #1
0
파일: Plane.cpp 프로젝트: MarkSkyzoid/ciri
	Plane::Plane( const cc::Vec3f& a, const cc::Vec3f& b, const cc::Vec3f& c ) {
		const cc::Vec3f ab = b - a;
		const cc::Vec3f ac = c - a;
		const cc::Vec3f cross = ab.cross(ac);
		_normal = cross.normalized();
		_d = -_normal.dot(a);
	}
예제 #2
0
cc::Vec3f GeometricPlane::getNormal() {
	const cc::Vec3f p0 = (_xform.getWorld() * cc::Vec4f(_verts[0].position, 1.0f)).truncated();
	const cc::Vec3f p1 = (_xform.getWorld() * cc::Vec4f(_verts[1].position, 1.0f)).truncated();
	const cc::Vec3f p2 = (_xform.getWorld() * cc::Vec4f(_verts[2].position, 1.0f)).truncated();
	const cc::Vec3f p3 = (_xform.getWorld() * cc::Vec4f(_verts[3].position, 1.0f)).truncated();
	const cc::Vec3f a = p1 - p0;
	const cc::Vec3f b = p3 - p0;
	return a.cross(b).normalized();
}
예제 #3
0
bool ClipMesh::getTriangles( std::vector<int>& indices ) {
	const size_t numFaces = _faces.size();
	for( size_t currFace = 0; currFace < numFaces; ++currFace ) {
		CFace& face = _faces[currFace];
		if( !face.visible ) {
			continue;
		}

		const size_t numEdges = face.edges.size();
		//assert(numEdges >= 3); // unexpected condition
		if( numEdges < 3 ) {
			return false;
		}
		std::vector<int> vOrdered(numEdges+1);
		if( !orderVertices(face, vOrdered) ) {
			return false;
		}

		const int v0 = vOrdered[0];
		const int v2 = vOrdered[numEdges - 1];
		const int v1 = vOrdered[(numEdges - 1) >> 1];
		const cc::Vec3f diff1 = _vertices[v1].point - _vertices[v0].point;
		const cc::Vec3f diff2 = _vertices[v2].point - _vertices[v0].point;
		const float sgnVolume = face.normal.dot(diff1.cross(diff2));
		if( sgnVolume < 0.0f ) { // feel free to invert this test
			// clockwise, need to swap
			for( unsigned int i = 1; i + 1 < numEdges; ++i ) {
				indices.push_back(v0);
				indices.push_back(vOrdered[i + 1]);
				indices.push_back(vOrdered[i]);
			}
		} else {
			// counterclockwise
			for( unsigned int i = 1; i + 1 < numEdges; ++i ) {
				indices.push_back(v0);
				indices.push_back(vOrdered[i]);
				indices.push_back(vOrdered[i + 1]);
			}
		}
	}

	return true;
}