예제 #1
0
/// Changes a btManifoldPoint collision normal to the normal from the mesh.
void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,const btCollisionObjectWrapper* colObj1Wrap, int partId0, int index0, int normalAdjustFlags)
{
    //btAssert(colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE);
    if (colObj0Wrap->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
        return;

    btBvhTriangleMeshShape* trimesh = 0;

    if( colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE )
       trimesh = ((btScaledBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape())->getChildShape();
   else
       trimesh = (btBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();

    btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
    if (!triangleInfoMapPtr)
        return;

    int hash = btGetHash(partId0,index0);


    btTriangleInfo* info = triangleInfoMapPtr->find(hash);
    if (!info)
        return;

    btScalar frontFacing = (normalAdjustFlags & BT_TRIANGLE_CONVEX_BACKFACE_MODE)==0? 1.f : -1.f;

    const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
    btVector3 v0,v1,v2;
    tri_shape->getVertex(0,v0);
    tri_shape->getVertex(1,v1);
    tri_shape->getVertex(2,v2);

    //btVector3 center = (v0+v1+v2)*btScalar(1./3.);

    btVector3 red(1,0,0), green(0,1,0),blue(0,0,1),white(1,1,1),black(0,0,0);
    btVector3 tri_normal;
    tri_shape->calcNormal(tri_normal);

    //btScalar dot = tri_normal.dot(cp.m_normalWorldOnB);
    btVector3 nearest;
    btNearestPointInLineSegment(cp.m_localPointB,v0,v1,nearest);

    btVector3 contact = cp.m_localPointB;
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
    const btTransform& tr = colObj0->getWorldTransform();
    btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,red);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW



    bool isNearEdge = false;

    int numConcaveEdgeHits = 0;
    int numConvexEdgeHits = 0;

    btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
    localContactNormalOnB.normalize();//is this necessary?

    // Get closest edge
    int      bestedge=-1;
    btScalar    disttobestedge=BT_LARGE_FLOAT;
    //
    // Edge 0 -> 1
    if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {
       btVector3 nearest;
       btNearestPointInLineSegment( cp.m_localPointB, v0, v1, nearest );
       btScalar     len=(contact-nearest).length();
       //
       if( len < disttobestedge )
       {
          bestedge=0;
          disttobestedge=len;
      }
   }
    // Edge 1 -> 2
    if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {
       btVector3 nearest;
       btNearestPointInLineSegment( cp.m_localPointB, v1, v2, nearest );
       btScalar     len=(contact-nearest).length();
       //
       if( len < disttobestedge )
       {
          bestedge=1;
          disttobestedge=len;
      }
   }
    // Edge 2 -> 0
    if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {
       btVector3 nearest;
       btNearestPointInLineSegment( cp.m_localPointB, v2, v0, nearest );
       btScalar     len=(contact-nearest).length();
       //
       if( len < disttobestedge )
       {
          bestedge=2;
          disttobestedge=len;
      }
   }

#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
   btVector3 upfix=tri_normal * btVector3(0.1f,0.1f,0.1f);
   btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red );
#endif
    if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
        btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
#endif
        btScalar len = (contact-nearest).length();
        if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
        if( bestedge==0 )
        {
            btVector3 edge(v0-v1);
            isNearEdge = true;

            if (info->m_edgeV0V1Angle==btScalar(0))
            {
                numConcaveEdgeHits++;
            } else
            {

                bool isEdgeConvex = (info->m_flags & TRI_INFO_V0V1_CONVEX);
                btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
    #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
                btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
    #endif //BT_INTERNAL_EDGE_DEBUG_DRAW

                btVector3 nA = swapFactor * tri_normal;

                btQuaternion orn(edge,info->m_edgeV0V1Angle);
                btVector3 computedNormalB = quatRotate(orn,tri_normal);
                if (info->m_flags & TRI_INFO_V0V1_SWAP_NORMALB)
                    computedNormalB*=-1;
                btVector3 nB = swapFactor*computedNormalB;

                btScalar	NdotA = localContactNormalOnB.dot(nA);
                btScalar	NdotB = localContactNormalOnB.dot(nB);
                bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);

#ifdef DEBUG_INTERNAL_EDGE
                {

                    btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
                }
#endif //DEBUG_INTERNAL_EDGE


                if (backFacingNormal)
                {
                    numConcaveEdgeHits++;
                }
                else
                {
                    numConvexEdgeHits++;
                    btVector3 clampedLocalNormal;
                    bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB, info->m_edgeV0V1Angle,clampedLocalNormal);
                    if (isClamped)
                    {
                        if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                        {
                            btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                            //					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                            cp.m_normalWorldOnB = newNormal;
                            // Reproject collision point along normal. (what about cp.m_distance1?)
                            cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
                            cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);

                        }
                    }
                }
            }
        }
    }

    btNearestPointInLineSegment(contact,v1,v2,nearest);
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
    btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,green);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW

#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
   btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green );
#endif

    if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
        btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW



        btScalar len = (contact-nearest).length();
        if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
        if( bestedge==1 )
        {
            isNearEdge = true;
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
            btDebugDrawLine(tr*nearest,tr*(nearest+tri_normal*10),white);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW

            btVector3 edge(v1-v2);

            isNearEdge = true;

            if (info->m_edgeV1V2Angle == btScalar(0))
            {
                numConcaveEdgeHits++;
            } else
            {
                bool isEdgeConvex = (info->m_flags & TRI_INFO_V1V2_CONVEX)!=0;
                btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
    #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
                btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
    #endif //BT_INTERNAL_EDGE_DEBUG_DRAW

                btVector3 nA = swapFactor * tri_normal;

                btQuaternion orn(edge,info->m_edgeV1V2Angle);
                btVector3 computedNormalB = quatRotate(orn,tri_normal);
                if (info->m_flags & TRI_INFO_V1V2_SWAP_NORMALB)
                    computedNormalB*=-1;
                btVector3 nB = swapFactor*computedNormalB;

#ifdef DEBUG_INTERNAL_EDGE
                {
                    btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
                }
#endif //DEBUG_INTERNAL_EDGE


                btScalar	NdotA = localContactNormalOnB.dot(nA);
                btScalar	NdotB = localContactNormalOnB.dot(nB);
                bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);

                if (backFacingNormal)
                {
                    numConcaveEdgeHits++;
                }
                else
                {
                    numConvexEdgeHits++;
                    btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
                    btVector3 clampedLocalNormal;
                    bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB, info->m_edgeV1V2Angle,clampedLocalNormal);
                    if (isClamped)
                    {
                        if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                        {
                            btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                            //					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                            cp.m_normalWorldOnB = newNormal;
                            // Reproject collision point along normal.
                            cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
                            cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                        }
                    }
                }
            }
        }
    }

    btNearestPointInLineSegment(contact,v2,v0,nearest);
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
    btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,blue);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
   btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue );
