Пример #1
0
void Viewer::mouse_button(int button, int action, int mods)
{
	if (button == GLFW_MOUSE_BUTTON_RIGHT)
	{
		polarView(distance,azimut,elevation,twist+5);
	}else if(button == GLFW_MOUSE_BUTTON_LEFT)
	{
		polarView(distance,azimut,elevation,twist-5);
	}
}
Пример #2
0
void TOpenGL_Form::DrawScene()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();

        latitude += latinc;
        longitude += longinc;

        polarView( radius, 0, latitude, longitude );


        glIndexi(RED_INDEX);
        glCallList(CONE);

        glIndexi(BLUE_INDEX);
        glCallList(GLOBE);

        glIndexi(GREEN_INDEX);
        glPushMatrix();
            glTranslatef(0.8F, -0.65F, 0.0F);
            glRotatef(30.0F, 1.0F, 0.5F, 1.0F);
            glCallList(CYLINDER);
        glPopMatrix();

    glPopMatrix();

    SwapBuffers(ghDC);
}
Пример #3
0
void Viewer::key(int key, int scancode, int action, int mods)
{
	if(action == GLFW_PRESS || action == GLFW_REPEAT)
	{
		if (key == GLFW_KEY_UP)
			polarView(distance,azimut,elevation+5,twist);
		else if (key == GLFW_KEY_DOWN)
	        polarView(distance,azimut,elevation-5,twist);
		else if (key == GLFW_KEY_LEFT)
	        polarView(distance,azimut-5,elevation,twist);
		else if (key == GLFW_KEY_RIGHT)
	        polarView(distance,azimut+5,elevation,twist);
	}


	/* w ==> switch draw_mode : wireframe <-> triangles */
	if(action == GLFW_PRESS  && key == GLFW_KEY_Z)
	{
		if(draw_mode == DRAW_MODE::WIREFRAME)
			draw_mode = DRAW_MODE::TRIANGLES;
		else if(draw_mode == DRAW_MODE::TRIANGLES)
			draw_mode = DRAW_MODE::WIREFRAME;
	}

	/* s ==> switch smooth mode : smooth <-> no smooth */
	if(action == GLFW_PRESS && key == GLFW_KEY_S)
	{
		if(smooth_mode == SMOOTH_MODE::SMOOTH)
			smooth_mode = SMOOTH_MODE::NO_SMOOTH;
		else
			smooth_mode = SMOOTH_MODE::SMOOTH;
	}

	/* l ==> siwth lighting mode : constant <-> gouraud */
	if(action == GLFW_PRESS && key == GLFW_KEY_L)
	{
		if(lighting_mode == LIGHTING_MODE::CONSTANT)
		{
			lighting_mode = LIGHTING_MODE::GOURAUD;
			glShadeModel(GL_SMOOTH);
			std::cout << "switch to gouraud illumination" << std::endl;
		}else
		{
			lighting_mode = LIGHTING_MODE::CONSTANT;
			glShadeModel(GL_FLAT);
			std::cout << "switch to constant illumination model" << std::endl;
		}
	}

	/* n ==> switch draw normals on/off */
	if(action == GLFW_PRESS && key == GLFW_KEY_N)
	{
		draw_normals = !draw_normals;
	}

	/* keypad 5,2,1,3 ==> control camera translation */
	if(action == GLFW_PRESS|| action == GLFW_REPEAT)
	{
		if(key == GLFW_KEY_KP_5)
		{
			translateCamera(0.0,1.0,0.0);
		}else if(key == GLFW_KEY_KP_2)
		{
			translateCamera(0.0,-1.0,0.0);
		}else if(key == GLFW_KEY_KP_1)
		{
			translateCamera(-1.0,0.0,0.0);
		}else if(key == GLFW_KEY_KP_3)
		{
			translateCamera(1.0,0.0,0.0);
		}
	}
}
Пример #4
0
void Viewer::zoom(double x, double y)
{
	polarView(distance-y,azimut,elevation,twist);
}
r2d2::DistanceSensor::SensorResult r2d2::VirtualUltrasonicSensor::get_data() {
    std::unique_ptr<PolarView> polarView(new r2d2::MapPolarView());

    // Lock map, unlocks automatically at end of scope
    LockingSharedObject<ReadOnlyMap>::Accessor accessor(map);

    // Scan on only one angle
    double angle = coordinate_attitude.get_attitude().get_yaw()/Angle::deg;
    Coordinate origin = coordinate_attitude.get_coordinate();

    // Calculate new point from point and vector
    // x = start_x + len * cos(angle);
    // y = start_y + len * sin(angle);
    //
    // angle must be in radians so
    // radians = degrees*(PI/180)
    Coordinate maxRangePoint(
                origin.get_x() + max_range*std::cos(angle*(M_PI/180)),
                origin.get_y() + max_range*std::sin(angle*(M_PI/180)),
                origin.get_z());

    double totalSteps = max_range/accuracy;

    Coordinate lastCoordinate = coordinate_attitude.get_coordinate();

    // Follow the soundwave from begin to end with stepsize accuracy and check
    // if there is an obstacle
    for(int i = 0; i <= totalSteps; ++i) {
        Length subLength = i*accuracy;

        // Calculate new point on line with distance subLength
        Coordinate newCoordinate(
                    origin.get_x() + subLength*std::cos(angle*(M_PI/180)),
                    origin.get_y() + subLength*std::sin(angle*(M_PI/180)),
                    origin.get_z());

        Box fieldToCheck(lastCoordinate, newCoordinate);
        BoxInfo boxInfo = accessor.access().get_box_info(fieldToCheck);

        if(boxInfo.get_has_obstacle()) {
            polarView->add_distancereading(
                        angle * Angle::deg,
                        DistanceReading(
                            subLength,
                            DistanceReading::ResultType::CHECKED));
            break;
        }
        else if(i == totalSteps) {
            // The ResultType is OUT_OF_RANGE so the distance is -1 meter
            // so it can't be mistaken for a CHECKED distance.
            polarView->add_distancereading(
                        angle * Angle::deg,
                        DistanceReading(
                            -1 * Length::METER,
                            DistanceReading::ResultType::OUT_OF_RANGE));
        }

        lastCoordinate = newCoordinate;
    }

    return r2d2::DistanceSensor::SensorResult(0, polarView);
}