Exemplo n.º 1
0
void restartMatch(void)
{
    gettimeofday(&Initial_Timer, NULL);

    MatrixCoord startGraphCoord = MatrixCoord(0, 0);
    MatrixCoord goalGraphCoord = MatrixCoord(Graph_Space.size().x-1, Graph_Space.size().y-1);

    for (unsigned int i=0; i<Player_List.size(); ++i) {
        if (Player_List[i]) {
            delete Player_List[i];
        }
    }
    Player_List.clear();
    Player_List = std::vector<PlayerBase*>(Config_Info.playerConfigs.size());

    float runSpeed = 0.2f;

    for (unsigned int i=0; i<Config_Info.playerConfigs.size(); ++i) {
        if (Config_Info.playerConfigs[i].type == HUMAN) {
            human = new Human(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                              startGraphCoord, goalGraphCoord, Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                              glmaze.aabb, Tilesize);
            Player_List[i] = human;
            humanIndex = i;
        }
        else if (Config_Info.playerConfigs[i].type == AI_DFS) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         randomDFSPath(Graph_Space, startGraphCoord, goalGraphCoord), Tilesize);
        }
        else if (Config_Info.playerConfigs[i].type == AI_SMART) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         smartEnhancePath(randomDFSPath(Graph_Space, startGraphCoord, goalGraphCoord)), Tilesize);
        }
        else if (Config_Info.playerConfigs[i].type == AI_DUMB) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         dumbPath(Graph_Space, startGraphCoord, goalGraphCoord), Tilesize);
        }
    }
    finishedPlayers = std::vector<int>(Config_Info.playerConfigs.size(), 0);

    glm::vec3 startcone = tileSpaceToWorldSpace(MatrixCoord(1,1), Tilesize, Tilesize/2.0f);
    glm::vec3 endcone = tileSpaceToWorldSpace(tileSpace.size()-MatrixCoord(2,2), Tilesize, Tilesize/2.0f);
    cone1 = Cone(Resources_Manager.mesh("cone.obj"), Resources_Manager.texture("startmark.tga"), startcone);
    cone2 = Cone(Resources_Manager.mesh("cone.obj"), Resources_Manager.texture("finishmark.tga"), endcone);

    winners.clear();
    toggleCameraButton->show = false;
    Camera_Mode = humanIndex;

}
Exemplo n.º 2
0
void Cone_api(const mxArray * const prhs[3], const mxArray *plhs[1])
{
  emxArray_real_T *x;
  emxArray_real_T *spacePoints;
  emxArray_real_T *t;
  emxArray_real_T *vals;
  emlrtStack st = { NULL, NULL, NULL };

  st.tls = emlrtRootTLSGlobal;
  emlrtHeapReferenceStackEnterFcnR2012b(&st);
  emxInit_real_T(&st, &x, 2, &ub_emlrtRTEI, true);
  emxInit_real_T(&st, &spacePoints, 2, &ub_emlrtRTEI, true);
  emxInit_real_T(&st, &t, 2, &ub_emlrtRTEI, true);
  emxInit_real_T(&st, &vals, 2, &ub_emlrtRTEI, true);

  /* Marshall function inputs */
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[0]), "x", x);
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "spacePoints", spacePoints);
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "t", t);

  /* Invoke the target function */
  Cone(&st, x, spacePoints, t, vals);

  /* Marshall function outputs */
  plhs[0] = e_emlrt_marshallOut(vals);
  vals->canFreeData = false;
  emxFree_real_T(&vals);
  t->canFreeData = false;
  emxFree_real_T(&t);
  spacePoints->canFreeData = false;
  emxFree_real_T(&spacePoints);
  x->canFreeData = false;
  emxFree_real_T(&x);
  emlrtHeapReferenceStackLeaveFcnR2012b(&st);
}
Exemplo n.º 3
0
//This sets a collisionMask as the cone vision object
collisionObject::collisionObject(Vec3f negX, Vec3f posX, Vec3f posZ, Vec3f Size, Vec3f CenterPos)
{
	theCone = Cone(negX, posX, posZ, Size, CenterPos);

	collisionType = 4;
	updatePos = true;
}
Exemplo n.º 4
0
static void render_image(void)
{
   GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
   GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
   GLfloat red_mat[]   = { 1.0, 0.2, 0.2, 1.0 };
   GLfloat green_mat[] = { 0.2, 1.0, 0.2, 1.0 };
   GLfloat blue_mat[]  = { 0.2, 0.2, 1.0, 1.0 };


   glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
   glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(-2.5, 2.5, -2.5, 2.5, -10.0, 10.0);
   glMatrixMode(GL_MODELVIEW);

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   glPushMatrix();
   glRotatef(20.0, 1.0, 0.0, 0.0);

   glPushMatrix();
   glTranslatef(-0.75, 0.5, 0.0); 
   glRotatef(90.0, 1.0, 0.0, 0.0);
   glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
   Torus(0.275, 0.85, 20, 20);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(-0.75, -0.5, 0.0); 
   glRotatef(270.0, 1.0, 0.0, 0.0);
   glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
   Cone(1.0, 2.0, 16, 1);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(0.75, 0.0, -1.0); 
   glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
   Sphere(1.0, 20, 20);
   glPopMatrix();

   glPopMatrix();

   /* This is very important!!!
    * Make sure buffered commands are finished!!!
    */
   glFinish();
}
Exemplo n.º 5
0
int main()
{
    //set up basisvectors
    std::vector<std::vector<double> > basis(2,std::vector<double>(2));
    basis[0][0] = 1;
    basis[0][1] = 0;
    basis[1][0] = 0;
    basis[1][1] = 1;
    
    
    //define lattice
    Lattice myLattice(2,basis);
    
    //set up cones
    
    Cone Sigma0 = Cone({{1,0},{0,1}},myLattice);
    Cone Sigma11 = Cone({{0,1},{-1,0}},myLattice);
    Cone Sigma12 = Cone({{-1,0},{-1,-1}},myLattice);
    Cone Sigma13 = Cone({{-1,-1},{-2,-3}},myLattice);
    Cone Sigma21 = Cone({{-2,-3},{-1,-2}},myLattice);
    Cone Sigma22 = Cone({{-1,-2},{0,-1}},myLattice);
    Cone Sigma23 = Cone({{0,-1},{1,0}},myLattice);
    
    //Define fan
    std::vector<Cone> myCones = {Sigma0, Sigma11, Sigma12, Sigma13, Sigma21, Sigma22, Sigma23};
    Fan myFan(myCones,myLattice);
    
    //Get dual fan
    Fan myDualFan = myFan.getCorrespondingDualFan();
    
    
    std::vector<Cone> myDualCones = myDualFan.getCones();
    std::cout << "CONES OF THE DUAL FAN" << std::endl;
    std::cout << "----------------------" << std::endl;
    for(int i = 0; i < myDualCones.size();++i)
    {
        std::cout << "Cone nr = " << i  << std::endl;
        Cone myDualCone = myDualCones[i];
        std::vector<std::vector<double> > myBVs = myDualCone.getBasisVectors();
        std::cout << "        " << myBVs[0][0] << std::endl;
        std::cout << "Ray 1 = " << myBVs[0][1] << std::endl;
        std::cout << "        " << myBVs[0][2] << std::endl;
        std::cout << "" << std::endl;
        std::cout << "        " << myBVs[1][0] << std::endl;
        std::cout << "Ray 2 = " << myBVs[1][1] << std::endl;
        std::cout << "        " << myBVs[1][2] << std::endl;
        std::cout << "----------------------" << std::endl;
    }
    
    myFan.drawFan();
    myDualFan.drawFan();
  
    return 0;
}
Exemplo n.º 6
0
bool Cone::intersects(const Sphere& b) const {
    // If the bounding sphere contains the tip, then
    // they definitely touch.
    if (b.contains(this->tip)) {
        return true;
    }

    // Move the tip backwards, effectively making the cone bigger
    // to account for the radius of the sphere.

    Vector3 tip = this->tip - direction * b.radius / sinf(angle);

    return Cone(tip, direction, angle).contains(b.center);
}
Exemplo n.º 7
0
void AirPlane(float x, float y, float z)
{
	static float i = 0, f = 0;
	i += 0.1;
	f += 0.01;
	if (i > 360)
		i = 0;
	if (f > 360)
		f = 0;
	glPushMatrix();
	glTranslatef(x, y, z);
	glRotatef(f, 1, 1, 1);

	glPushMatrix();
	glColor3f(0.5, 1.5, 0.5);
	glRotatef(i, 0, 1, 0);
	glTranslatef(0, 0, 0.5);
	glScalef(0.1, 0.05, 1);
	Cube(); //螺旋桨
	glPopMatrix();

	glTranslatef(0, -0.1, 0);
	glScalef(0.1, 0.1, 0.1);
	Cube();
	glScalef(10, 10, 10);

	glColor3f(1, 0, 1);
	glTranslatef(0.04, -0.05, -0.9);
	glScalef(0.1, 0.1, 1.5);
	Cylinder();
	glColor3f(0, 1, 0);
	glScalef(1, 1, 0.2);
	Cone();
	glColor3f(0, 1, 1);
	glTranslatef(0, 0.7, -4.5);
	glScalef(0.2, 2, 1);
	Cube();

	glTranslatef(-13, 0.3, 0);
	glScalef(27, 0.1, 1);
	Cube();

	glPopMatrix();
}
Exemplo n.º 8
0
void IntersectionUI::writeTest() const {
    // creates a deterministic sequence of ray positions and directions
    // and writes the resulting intersections to a file
    // you must add the proper intersect calls for this file to be generated
    
    double invBase[5] = {1.0 / 2.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 7.0, 1.0 / 11.0};
    double values[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
    std::ofstream file("../intersections.txt");
    file.precision(4);

    const int seed = static_cast<int>(intersectionUI->m_iSeed->value());
    // generate a halton sequence to pick position/ray combinations
    // skip the first 'seed' values
    for (int i = 0; i < seed; i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
    }
    for (int i = seed; i < (seed + 1638); i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
        // create the ray from the five random values
        // compute ray origin
        Point3 p;
        p[0] = values[4] * sin(values[0] * M_PI) * cos(values[1] * 2.0 * M_PI);
        p[1] = values[4] * sin(values[0] * M_PI) * sin(values[1] * 2.0 * M_PI);
        p[2] = values[4] * cos(values[0] * M_PI);
        // compute ray direction
        Vector3 dir;
        dir[0] = sin(values[2] * M_PI) * cos(values[3] * 2.0 * M_PI);
        dir[1] = sin(values[2] * M_PI) * sin(values[3] * 2.0 * M_PI);
        dir[2] = cos(values[2] * M_PI);
        
        HitRecord cubeHr, cylinderHr, coneHr, sphereHr;
        // ToDo: intersect with your shapes here and store the result
        // in the appropriate hit record
        //cube.intersect(p, dir);
		Cube cube = Cube(1);
		cubeHr = *(cube.intersect(p, dir));
        //cylinder.intersect(p, dir);
		Cylinder cylinder = Cylinder(1, 1);
		cylinderHr = *(cylinder.intersect(p, dir));
        //coneHr = cone.intersect(p, dir);
		Cone cone = Cone(1, 1);
		coneHr = *(cone.intersect(p, dir));
        //sphereHr = sphere.intersect(p, dir);
		Sphere sphere = Sphere(1);
		sphereHr = *(sphere.intersect(p, dir));

        // write out
        file << i << " Cube     " << cubeHr     << std::endl;
        file << i << " Cylinder " << cylinderHr << std::endl;
        file << i << " Cone     " << coneHr     << std::endl;
        file << i << " Sphere   " << sphereHr   << std::endl;
    }
    file.close();
}
Exemplo n.º 9
0
 Cone Cone::GetTranslated(const NX::vector<float, 3> &T) const{
     return Cone(*this).Translate(T);
 }
Exemplo n.º 10
0
 Cone Cone::GetTransformed(const NX::vector<float, 3>    &T, const NX::Matrix<float, 3, 3> &R) const{
     return Cone(*this).Transform(T, R);
 }
Exemplo n.º 11
0
 Cone Cone::GetTransformed(const NX::Matrix<float, 4, 4> &M) const{
     return Cone(*this).Transform(M);
 }
Exemplo n.º 12
0
void SceneObject::DrawCoordinate()
{
	GLdouble orig[3];
	int viewport[4];
	double modelview[16], projection[16];

	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	int width = viewport[2], height = viewport[3];

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	//glFrustum(viewport[0], viewport[2], viewport[1], viewport[3], 0.01, 1000.);
	if (width > height)
		glOrtho(-width / (double)height, width / (double)height, -1., 1., 0.01, 1000);
	else
		glOrtho(-1., 1., -height / (double)width, height / (double)width, 0.01, 1000);

	glDepthMask(GL_FALSE);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);
	gluUnProject(50, 50, 0.0005, modelview, projection, viewport, &orig[0], &orig[1], &orig[2]);

	glPushMatrix();
	glTranslated(orig[0], orig[1], orig[2]);
	glScaled(.1, .1, .1);
	glPushAttrib (GL_TRANSFORM_BIT |GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT);
	glEnable(GL_COLOR_MATERIAL);

	glColor4f(1.0,0.0,1.0,1.0); //purple sphere
	glutSolidSphere(0.3,30,30);

	glColor4f(1.0,0.0,0.0,1.0); //x red
	glPushMatrix();
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glColor4f(0.0,1.0,0.0,1.0); //y green
	glPushMatrix();
	glRotatef(90,0,0,1);
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glColor4f(0.0,0.0,1.0,1.0); //z blue
	glPushMatrix();
	glRotatef(90,0,-1,0);
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glPopAttrib();
	glPopMatrix();

	glDepthMask(GL_TRUE);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
}
Exemplo n.º 13
0
int main(int argc, char* argv[]) {
  // Check arguments
  if (argc < 5) {
    std::cerr << "Usage: final_project NODES_FILE TRIS_FILE ball.nodes ball.tris \n";
    exit(1);
  }

  MeshType mesh;
  std::vector<typename MeshType::node_type> mesh_node;

  // Read all water Points and add them to the Mesh
  std::ifstream nodes_file(argv[1]);
  Point p;
  uint water_nodes = 0;
  while (CS207::getline_parsed(nodes_file, p)) {
    mesh_node.push_back(mesh.add_node(p));
    water_nodes++;
  }

  // Read all water mesh triangles and add them to the Mesh
  std::ifstream tris_file(argv[2]);
  std::array<int,3> t;
  int water_tris = 0;
  while (CS207::getline_parsed(tris_file, t)) {
    mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]);
    water_tris++;
  }
  uint water_edges = mesh.num_edges();

  std::ifstream nodes_file2(argv[3]);
  double radius = 1 * scale;
  while (CS207::getline_parsed(nodes_file2, p)) {
    p *= scale;
    p.z += + start_height;
    mesh_node.push_back(mesh.add_node(p));
  }

  // Read all ball mesh triangles and add them to the mesh
  std::ifstream tris_file2(argv[4]);
  while (CS207::getline_parsed(tris_file2, t)) {
    mesh.add_triangle(mesh_node[t[0]+water_nodes], mesh_node[t[1]+water_nodes], mesh_node[t[2]+water_nodes]);
  }

  // Print out the stats
  std::cout << mesh.num_nodes() << " "
            << mesh.num_edges() << " "
            << mesh.num_triangles() << std::endl;

  /* Set the initial conditions */ 
  // Set the initial values of the nodes and get the maximum height double
  double max_h = 0;
  double dx = 0;
  double dy = 0;
  auto init_cond = Still();
  auto b_init_cond = Cone(); 

  // Find the maximum height and apply initial conditions to nodes
  for (auto it = mesh.node_begin(); it != mesh.node_end(); ++it) { 
    auto n = *it;
    if (n.index() < water_nodes){
	    n.value().q = init_cond(n.position());
	    n.value().b = b_init_cond(n.position());
	    max_h = std::max(max_h, n.value().q.h);
  	}
  	else {
  		n.value().q = QVar(n.position().z, 0, 0);
      n.value().mass = total_mass/(mesh.num_nodes() - water_nodes);
      n.value().velocity = Point(0.0,0.0,0.0);
  	}
  } 

  // Set the initial values of the triangles to the average of their nodes and finds S
  // Set the triangle direction values so that we can determine which 
  // way to point normal vectors. This part assumes a convex shape
  Point center = get_center(mesh); 
  for (auto it = mesh.triangle_begin(); it != mesh.triangle_end(); ++it) {
    auto t = *it; 
    if (t.index() < water_tris){
	    t.value().q_bar = (t.node1().value().q + 
	                       t.node2().value().q + 
	                       t.node3().value().q) / 3.0;
	    t.value().q_bar2 = t.value().q_bar;

	    double b_avg = (t.node1().value().b + 
	                    t.node2().value().b + 
	                    t.node3().value().b) / 3.0;
	    // finds the max dx and dy to calculate Source
	    dx = std::max(dx, fabs(t.node1().position().x - t.node2().position().x));
	    dx = std::max(dx, fabs(t.node2().position().x - t.node3().position().x));
	    dx = std::max(dx, fabs(t.node3().position().x - t.node1().position().x));
	    dy = std::max(dy, fabs(t.node1().position().y - t.node2().position().y));
	    dy = std::max(dy, fabs(t.node2().position().y - t.node3().position().y));
	    dy = std::max(dy, fabs(t.node3().position().y - t.node1().position().y));
	    t.value().S = QVar(0, -grav * t.value().q_bar.h * b_avg / dx, -grav * t.value().q_bar.h * b_avg / dy);
	  } 
    else
      set_normal_direction((*it),center);
  }

  // Calculate the minimum edge length and set edge inital condititons
  double min_edge_length = std::numeric_limits<double>::max();
  uint count = 0;
  for (auto it = mesh.edge_begin(); it != mesh.edge_end(); ++it, count++){
    if (count < water_edges)
      min_edge_length = std::min(min_edge_length, (*it).length());
    else {
      (*it).value().spring_constant = spring_const;
      (*it).value().initial_length = (*it).length();
    }
  }
	
  // Launch the SDLViewer
  CS207::SDLViewer viewer;
  viewer.launch();

  auto node_map = viewer.empty_node_map(mesh);
  viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                   Color(water_nodes), NodePosition(), node_map);
  viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map);
  // adds solid color-slows down program significantly
  //viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map);
  viewer.center_view();


  // CFL stability condition requires dt <= dx / max|velocity|
  // For the shallow water equations with u = v = 0 initial conditions
  //   we can compute the minimum edge length and maximum original water height
  //   to set the time-step
  // Compute the minimum edge length and maximum water height for computing dt
  double dt = 0.25 * min_edge_length / (sqrt(grav * max_h));
  double t_start = 0;
  double t_end = 10;
  Point ball_loc = Point(0,0,0);
  double dh = 0;
  // double pressure = gas_const/(4/3*M_PI*radius*radius*radius);

  // add listener
  my_listener* l = new my_listener(viewer,mesh,dt); 
  viewer.add_listener(l);

  // Preconstruct a Flux functor
  EdgeFluxCalculator f;
  // defines the constraint
  PlaneConstraint c = PlaneConstraint(plane_const);

  // Begin the time stepping
  for (double t = t_start; t < t_end; t += dt) {
    // define forces on ball
    GravityForce g_force;
    BuoyantForce b_force = BuoyantForce(dh, ball_loc.z);
    WindForce w_force;
    MassSpringForce ms_force;
    // PressureForce p_force = PressureForce(pressure);
    // DampingForce d_force = DampingForce(mesh.num_nodes());
    auto combined_forces = make_combined_force(g_force, b_force, w_force, ms_force);
    
    // Step forward in time with forward Euler
    hyperbolic_step(mesh, f, t, dt, ball_loc, water_tris);

    // Update node values with triangle-averaged values
    ball_loc = post_process(mesh, combined_forces, c, t, dt, water_nodes);

    // Update the viewer with new node positions
    viewer.add_nodes(mesh.node_begin(), mesh.node_end(), 
                     Color(water_nodes), NodePosition(), node_map);
    // viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map);
    viewer.set_label(t);

    // find radius of cross sectional radius of ball submerged
    dh = ball_loc.z;
    if (dh > 2*radius)
      dh = 2 * radius;
    ball_loc.z = cross_radius(radius, dh);

    // These lines slow down the animation for small meshes.
    if (mesh.num_nodes() < 100)
      CS207::sleep(0.05);
  }
  return 0;
}
Exemplo n.º 14
0
void
Display( )
{
	if( DebugOn != 0 )
	{
		fprintf( stderr, "Display\n" );
	}


	// set which window we want to do the graphics into:

	glutSetWindow( MainWindow );


	// erase the background:

	glDrawBuffer( GL_BACK );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glEnable( GL_DEPTH_TEST );


	
	//glShadeModel(GL_FLAT);

	// set the viewport to a square centered in the window:

	GLsizei vx = glutGet( GLUT_WINDOW_WIDTH );
	GLsizei vy = glutGet( GLUT_WINDOW_HEIGHT );
	GLsizei v = vx < vy ? vx : vy;			// minimum dimension
	GLint xl = ( vx - v ) / 2;
	GLint yb = ( vy - v ) / 2;
	glViewport( xl, yb,  v, v );


	// set the viewing volume:
	// remember that the Z clipping  values are actually
	// given as DISTANCES IN FRONT OF THE EYE
	// USE gluOrtho2D( ) IF YOU ARE DOING 2D !

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	if( WhichProjection == ORTHO )
		glOrtho( -3., 3.,     -3., 3.,     0.1, 1000. );
	else
		gluPerspective( 90., 1.,	0.1, 1000. );


	// place the objects into the scene:

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );

	//project4 setting the light position
	//glLightfv(GL_LIGHT0, GL_POSITION, Array3(0., 0., 0.));

	//glLightfv(GL_LIGHT1, GL_POSITION, Array3(0., 2., 0.));
	// set the eye position, look-at position, and up-vector:

	gluLookAt( 0., 0., 3.,     0., 0., 0.,     0., 1., 0. );


	// rotate the scene:

	glRotatef( (GLfloat)Yrot, 0., 1., 0. );
	glRotatef( (GLfloat)Xrot, 1., 0., 0. );


	// uniformly scale the scene:

	if( Scale < MINSCALE )
		Scale = MINSCALE;
	glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale );


	// set the fog parameters:

	if( DepthCueOn != 0 )
	{
		glFogi( GL_FOG_MODE, FOGMODE );
		glFogfv( GL_FOG_COLOR, FOGCOLOR );
		glFogf( GL_FOG_DENSITY, FOGDENSITY );
		glFogf( GL_FOG_START, FOGSTART );
		glFogf( GL_FOG_END, FOGEND );
		glEnable( GL_FOG );
	}
	else
	{
		glDisable( GL_FOG );
	}


	// possibly draw the axes:

	if( AxesOn != 0 )
	{
		glColor3fv( &Colors[WhichColor][0] );
		glCallList( AxesList );
	}

	// draw the current object:
	//glTranslatef(0., .5, 1.);
	// since we are using glScalef( ), be sure normals get unitized:
	
	//project4
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, MulArray3(.3f, White));
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
	SetSpotLight(GL_LIGHT0, 2 * sin(Period), 0., 0., 0., 0., -1., 0., 0., 1.);
	

	SetPointLight(GL_LIGHT1, 1., 1.5, -1., 1., 1., 1.);

	//The light sources LIGHT0 AND LIGHT1:
	if (Light0On)
		glEnable(GL_LIGHT0);
	else
		glDisable(GL_LIGHT0);

	if (Light1On)
		glEnable(GL_LIGHT1);
	else
		glDisable(GL_LIGHT1);

	glEnable(GL_NORMALIZE);

	// specify shading to be flat or smooth:
	glShadeModel(GL_SMOOTH);

	//Draw a stationary light
	glPushMatrix();
	glTranslatef(1., 1.5, -1.);
	glScalef(.3, .3, .3);
	glRotatef(180, 1., 0., 0.);
	Cone();
	glPopMatrix();

	//draw the moving bulb
	glColor3f(0., 0., 1.);
	glPushMatrix();
	glTranslatef(1.2 * sin(Period), 0., 0.);
	MjbSphere(.1, 100, 100);
	glPopMatrix();

	glEnable(GL_LIGHTING);

	//Draw one torus

	//make the torus as flat
	glShadeModel(GL_FLAT);

	glPushMatrix();
		SetMaterial(1., 0., 0., 60.);
		glTranslatef(-1.7, 0., 0.);
		glRotatef(90., 0., 1., 0.);
		glScalef(.1, .1, .1);
		glutSolidTorus(2.7, 6., SLICES, SLICES);
	glPopMatrix();
	
	//make the other objects smooth;
	glShadeModel(GL_SMOOTH);

	//Draw a rotating solid teapot
	SetMaterial(1., 1., 0., 1.5);
	glPushMatrix();	
		glTranslatef(1., .3,-1.);
		glRotatef(360. * Time, 0., 1., 0.);
		glutSolidTeapot(TeapotSize);
	glPopMatrix();

	//the sphere with Texture mapping:
	SetMaterial(0., 1., 0.5, 20.);
	glPushMatrix();
		glRotatef(360. * Time , 0., 1., 0.);
		printf("the time is %f\n", Time);
		glTranslatef(1., 2., -2.);
		TextureSphere();
	glPopMatrix();
	
	glDisable(GL_LIGHTING);

	// draw some gratuitous text that just rotates on top of the scene:
	
	// draw some gratuitous text that is fixed on the screen:
	//
	// the projection matrix is reset to define a scene whose
	// world coordinate system goes from 0-100 in each axis
	//
	// this is called "percent units", and is just a convenience
	//
	// the modelview matrix is reset to identity as we don't
	// want to transform these coordinates

	glDisable( GL_DEPTH_TEST );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	gluOrtho2D( 0., 100.,     0., 100. );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );



	// swap the double-buffered framebuffers:

	glutSwapBuffers( );


	// be sure the graphics buffer has been sent:
	// note: be sure to use glFlush( ) here, not glFinish( ) !

	glFlush( );
}