#endif

    if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
    {

#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
        btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW

        btScalar len = (contact-nearest).length();
        if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
        if( bestedge==2 )
        {
            isNearEdge = true;
#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
            btDebugDrawLine(tr*nearest,tr*(nearest+tri_normal*10),white);
#endif //BT_INTERNAL_EDGE_DEBUG_DRAW

            btVector3 edge(v2-v0);

            if (info->m_edgeV2V0Angle==btScalar(0))
            {
                numConcaveEdgeHits++;
            } else
            {

                bool isEdgeConvex = (info->m_flags & TRI_INFO_V2V0_CONVEX)!=0;
                btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
    #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
                btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
    #endif //BT_INTERNAL_EDGE_DEBUG_DRAW

                btVector3 nA = swapFactor * tri_normal;
                btQuaternion orn(edge,info->m_edgeV2V0Angle);
                btVector3 computedNormalB = quatRotate(orn,tri_normal);
                if (info->m_flags & TRI_INFO_V2V0_SWAP_NORMALB)
                    computedNormalB*=-1;
                btVector3 nB = swapFactor*computedNormalB;

#ifdef DEBUG_INTERNAL_EDGE
                {
                    btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
                }
#endif //DEBUG_INTERNAL_EDGE

                btScalar	NdotA = localContactNormalOnB.dot(nA);
                btScalar	NdotB = localContactNormalOnB.dot(nB);
                bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);

                if (backFacingNormal)
                {
                    numConcaveEdgeHits++;
                }
                else
                {
                    numConvexEdgeHits++;
                    //				printf("hitting convex edge\n");


                    btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
                    btVector3 clampedLocalNormal;
                    bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB,info->m_edgeV2V0Angle,clampedLocalNormal);
                    if (isClamped)
                    {
                        if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                        {
                            btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                            //					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                            cp.m_normalWorldOnB = newNormal;
                            // Reproject collision point along normal.
                            cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
                            cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                        }
                    }
                }
            }


        }
    }

#ifdef DEBUG_INTERNAL_EDGE
    {
        btVector3 color(0,1,1);
        btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+cp.m_normalWorldOnB*10,color);
    }
