예제 #1
0
		/**
		 * Method is used to group object components.
		 * @param	object is source object.
		 * @param	vertices is other object vertices.
		 * @pram	indices is other object indices.
		 * @param	faceStatus1 is face status.
		 * @param	faceStatus2 is face status.
		 */
		void GeoModifier::groupObjectComponents(Object3D& object, VertexSet& vertices, IntSet& indices, int faceStatus1, int faceStatus2)
		{
			//for each face..
			for(int i = 0; i < object.getNumFaces(); ++i)
			{
				Face& face = *(object.getFace(i));

				if(face.getStatus()==faceStatus1 || face.getStatus()==faceStatus2)
				{
					VertexPointerSet faceVerts;
					faceVerts.add(face.v1);
					faceVerts.add(face.v2);
					faceVerts.add(face.v3);

					for(int j=0;j<faceVerts.length();j++)
					{
						if(vertices.contains(faceVerts[j]))
							indices.push_back(vertices.indexOf(faceVerts[j]));
						else
						{
							indices.push_back(vertices.length());
							vertices.AddVertex(*faceVerts[j]);
						}
					}
				}
			}
		}
예제 #2
0
		/**
		 * Method is used to perform ray trace classify of face.
		 * @param	oobject is source object.
		 */
		void Face::rayTraceClassify(Object3D& object)
		{
			//creating a ray starting starting at the face baricenter going to the normal direction
			Vector p0;
			p0.x = (v1->x + v2->x + v3->x)/3.0f;
			p0.y = (v1->y + v2->y + v3->y)/3.0f;
			p0.z = (v1->z + v2->z + v3->z)/3.0f;
			Line ray(getNormal(),p0);
	
			bool success;
			float dotProduct, distance; 
			Vector intersectionPoint;
			Face * closestFace = 0;
			float closestDistance;

			//float TOL = 0.0001f;
								
			do
			{
				success = true;
				closestDistance = 99999.9f;
				//for each face from the other solid...
				for(int i=0;i<object.getNumFaces();i++)
				{
					Face & face = *(object.getFace(i));
					dotProduct = face.getNormal() * ray.getDirection(); // dot product
					bool bIntersectResult = false;
					intersectionPoint = ray.computePlaneIntersection(face.getNormal(), face.v1->getPosition(), bIntersectResult);
					// Need to return whether was successful.
							
					//if ray intersects the plane...  
					//if(intersectionPoint!=0)
					if(bIntersectResult)
					{
						distance = ray.computePointToPointDistance(intersectionPoint);
				
						//if ray lies in plane...
						if(fabs(distance)<TOL && fabs(dotProduct)<TOL)
						{
							//disturb the ray in order to not lie into another plane 
							ray.perturbDirection();
							success = false;
							break;
						}
				
						//if ray starts in plane...
						if(fabs(distance)<TOL && fabs(dotProduct)>TOL)
						{
							//if ray intersects the face...
							if(face.hasPoint(intersectionPoint))
							{
								//faces coincide
								closestFace = &face;
								closestDistance = 0;
								break;
							}
						}
				
						//if ray intersects plane... 
						else if(fabs(dotProduct)>TOL && distance>TOL)
						{
							if(distance<closestDistance)
							{
								//if ray intersects the face;
								if(face.hasPoint(intersectionPoint))
								{
									//this face is the closest face untill now
									closestDistance = distance;
									closestFace = &face;
								}
							}
						}
					}
				}
			}while(success==false);
	
			//none face found: outside face
			if(closestFace==0)
				status = OUTSIDE;
			//face found: test dot product
			else
			{
				dotProduct = closestFace->getNormal() * ray.getDirection();
		
				//distance = 0: coplanar faces
				if(fabs(closestDistance)<TOL)
				{
					if(dotProduct>TOL)
						status = SAME;
					else if(dotProduct<-TOL)
						status = OPPOSITE;
				}
		
				//dot product > 0 (same direction): inside face
				else if(dotProduct>TOL)
					status = INSIDE;
				//dot product < 0 (opposite direction): outside face
				else if(dotProduct<-TOL)
					status = OUTSIDE;
			}
		}