#endif //DEBUG_INTERNAL_EDGE

    if (isNearEdge)
    {

        if (numConcaveEdgeHits>0)
        {
            if ((normalAdjustFlags & BT_TRIANGLE_CONCAVE_DOUBLE_SIDED)!=0)
            {
                //fix tri_normal so it pointing the same direction as the current local contact normal
                if (tri_normal.dot(localContactNormalOnB) < 0)
                {
                    tri_normal *= -1;
                }
                cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis()*tri_normal;
            } else
            {
                btVector3 newNormal = tri_normal *frontFacing;
                //if the tri_normal is pointing opposite direction as the current local contact normal, skip it
                btScalar d = newNormal.dot(localContactNormalOnB) ;
                if (d< 0)
                {
                    return;
                }
                //modify the normal to be the triangle normal (or backfacing normal)
                cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() *newNormal;
            }

            // Reproject collision point along normal.
            cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
            cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
        }
    }
}
void 												
World::build(void) {
	int num_samples = 1;
	  
	vp.set_hres(600);
	vp.set_vres(600);
	vp.set_pixel_size(0.5);
	vp.set_samples(num_samples);  
	
	tracer_ptr = new RayCast(this);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 10000);
	pinhole_ptr->set_lookat(0.0);   
	pinhole_ptr->set_view_distance(15000);	
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
	
	Directional* light_ptr = new Directional;
	light_ptr->set_direction(100, 100, 200);
	light_ptr->scale_radiance(3.0); 			
	add_light(light_ptr);
	
		
	// colors

	float a = 0.75;  // scaling factor for yellow, orange, and light green
	
	RGBColor yellow(a * 1, a * 1, 0);								// yellow
	RGBColor brown(0.71, 0.40, 0.16);								// brown
	RGBColor dark_green(0.0, 0.41, 0.41);							// dark_green
	RGBColor orange(a * 1, a * 0.75, 0);							// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor light_green(a * 0.65, a * 1, a * 0.30);				// light green
	RGBColor dark_yellow(0.61, 0.61, 0);							// dark yellow
	RGBColor light_purple(0.65, 0.3, 1);							// light purple
	RGBColor dark_purple(0.5, 0, 1);								// dark purple
	
	
	// Phong materials' reflection coefficients
	
	float ka 	= 0.25;
	float kd 	= 0.75;
	float ks 	= 0.1;
	float exp 	= 10;
		
	// spheres
	
	Phong* phong_ptr1 = new Phong;
	phong_ptr1->set_ka(ka);	
	phong_ptr1->set_kd(kd);
	phong_ptr1->set_ks(ks);
	phong_ptr1->set_exp(exp);
	phong_ptr1->set_cd(yellow);
					
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(phong_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	
	Phong* phong_ptr2 = new Phong;
	phong_ptr2->set_ka(ka);	
	phong_ptr2->set_kd(kd);
	phong_ptr2->set_ks(ks);
	phong_ptr2->set_exp(exp);
	phong_ptr2->set_cd(brown);
	
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(phong_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Phong* phong_ptr3 = new Phong;
	phong_ptr3->set_ka(ka);	
	phong_ptr3->set_kd(kd);
	phong_ptr3->set_ks(ks);
	phong_ptr3->set_exp(exp);
	phong_ptr3->set_cd(dark_green);
		
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(phong_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	
	Phong* phong_ptr4 = new Phong;
	phong_ptr4->set_ka(ka);	
	phong_ptr4->set_kd(kd);
	phong_ptr4->set_ks(ks);
	phong_ptr4->set_exp(exp);
	phong_ptr4->set_cd(orange);
	
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(phong_ptr4);								// orange
	add_object(sphere_ptr4);
	
	
	Phong* phong_ptr5 = new Phong;
	phong_ptr5->set_ka(ka);	
	phong_ptr5->set_kd(kd);
	phong_ptr5->set_ks(ks);
	phong_ptr5->set_exp(exp);
	phong_ptr5->set_cd(green);
	
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(phong_ptr5);								// green
	add_object(sphere_ptr5);
	
	
	Phong* phong_ptr6 = new Phong;
	phong_ptr6->set_ka(ka);	
	phong_ptr6->set_kd(kd);
	phong_ptr6->set_ks(ks);
	phong_ptr6->set_exp(exp);
	phong_ptr6->set_cd(light_green);
	
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(phong_ptr6);								// light green
	add_object(sphere_ptr6);
	
	
	Phong* phong_ptr7 = new Phong;
	phong_ptr7->set_ka(ka);	
	phong_ptr7->set_kd(kd);
	phong_ptr7->set_ks(ks);
	phong_ptr7->set_exp(exp);
	phong_ptr7->set_cd(green);
	
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(phong_ptr7);   							// green
	add_object(sphere_ptr7);
	
	
	Phong* phong_ptr8 = new Phong;
	phong_ptr8->set_ka(ka);	
	phong_ptr8->set_kd(kd);
	phong_ptr8->set_ks(ks);
	phong_ptr8->set_exp(exp);
	phong_ptr8->set_cd(brown);
	
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(phong_ptr8);								// brown
	add_object(sphere_ptr8);
	
	
	Phong* phong_ptr9 = new Phong;
	phong_ptr9->set_ka(ka);	
	phong_ptr9->set_kd(kd);
	phong_ptr9->set_ks(ks);
	phong_ptr9->set_exp(exp);
	phong_ptr9->set_cd(light_green);
	
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(phong_ptr9);								// light green
	add_object(sphere_ptr9);
	
	
	Phong* phong_ptr10 = new Phong;
	phong_ptr10->set_ka(ka);	
	phong_ptr10->set_kd(kd);
	phong_ptr10->set_ks(ks);
	phong_ptr10->set_exp(exp);
	phong_ptr10->set_cd(dark_green);
			
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(phong_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	
	Phong* phong_ptr11 = new Phong;
	phong_ptr11->set_ka(ka);	
	phong_ptr11->set_kd(kd);
	phong_ptr11->set_ks(ks);
	phong_ptr11->set_exp(exp);
	phong_ptr11->set_cd(dark_yellow);
	
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(phong_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	
	Phong* phong_ptr12 = new Phong;
	phong_ptr12->set_ka(ka);	
	phong_ptr12->set_kd(kd);
	phong_ptr12->set_ks(ks);
	phong_ptr12->set_exp(exp);
	phong_ptr12->set_cd(dark_yellow);
	
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(phong_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	
	Phong* phong_ptr13 = new Phong;
	phong_ptr13->set_ka(ka);	
	phong_ptr13->set_kd(kd);
	phong_ptr13->set_ks(ks);
	phong_ptr13->set_exp(exp);
	phong_ptr13->set_cd(dark_yellow);
			
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(phong_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	
	Phong* phong_ptr14 = new Phong;
	phong_ptr14->set_ka(ka);	
	phong_ptr14->set_kd(kd);
	phong_ptr14->set_ks(ks);
	phong_ptr14->set_exp(exp);
	phong_ptr14->set_cd(dark_green);
		
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(phong_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	
	Phong* phong_ptr15 = new Phong;
	phong_ptr15->set_ka(ka);	
	phong_ptr15->set_kd(kd);
	phong_ptr15->set_ks(ks);
	phong_ptr15->set_exp(exp);
	phong_ptr15->set_cd(brown);
		
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(phong_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	
	Phong* phong_ptr16 = new Phong;
	phong_ptr16->set_ka(ka);	
	phong_ptr16->set_kd(kd);
	phong_ptr16->set_ks(ks);
	phong_ptr16->set_exp(exp);
	phong_ptr16->set_cd(light_purple);
	
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(phong_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	
	Phong* phong_ptr17 = new Phong;
	phong_ptr17->set_ka(ka);	
	phong_ptr17->set_kd(kd);
	phong_ptr17->set_ks(ks);
	phong_ptr17->set_exp(exp);
	phong_ptr17->set_cd(brown);
	
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(phong_ptr17);							// browm
	add_object(sphere_ptr17);
	
	
	Phong* phong_ptr18 = new Phong;
	phong_ptr18->set_ka(ka);	
	phong_ptr18->set_kd(kd);
	phong_ptr18->set_ks(ks);
	phong_ptr18->set_exp(exp);
	phong_ptr18->set_cd(dark_purple);
	
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(phong_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	
	Phong* phong_ptr19 = new Phong;
	phong_ptr19->set_ka(ka);	
	phong_ptr19->set_kd(kd);
	phong_ptr19->set_ks(ks);
	phong_ptr19->set_exp(exp);
	phong_ptr19->set_cd(dark_green);
	
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(phong_ptr19);							// dark green
	add_object(sphere_ptr19);
	
	
	Phong* phong_ptr20 = new Phong;
	phong_ptr20->set_ka(ka);	
	phong_ptr20->set_kd(kd);
	phong_ptr20->set_ks(ks);
	phong_ptr20->set_exp(exp);
	phong_ptr20->set_cd(brown);

	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(phong_ptr20);							// browm
	add_object(sphere_ptr20);
	
	
	Phong* phong_ptr21 = new Phong;
	phong_ptr21->set_ka(ka);	
	phong_ptr21->set_kd(kd);
	phong_ptr21->set_ks(ks);
	phong_ptr21->set_exp(exp);
	phong_ptr21->set_cd(light_purple);
	 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(phong_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	
	Phong* phong_ptr22 = new Phong;
	phong_ptr22->set_ka(ka);	
	phong_ptr22->set_kd(kd);
	phong_ptr22->set_ks(ks);
	phong_ptr22->set_exp(exp);
	phong_ptr22->set_cd(light_purple);
	
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(phong_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	
	Phong* phong_ptr23 = new Phong;
	phong_ptr23->set_ka(ka);	
	phong_ptr23->set_kd(kd);
	phong_ptr23->set_ks(ks);
	phong_ptr23->set_exp(exp);
	phong_ptr23->set_cd(dark_purple);
	
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(phong_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	
	Phong* phong_ptr24 = new Phong;
	phong_ptr24->set_ka(ka);	
	phong_ptr24->set_kd(kd);
	phong_ptr24->set_ks(ks);
	phong_ptr24->set_exp(exp);
	phong_ptr24->set_cd(light_purple);
	 
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(phong_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	
	Phong* phong_ptr25 = new Phong;
	phong_ptr25->set_ka(ka);	
	phong_ptr25->set_kd(kd);
	phong_ptr25->set_ks(ks);
	phong_ptr25->set_exp(exp);
	phong_ptr25->set_cd(green);
	
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(phong_ptr25);					 		// green
	add_object(sphere_ptr25);
	
	
	Phong* phong_ptr26 = new Phong;
	phong_ptr26->set_ka(ka);	
	phong_ptr26->set_kd(kd);
	phong_ptr26->set_ks(ks);
	phong_ptr26->set_exp(exp);
	phong_ptr26->set_cd(light_purple);
	  
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(phong_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	
	Phong* phong_ptr27 = new Phong;
	phong_ptr27->set_ka(ka);	
	phong_ptr27->set_kd(kd);
	phong_ptr27->set_ks(ks);
	phong_ptr27->set_exp(exp);
	phong_ptr27->set_cd(light_purple);
	
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(phong_ptr27);							// light purple
	add_object(sphere_ptr27);
	
		
	Phong* phong_ptr28 = new Phong;
	phong_ptr28->set_ka(ka);	
	phong_ptr28->set_kd(kd);
	phong_ptr28->set_ks(ks);
	phong_ptr28->set_exp(exp);
	phong_ptr28->set_cd(dark_purple);
	 
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(phong_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	
	
	Phong* phong_ptr29 = new Phong;
	phong_ptr29->set_ka(ka);	
	phong_ptr29->set_kd(kd);
	phong_ptr29->set_ks(ks);
	phong_ptr29->set_exp(exp);
	phong_ptr29->set_cd(dark_purple);
	
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(phong_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	
	Phong* phong_ptr30 = new Phong;
	phong_ptr30->set_ka(ka);	
	phong_ptr30->set_kd(kd);
	phong_ptr30->set_ks(ks);
	phong_ptr30->set_exp(exp);
	phong_ptr30->set_cd(dark_purple);
	
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(phong_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	
	Phong* phong_ptr31 = new Phong;
	phong_ptr31->set_ka(ka);	
	phong_ptr31->set_kd(kd);
	phong_ptr31->set_ks(ks);
	phong_ptr31->set_exp(exp);
	phong_ptr31->set_cd(light_purple);
	
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(phong_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
		
	Phong* phong_ptr32 = new Phong;
	phong_ptr32->set_ka(ka);	
	phong_ptr32->set_kd(kd);
	phong_ptr32->set_ks(ks);
	phong_ptr32->set_exp(exp);
	phong_ptr32->set_cd(green);
	
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(phong_ptr32);							//  green
	add_object(sphere_ptr32);
	
	
	Phong* phong_ptr33 = new Phong;
	phong_ptr33->set_ka(ka);	
	phong_ptr33->set_kd(kd);
	phong_ptr33->set_ks(ks);
	phong_ptr33->set_exp(exp);
	phong_ptr33->set_cd(green);
	
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(phong_ptr33);							// green 
	add_object(sphere_ptr33);
	
	
	Phong* phong_ptr34 = new Phong;
	phong_ptr34->set_ka(ka);	
	phong_ptr34->set_kd(kd);
	phong_ptr34->set_ks(ks);
	phong_ptr34->set_exp(exp);
	phong_ptr34->set_cd(light_purple);
	
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(phong_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	
	Phong* phong_ptr35 = new Phong;
	phong_ptr35->set_ka(ka);	
	phong_ptr35->set_kd(kd);
	phong_ptr35->set_ks(ks);
	phong_ptr35->set_exp(exp);
	phong_ptr35->set_cd(light_purple);
	
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(phong_ptr35);							// light purple
	add_object(sphere_ptr35);
}
예제 #3
0
void
My_TestGLDrawing::InitTest()
{
    _renderIndex = HdRenderIndex::New(&_renderDelegate);
    TF_VERIFY(_renderIndex != nullptr);
    _delegate = new Hdx_UnitTestDelegate(_renderIndex);

    _delegate->SetRefineLevel(_refineLevel);

    // prepare render task
    SdfPath renderSetupTask("/renderSetupTask");
    SdfPath renderTask("/renderTask");
    _delegate->AddRenderSetupTask(renderSetupTask);
    _delegate->AddRenderTask(renderTask);

    // render task parameters.
    HdxRenderTaskParams param
        = _delegate->GetTaskParam(
            renderSetupTask, HdTokens->params).Get<HdxRenderTaskParams>();
    param.enableLighting = true; // use default lighting
    _delegate->SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param));
    _delegate->SetTaskParam(renderTask, HdTokens->collection,
                           VtValue(HdRprimCollection(HdTokens->geometry,
                                   HdReprSelector(_reprName))));

    // prepare scene
    // To ensure that the non-aggregated element index returned via picking, 
    // we need to have at least two cubes with uniform colors.
    GfVec4f red(1,0,0,1), green(0,1,0,1), blue(0,0,1,1),
            yellow(1,1,0,1), magenta(1,0,1,1), cyan(0,1,1,1),
            white(1,1,1,1), black(0,0,0,1);

    GfVec4f faceColors[] = { red, green, blue, yellow, magenta, cyan};
    VtValue faceColor = VtValue(_BuildArray(&faceColors[0],
                                 sizeof(faceColors)/sizeof(faceColors[0])));

    GfVec4f vertColors[] = { white, blue, green, yellow,
                             black, blue, magenta, red};
    VtValue vertColor = VtValue(_BuildArray(&vertColors[0],
                                 sizeof(vertColors)/sizeof(vertColors[0])));

    _delegate->AddCube(SdfPath("/cube0"), _GetTranslate( 5, 0, 5),
                       /*guide=*/false, /*instancerId=*/SdfPath(),
                       /*scheme=*/PxOsdOpenSubdivTokens->catmark,
                       /*color=*/faceColor,
                       /*colorInterpolation=*/HdInterpolationUniform);
    _delegate->AddCube(SdfPath("/cube1"), _GetTranslate(-5, 0, 5),
                       /*guide=*/false, /*instancerId=*/SdfPath(),
                       /*scheme=*/PxOsdOpenSubdivTokens->catmark,
                       /*color=*/faceColor,
                       /*colorInterpolation=*/HdInterpolationUniform);
    _delegate->AddCube(SdfPath("/cube2"), _GetTranslate(-5, 0,-5));
    _delegate->AddCube(SdfPath("/cube3"), _GetTranslate( 5, 0,-5),
                        /*guide=*/false, /*instancerId=*/SdfPath(),
                       /*scheme=*/PxOsdOpenSubdivTokens->catmark,
                       /*color=*/vertColor,
                       /*colorInterpolation=*/HdInterpolationVertex);

    {
        _delegate->AddInstancer(SdfPath("/instancerTop"));
        _delegate->AddCube(SdfPath("/protoTop"),
                         GfMatrix4d(1), false, SdfPath("/instancerTop"));

        std::vector<SdfPath> prototypes;
        prototypes.push_back(SdfPath("/protoTop"));

        VtVec3fArray scale(3);
        VtVec4fArray rotate(3);
        VtVec3fArray translate(3);
        VtIntArray prototypeIndex(3);

        scale[0] = GfVec3f(1);
        rotate[0] = GfVec4f(0);
        translate[0] = GfVec3f(3, 0, 2);
        prototypeIndex[0] = 0;

        scale[1] = GfVec3f(1);
        rotate[1] = GfVec4f(0);
        translate[1] = GfVec3f(0, 0, 2);
        prototypeIndex[1] = 0;

        scale[2] = GfVec3f(1);
        rotate[2] = GfVec4f(0);
        translate[2] = GfVec3f(-3, 0, 2);
        prototypeIndex[2] = 0;

        _delegate->SetInstancerProperties(SdfPath("/instancerTop"),
                                        prototypeIndex,
                                        scale, rotate, translate);
    }

    {
        _delegate->AddInstancer(SdfPath("/instancerBottom"));
        _delegate->AddCube(SdfPath("/protoBottom"),
                         GfMatrix4d(1), false, SdfPath("/instancerBottom"));

        std::vector<SdfPath> prototypes;
        prototypes.push_back(SdfPath("/protoBottom"));

        VtVec3fArray scale(3);
        VtVec4fArray rotate(3);
        VtVec3fArray translate(3);
        VtIntArray prototypeIndex(3);

        scale[0] = GfVec3f(1);
        rotate[0] = GfVec4f(0);
        translate[0] = GfVec3f(3, 0, -2);
        prototypeIndex[0] = 0;

        scale[1] = GfVec3f(1);
        rotate[1] = GfVec4f(0);
        translate[1] = GfVec3f(0, 0, -2);
        prototypeIndex[1] = 0;

        scale[2] = GfVec3f(1);
        rotate[2] = GfVec4f(0);
        translate[2] = GfVec3f(-3, 0, -2);
        prototypeIndex[2] = 0;

        _delegate->SetInstancerProperties(SdfPath("/instancerBottom"),
                                        prototypeIndex,
                                        scale, rotate, translate);
    }

    SetCameraTranslate(GfVec3f(0, 0, -20));

    // XXX: Setup a VAO, the current drawing engine will not yet do this.
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    glBindVertexArray(0);
}
예제 #4
0
파일: main.cpp 프로젝트: CCJY/coliru
constexpr Table MagicFunction(seq<Is...>){
    return {{red(Is)..., green(Is)..., blue(Is)...}};
}
예제 #5
0
파일: Reader.cpp 프로젝트: AsherBond/PDAL
std::vector<Dimension> Reader::getDefaultDimensions()
{
    std::vector<Dimension> output;

    Dimension alpha("Alpha", dimension::UnsignedInteger, 1,
                    "The alpha image channel value associated with this point");
    alpha.setUUID("f3806ee6-e82e-45af-89bd-59b20cda8ffa");
    alpha.setNamespace(s_getName());
    output.push_back(alpha);

    Dimension classification("Classification", dimension::UnsignedInteger, 1,
                             "Classification code 0-255");
    classification.setUUID("845e23ca-fc4b-4dfc-aa71-a40cc2927421");
    classification.setNamespace(s_getName());
    output.push_back(classification);

    Dimension point_source("PointSourceId", dimension::UnsignedInteger, 1,
                           "Flightline number 0-255");
    point_source.setUUID("68c03b56-4248-4cca-ade5-33e90d5c5563");
    point_source.setNamespace(s_getName());
    output.push_back(point_source);

    Dimension point_source2("PointSourceId", dimension::UnsignedInteger, 2,
                            "Flightline number 0-65536");
    point_source2.setUUID("7193bb9f-3ca2-491f-ba18-594321493789");
    point_source2.setNamespace(s_getName());
    output.push_back(point_source2);

    Dimension return_number("ReturnNumber", dimension::UnsignedInteger, 1,
                            "Echo/Return Number.  0 - Only echo. 1 - First of many echo. 2 - Intermediate echo. 3 - Last of many echo.");
    return_number.setUUID("465a9a7e-1e04-47b0-97b6-4f826411bc71");
    return_number.setNamespace(s_getName());
    output.push_back(return_number);

    Dimension return_number2("ReturnNumber", dimension::UnsignedInteger, 2,
                             "Echo/Return Number.  0 - Only echo. 1 - First of many echo. 2 - Intermediate echo. 3 - Last of many echo.");
    return_number2.setUUID("43a1c59d-02ae-4a05-85af-526fae890eb9");
    return_number2.setNamespace(s_getName());
    output.push_back(return_number2);

    Dimension flag("Flag", dimension::UnsignedInteger, 1,
                   "Runtime flag (view visibility)");
    flag.setUUID("583a5904-ee67-47a7-9fba-2f46daf11441");
    flag.setNamespace(s_getName());
    output.push_back(flag);

    Dimension mark("Mark", dimension::UnsignedInteger, 1,
                   "Runtime flag");
    mark.setUUID("e889747c-2f19-4244-b282-b0b223868401");
    mark.setNamespace(s_getName());
    output.push_back(mark);

    Dimension intensity("Intensity", dimension::UnsignedInteger, 2,
                        "Runtime flag");
    intensity.setUUID("beaa015b-20dd-4922-bf1d-da6972596fe6");
    intensity.setNamespace(s_getName());
    output.push_back(intensity);

    Dimension x("X", dimension::SignedInteger, 4,
                "X dimension as a scaled integer");
    x.setUUID("64e530ee-7304-4d6a-9fe4-231b6c960e69");
    x.setNamespace(s_getName());
    output.push_back(x);

    Dimension y("Y", dimension::SignedInteger, 4,
                "Y dimension as a scaled integer");
    y.setUUID("9b4fce29-2846-45fa-be0c-f50228407f05");
    y.setNamespace(s_getName());
    output.push_back(y);

    Dimension z("Z", dimension::SignedInteger, 4,
                "Z dimension as a scaled integer");
    z.setUUID("464cd1f6-5bec-4610-9f25-79e839ee39a6");
    z.setNamespace(s_getName());
    output.push_back(z);

    Dimension red("Red", dimension::UnsignedInteger, 1,
                  "Red color value 0 - 256 ");
    red.setUUID("2157fd43-a492-40e4-a27c-7c37b48bd55c");
    red.setNamespace(s_getName());
    output.push_back(red);

    Dimension green("Green", dimension::UnsignedInteger, 1,
                    "Green color value 0 - 256 ");
    green.setUUID("c9cd71ef-1ce0-48c2-99f8-5b283e598eac");
    green.setNamespace(s_getName());
    output.push_back(green);

    Dimension blue("Blue", dimension::UnsignedInteger, 1,
                   "Blue color value 0 - 256 ");
    blue.setUUID("649f383f-8a7a-4658-ac2a-e1e36cfed05e");
    blue.setNamespace(s_getName());
    output.push_back(blue);

    Dimension time("Time", dimension::UnsignedInteger, 4,
                   "32 bit integer time stamps. Time stamps are assumed to be "
                   "GPS week seconds. The storage format is a 32 bit unsigned "
                   "integer where each integer step is 0.0002 seconds.");
    time.setNumericScale(0.0002);
    time.setNumericOffset(0.0);
    time.setUUID("0dcda772-56da-47f6-b04a-edad72361da9");
    time.setNamespace(s_getName());
    output.push_back(time);
    return output;
}
//--------------------------------------------------------------
void ofApp::setup(){
    numSmallCircles = 41; //11 purple, 7 blue, 5 top right, 11 sleave, 7 but, 14 bottom
    grabbed = false;
    
    
    ofColor purple (161, 99, 128);
    ofColor pink (214, 73, 89);  // 1 pink
    ofColor lightPink (147,131,17);  //2 light pink
    ofColor yellow (212,179,14);  //3 yellow
    ofColor black (44,53,71);  //4 middle black
    ofColor blue (47,96,137);//5 blue
    ofColor green (28,124,92);//6 green
    ofColor orange (228,95,79);//7 orange bottom circles
    ofColor moreYellow (204, 155, 82);
    ofColor orangeLighter (232,105,92);
    ofColor darkBlue (38,81,126);
    
    //purple circle positions 0-11
    circlePositions.push_back(ofPoint(436, 342)); //0
    circlePositions.push_back(ofPoint(446, 358)); //1
    circlePositions.push_back(ofPoint(438, 385)); //2
    circlePositions.push_back(ofPoint(414,352)); //3
    circlePositions.push_back(ofPoint(429, 369)); //4
    circlePositions.push_back(ofPoint(423, 385)); //5
    circlePositions.push_back(ofPoint(425, 395)); //6
    circlePositions.push_back(ofPoint(402,337)); //7
    circlePositions.push_back(ofPoint(403, 376)); //8
    circlePositions.push_back(ofPoint(389, 392)); //9
    circlePositions.push_back(ofPoint(381, 348)); //10
     circlePositions.push_back(ofPoint(382, 365)); //11

    
    for(int i=0; i<11; i++){
       CirclesWoman tempCircle;
        smallCircles.push_back(tempCircle);
    }
    int width = ofRandom(20,30);
    int height = ofRandom(10,20);
    
    smallCircles[1].setup(width, height, pink, lightPink, black, circlePositions[1]);
    smallCircles[2].setup(width, height, purple, yellow, black, circlePositions[2]);
    smallCircles[3].setup(width, height, yellow, pink, black, circlePositions[3]);
    smallCircles[4].setup(width, height, pink, lightPink, black, circlePositions[4]);
    smallCircles[5].setup(width, height, purple, yellow, black, circlePositions[5]);
    smallCircles[6].setup(width, height, yellow, lightPink, black, circlePositions[6]);
    smallCircles[7].setup(width, height, pink, yellow, yellow, circlePositions[7]);
    smallCircles[8].setup(width, height, pink, yellow, black, circlePositions[8]);
    smallCircles[9].setup(width, height, blue, green, green, circlePositions[9]);
    smallCircles[10].setup(width, height, pink, purple, black, circlePositions[10]);
    smallCircles[11].setup(width, height, purple, yellow, black, circlePositions[11]);
    
    //blue circles
    for(int i=11; i<19; i++){
        CirclesWoman tempBlueCircle;
        tempBlueCircle.randomSetup("blue");
         smallCircles.push_back(tempBlueCircle);
        
    }
    //        setup(int _width, int _height, ofColor color1, ofColor color2, ofColor color3 , ofPoint _position)
    
    for(int i=19; i<26; i++){
        CirclesWoman tempButtCircle;
        tempButtCircle.randomSetup("butt");
        smallCircles.push_back(tempButtCircle);
        
    }
    
    for(int i=26; i<41; i++){
        CirclesWoman tempBottomCircle;
        smallCircles.push_back(tempBottomCircle);
    }
    
    smallCircles[26].setup(13.33, 9.33, orange, moreYellow, moreYellow, ofPoint(447,727));
    smallCircles[27].setup(17.33, 18.833, orange, moreYellow, moreYellow, ofPoint(447,738.5));
    smallCircles[28].setup(17.33, 15.75, orange, moreYellow, green, ofPoint(450,753));
    smallCircles[29].setup(16, 11.875, orange, moreYellow, moreYellow, ofPoint(442,769));
    smallCircles[30].setup(17.33, 14.542, orange, moreYellow, green, ofPoint(429,722));
    smallCircles[31].setup(18.267, 14.751, orange, moreYellow, moreYellow, ofPoint(430,733));
    smallCircles[32].setup(24.99, 18.17, orange, orangeLighter, black, ofPoint(430,748));
    smallCircles[33].setup(19.313, 15.34, darkBlue, darkBlue, black, ofPoint(418,762.566));
    smallCircles[34].setup(18.3, 13.602, orange, moreYellow, moreYellow, ofPoint(415.33,720));
    smallCircles[35].setup(23.54, 16.605, orange, orangeLighter, black, ofPoint(408,736));
    smallCircles[36].setup(22, 14, darkBlue, darkBlue, black, ofPoint(389,722));
    smallCircles[37].setup(21, 14, orange, yellow, yellow, ofPoint(385,740));
    smallCircles[38].setup(21, 14, orange, orangeLighter, black, ofPoint(395,750));
    smallCircles[39].setup(21, 18, orange, moreYellow, moreYellow, ofPoint(382,763));
    smallCircles[40].setup(21, 17, orange, moreYellow, moreYellow, ofPoint(404,765));

    
//<-------------- squiggly lines dress ---------------->
    numLines = 30;
    int startingX = 332;
    int endingX = 500;
    int interval = (endingX-startingX)/numLines;
    for(int i=0; i<numLines; i++){
        SquigglyLine tempSquiggle;
        tempSquiggle.setup(startingX + interval*i);
        lines.push_back(tempSquiggle);
    }
    
//<-------------- images ---------------->
    arm.loadImage("arm.png");
    greenCircle.loadImage("green_circle.png");
    orangeBackground.loadImage("orange_background.jpg");
    heads.loadImage("heads.png");
    spiralBackground.loadImage("under_spirals.png");
    background.loadImage("background.jpg");
    man.loadImage("man.png");
    
//<-------------- little squares dress ---------------->
    numLittleSquares = 120;
    for(int i=0; i<numLittleSquares; i++){
        LittleSquares tempSquare;
        tempSquare.setup();
        dressSquares.push_back(tempSquare);
    }
//<-------------- big circles dress ---------------->
    numBigCirclesDress = 10;
//    for(int i=0; i<numBigCirclesDress; i++){
//        bigCirclesDress tempBigCircle;
//        tempBigCircle.setup();
//        bigCircles.push_back(tempBigCircle);
//        
//        
//    }
//
    for(int i=0; i<numBigCirclesDress; i++){
        bigCirclesDress tempBigCircle;
        bigCircles.push_back(tempBigCircle);
    }

    bigCircles[0].setupFixed(ofPoint(411,488),22,16);
    bigCircles[1].setupFixed(ofPoint(412,637),20,16);
    bigCircles[2].setupFixed(ofPoint(457,330),22,14);
    bigCircles[3].setupFixed(ofPoint(417,543),21,15);
    bigCircles[4].setupFixed(ofPoint(342,500),18,11);
    bigCircles[5].setupFixed(ofPoint(377,519),18,13);
    bigCircles[6].setupFixed(ofPoint(449,548),22,16);
    bigCircles[7].setupFixed(ofPoint(388,590),21,15);
    bigCircles[8].setupFixed(ofPoint(392,649),15,11);
    bigCircles[9].setupFixed(ofPoint(465,726),19,15);
    
    //<-------------- spirals ---------------->
    numSpirals = 12;
    
    for(int i=0; i<numSpirals; i++){
        spiral tempSpiral;
        spirals.push_back(tempSpiral);
        //spirals[i].setupRandom();
    }
    
    spirals[0].setup(ofPoint(495,373), 35,35, 4);
    spirals[1].setup(ofPoint(537,355), 52,52, 4);
    spirals[2].setup(ofPoint(560, 506), 40, 38, 4);
    spirals[3].setup(ofPoint(499, 473), 60, 55, 5);
    spirals[4].setup(ofPoint(520, 438), 35, 32, 4);
    spirals[5].setup(ofPoint(553, 414), 29, 29, 3);
    spirals[6].setup(ofPoint(483, 598), 50, 45, 4);
    spirals[7].setup(ofPoint(540, 619), 40, 35, 4);
     spirals[8].setup(ofPoint(595, 554), 34, 32, 3);
     spirals[9].setup(ofPoint(479, 414), 45, 40, 4);
     spirals[10].setup(ofPoint(534, 537), 54, 44, 6);
     spirals[11].setup(ofPoint(490, 530), 36, 31, 4);
//    int posX = 495;
//    float radius = 35;
//    for(var i=0; i<numSpirals; i++){
//        if(posX < 650){
//            posX += numSpirals[i-1].radius/2
//        }
//        spirals[i].setup(ofPoint());
//    }
    
    
}
예제 #7
0
void drawLine(bsCurve cv) {
    float x1, x2, y1, y2, sp, sp2;
    float slope;
    float newx, newy;
    y1 = y2 = x1 = x2 = 0;
    Vector3 red(1,0,0);
    Vector3 green(0,1,0);
    Vector3 color;
    if (cv.ctype == 0)
        color = red;
    else
        color = green;
    for (int i = 0; i < cv.numctrlpts - 1; i++)
    {        
        x1 = cv.ctrlpts[i].x;
        y1 = cv.ctrlpts[i].y;
        x2 = cv.ctrlpts[i + 1].x;
        y2 = cv.ctrlpts[i + 1].y;

        
        
        if(x1 == x2) {
            if (y2 < y1) {
                sp = y1;
                y1 = y2;
                y2 = sp;
            }
            for (int i = y1; i < y2; i++) {
                drawPoint(x1, i, color);
            }
        }
        else if(y1 == y2) {
            if (x2 < x1) {
                sp = x1;
                x1 = x2;
                x2 = sp;
            }
            for (int i = x1; i < x2; i++) {
                drawPoint(i, y1, color);
            }
        }
        else if ((y2-y1)/(x2-x1) <= 1 && (y2-y1)/(x2-x1) >= -1) {
            if(x2 < x1) {
                sp = x1;
                sp2 = y1;
                x1 = x2;
                y1 = y2;
                x2 = sp;
                y2 = sp2;
            }
            slope = (y2-y1)/(x2-x1);
            newy = y1;
            for (int i = x1+1; i < x2; i++) {
                newy += slope;
                drawPoint(i, rounder(newy), color);
            }
        }
        else if ((float)(y2-y1)/(x2-x1) > 1 || (float)(y2-y1)/(x2-x1) < -1) {
            if(y2 < y1) {
                sp = x1;
                sp2 = y1;
                x1 = x2;
                y1 = y2;
                x2 = sp;
                y2 = sp2;
            }
            slope = (x2-x1)/(y2-y1);
            newx = x1;
            for (int i = y1 + 1; i < y2; i++) {
                newx += slope;
                drawPoint(rounder(newx), i, color);
            }
        }
    }
}
예제 #8
0
int main()
{
    Tserial *com;
    char ch;
    com = new Tserial();
    com->connect("COM3", 4800, spNONE);
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int key = 0;
   // com->sendChar('a');
    int pinkx,pinky,yellowx,yellowy,bluey,greeny,violetx,violety,botx,boty,i=0;
    int hb,sb,cb,wb;
    int greenx[21]={1},bluex[21]={1};
    double bottheta,theta2,slope;
    int flag=1,flag1=1,flag2=1;
    
    /* initialize camera */
    capture = cvCaptureFromCAM(0);
    //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 1024 );

    //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 );

    /* always check */
    if ( !capture )
    {     
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }
 
    /* create a window for the video */
    cvNamedWindow( "image", CV_WINDOW_AUTOSIZE );
 
    while( key != 'q' ) 
    {
        /* get a frame */
        img = cvQueryFrame( capture );
      
        /* always check */
        if( !img ) break;
        
        cvErode(img,img,NULL,1);
         cvDilate(img,img,NULL,1);
         cvErode(img,img,NULL,1);
         cvDilate(img,img,NULL,1);
         cvErode(img,img,NULL,1);
         cvDilate(img,img,NULL,1);
        img0=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        imgblue=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        imgpink=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        imgyellow=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        imggreen=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        imgblack=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        
        imgviolet=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        cvCvtColor(img,img0,CV_BGR2HSV);
        cvSetMouseCallback( "image", mouseHandler, img0 );
      // cvThreshold(img0, img0, 85, 255, CV_THRESH_BINARY);
         /*cvErode(img0,img0,NULL,1);
         cvDilate(img0,img0,NULL,1);
         cvErode(img0,img0,NULL,1);
         cvDilate(img0,img0,NULL,1);
         cvErode(img0,img0,NULL,1);
         cvDilate(img0,img0,NULL,1);*/
        /* display curent frame */
        cvShowImage( "image", img );
        pinkx=pink(img0,1);
        yellowx=yellow(img0,1);
        for(i=20;i>0;i--)
                          {
                               bluex[i]=bluex[i-1];
                           
                           }
        bluex[0]=blue(img0,1);
        for(i=20;i>0;i--)
                          {
                               greenx[i]=greenx[i-1];
                           
                           }
        greenx[0]=green(img0,1);
        violetx=violet(img0,1);
        black(img,1);
        uchar* datablack=(uchar*)imgblack->imageData;
         hb=img0->height;
          wb=img0->width;
          cb=img0->nChannels;
          sb=img0->widthStep;
          uchar* datablue=(uchar*)imgblue->imageData;
          uchar* datayellow=(uchar*)imgyellow->imageData;
        pinky=pink(img0,0);
        yellowy=yellow(img0,0);
        bluey=blue(img0,0);
        greeny=green(img0,0);
        violety=violet(img0,0);
        
        cvShowImage( "imageblue", imgblue ); 
        cvShowImage( "imagepink", imgpink );
        cvShowImage( "imageyellow", imgyellow );
        cvShowImage( "imagegreen", imggreen );
        cvShowImage( "imageblack", imgblack );
        cvShowImage( "imageviolet", imgviolet );
        
        
        botx=pinkx-violetx;
        boty=pinky-violety;
        bottheta=atan((double)boty/(double)botx)*180/PI;
         if(pinky>giy && pinky<gfy && pinkx < 225&& flag2==1){
                   if(greenx[0]-greenx[20]>1 && greenx[0]>gix ){
                                           com->sendChar('F');
                                           printf("1");
                                           flag2=0;
                                           } 
                   else{
                                           com->sendChar('s');
                                           printf("stop");
                                           }
        }
        
        else if(bottheta<45 && bottheta >-45 && pinkx>violetx && flag==1){//right
                       flag1=1;
                        printf("right\n");
                       if(datablack[pinky*sb+(pinkx+l)*cb+0]!=0)
                       {
                                   if(bottheta >20)
                                   {
                                               com->sendChar('l');
                                               printf("R\n");
                                   }
                                   else if (bottheta <-20)
                                   {
                                        com->sendChar('r');
                                         printf("L\n");
                                   }
                                   else if(bottheta >10)
                                   {
                                               com->sendChar('r');
                                                printf("r\n");
                                   }
                                   else if (bottheta <-10)
                                   {
                                        com->sendChar('l');
                                         printf("l\n");
                                   }
                                   
                                   else
                                   {
                                       com->sendChar('F');
                                        printf("F\n");
                                   }
                       }
                                   
                       else if(datablack[pinky*sb+(pinkx+l)*cb+0]==0)
                       {
                                  if((pinky-m)>0){                             
                                  if(datablack[(pinky-m)*sb+(pinkx)*cb+0]!=0)
                                  {
                                        com->sendChar('L');
                                         printf("Left\n");
                                        flag=0;
                                  }
                                  else if((pinky+m)<479){
                                   if(datablack[(pinky+m)*sb+(pinkx)*cb+0]!=0)
                                  {
                                        com->sendChar('R');
                                         printf("Right\n");
                                        flag=0;
                                  }
                                  }
                                  }
                                  
                       }
                                   
               }
               
               
               else if((bottheta>45 || 180+bottheta <135) && pinky > violety && flag1==1){//back                 
                                   flag=1;
                                    printf("back\n");
                                    if((pinky+n)<479){
                          if(datablack[(pinky+n)*sb+(pinkx)*cb+0]!=0&&(pinky+l)<479)
                          {
                                   if(bottheta <75 && bottheta>45)
                                   {
                                               com->sendChar('r');
                                                printf("R\n");
                                   }
                                   else if (180+bottheta >105&&180+bottheta <135)
                                   {
                                        com->sendChar('l');
                                         printf("L\n");
                                   }
                                   else if(bottheta <85&&bottheta>45)
                                   {
                                               com->sendChar('e');
                                                printf("r\n");
                                   }
                                   else if (180+bottheta >95 && 180+bottheta <135)
                                   {
                                        com->sendChar('d');
                                         printf("l\n");
                                   }
                                   
                                   else
                                   {
                                       com->sendChar('F');
                                        printf("F\n");
                                   }
                       }
                              
                       else if(datablack[(pinky+n)*sb+(pinkx)*cb+0]==0)
                       {
                                   if((pinkx-m)>0){                             
                                  if(datablack[(pinky)*sb+(pinkx-m)*cb+0]!=0)
                                  {
                                        com->sendChar('R');
                                         printf("Right\n");
                                        flag1=0;
                                  }
                                  else if(datablack[(pinky)*sb+(pinkx+m)*cb+0]!=0)
                                  {
                                        com->sendChar('L');
                                         printf("Left\n");
                                        flag1=0;
                                  }
                                  }
                                  
                       }
                       }
                                   
                    
                    }
              else if(180+bottheta>135 && 180+bottheta < 225 && pinkx<violetx && flag==1){//left
                       flag1=1;
                        printf("left\n");
                        if((pinkx-l) >0){
                       if(datablack[pinky*sb+(pinkx-l)*cb+0]!=0)
                       {
                                   if(180+bottheta <160)
                                   {
                                               com->sendChar('r');
                                               printf("R\n");
                                   }
                                   else if (180+bottheta >200)
                                   {
                                        com->sendChar('l');
                                        printf("L\n");
                                   }
                                   else if(180+bottheta <170)
                                   {
                                               com->sendChar('e');
                                               printf("r\n");
                                   }
                                   else if (180+bottheta>190)
                                   {
                                        com->sendChar('d');
                                        printf("l\n");
                                   
                                   }
                                   
                                   else
                                   {
                                       com->sendChar('F');
                                       printf("F\n");
                                   }
                       }
                                   
                       else if(datablack[pinky*sb+(pinkx-l)*cb+0]==0)
                       {
                                  if((pinky-m)>0&&pinky+m<479){                              
                                  
                                  
                                  if(datablack[(pinky-m)*sb+(pinkx)*cb+0]!=0)
                                  {
                                        com->sendChar('R');
                                        printf("Right\n");
                                        flag=0;
                                  }
                                  else if(datablack[(pinky+m)*sb+(pinkx)*cb+0]!=0)
                                  {
                                        com->sendChar('L');
                                        printf("Left\n");
                                        flag=0;
                                  }
                                  }
                                  
                       }
                       }
                                   
               }
        
              
               else if((180+bottheta > 225 || bottheta < -45)  && pinky < violety && flag1==1){//straight                              
                                   flag=1;
                                   printf("straight\n");
                                   if((pinky-l)>0 || pinky<125){
                                   if(datablack[(pinky-l)*sb+(pinkx)*cb+0]!=0)
                                   {
                                      if((180+bottheta <250) && (180+bottheta > 225))
                                   {
                                               com->sendChar('r');
                                               printf("R\n");
                                   }
                                   else if ((bottheta > -70) && (bottheta < -45))
                                   {
                                        com->sendChar('l');
                                        printf("L\n");
                                   }
                                   else if((180+bottheta <260) && (180+bottheta > 225))
                                   {
                                               com->sendChar('e');
                                               printf("r\n");
                                   }
                                   else if ((bottheta > -80) && (bottheta < -45))
                                   {
                                        com->sendChar('d');
                                        printf("l\n");
                                   }
                                   
                                   else if((pinkx > bix && pinky < biy)==0)
                                   {
                                       com->sendChar('F');
                                       printf("F\n");
                                   }
                                   else{
                                        if(((datablue[(pinky-40)*sb+(pinkx-30)*cb+0]!=0)&&(bluex[20]-bluex[0]<0)))
                                        {
                                                                                 com->sendChar('F');
                                                                                 printf("blueforward\n");
                                                                                 
                                        }
                                        else{
                                                                                 com->sendChar('s');
                                                                                 printf("bluesstop\n");
                                             }
                                        
                                        }
                       }
                                   
                       else if(datablack[(pinky-l)*sb+(pinkx)*cb+0]==0)
                       {
                                                                
                                  if((pinkx-l)> 0){
                                  
                                  if(datablack[(pinky)*sb+(pinkx+m)*cb+0]!=0)
                                  {
                                        com->sendChar('R');
                                        printf("Right\n");
                                        flag1=0;
                                  }
                                  else if(datablack[(pinky)*sb+(pinkx-m)*cb+0]!=0)
                                  {
                                        com->sendChar('L');
                                        printf("Left\n");
                                        flag1=0;
                                  }
                                  }
                       }
                       }
                                   
                    
                    }
        
        
        
        
        
        
        key = cvWaitKey(1);
        cvReleaseImage(&img0);
        //cvReleaseImage(&img);
        cvReleaseImage(&imgblue);
        cvReleaseImage(&imgpink);
        cvReleaseImage(&imgyellow);
        cvReleaseImage(&imggreen);
        cvReleaseImage(&imgblack);
        cvReleaseImage(&imgviolet);
        
     }


    /* free memory */
    cvDestroyWindow( "image" );
    cvDestroyWindow( "imageblue");
    cvDestroyWindow( "imagepink");
    cvDestroyWindow( "imageyellow");
    cvDestroyWindow( "imageblack");
    cvDestroyWindow( "imagegreen");
    cvDestroyWindow( "imageviolet");
    cvReleaseCapture( &capture );
    com->disconnect();
    return 0;
}