Exemple #1
0
/* Replacement for gluBuild2DMipmaps so GLU isn't needed */
static void Build2DMipmaps(GLint components, GLint width, GLint height, GLenum format, const unsigned char *data, int filter) {
      int level = 0;
      unsigned char *d = (unsigned char *) malloc((width/2)*(height/2)*components+4);
      const unsigned char *last = data;

      glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, data);
      level++;

      while (HalfSize(components, width, height, last, d, filter)) {
            if (width  > 1) width  /= 2;
            if (height > 1) height /= 2;

            glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, d);
            level++;
            last = d;
      }

      free(d);
}
Exemple #2
0
Wall::Wall(Ogre::Vector3 Pos, Ogre::Vector3 size,Physics * physics, Ogre::SceneManager * manager, float rotation)
	: StaticObject(Pos,
					Ogre::Vector3(size.x, size.y, 20.0f),
					"cube.mesh",
					physics,
					manager)
{
	mOrintation = Ogre::Quaternion(Ogre::Radian(Ogre::Degree(rotation)), Ogre::Vector3(0,1,0));
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						WallInfo;
	WallInfo.m_mass =						100.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, WallInfo.m_mass, massProperties);
	WallInfo.m_mass =						massProperties.m_mass;
	WallInfo.m_centerOfMass =				massProperties.m_centerOfMass;
	WallInfo.m_inertiaTensor =				massProperties.m_inertiaTensor;
	WallInfo.m_solverDeactivation =			WallInfo.SOLVER_DEACTIVATION_MEDIUM;
	WallInfo.m_shape =						Hbox;
	WallInfo.m_restitution =				0.0f;
	WallInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_FIXED;
	WallInfo.m_motionType =					hkpMotion::MOTION_FIXED;
	WallInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	WallInfo.m_position = 					hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(WallInfo);
	Body->setUserData(hkUlong(this));
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
	ObjectEnt->setMaterialName("Examples/RustySteel");
	hkQuaternion GetBodyAngle = Body->getRotation();
	hkVector4 GetrotationAxis(0,0,0);
	if(GetBodyAngle.hasValidAxis())
	{
		GetBodyAngle.getAxis(GetrotationAxis);
	}
	Ogre::Quaternion UpdateOrintation(Ogre::Radian(GetBodyAngle.getAngle()), Ogre::Vector3(GetrotationAxis(0),GetrotationAxis(1),GetrotationAxis(2)));
	ObjectNode->setOrientation(UpdateOrintation);
}
Exemple #3
0
Turret::Turret(Ogre::Vector3 Pos, Ogre::SceneManager* manager, Physics* physicsManager)
		:	DynamicObject( Pos,
						"cube.mesh",
						Ogre::Vector3(20.0,50.0,20.0),
						Ogre::Quaternion( Ogre::Radian(0), Ogre::Vector3(0,1,0)),
						manager,
						physicsManager )
				,mRotateValue(0)
				,mChangeInRotation(0.001)
				,mKillTimer(0)
				,mShutdown(false)
{
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						TurretInfo;
	TurretInfo.m_mass =						5000.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, TurretInfo.m_mass, massProperties);
	TurretInfo.m_mass =						massProperties.m_mass;
	TurretInfo.m_centerOfMass =				hkVector4(massProperties.m_centerOfMass(0),massProperties.m_centerOfMass(1) - 20,massProperties.m_centerOfMass(2));
	TurretInfo.m_inertiaTensor =			massProperties.m_inertiaTensor;
	TurretInfo.m_solverDeactivation =		TurretInfo.SOLVER_DEACTIVATION_MEDIUM;
	TurretInfo.m_shape =					Hbox;
	TurretInfo.m_restitution =				0.0f;
	TurretInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_MOVING;
	TurretInfo.m_motionType =				hkpMotion::MOTION_BOX_INERTIA;
	TurretInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	TurretInfo.m_position = 				hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(TurretInfo);
	Body->setUserData(hkUlong(this));
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
}
Exemple #4
0
Create::Create(Ogre::Vector3 Pos, Ogre::SceneManager* manager, Physics* physicsManager)
	:	DynamicObject( Pos,
						"cube.mesh",
						Ogre::Vector3(34.0,34.0,34.0),
						Ogre::Quaternion( Ogre::Radian(0), Ogre::Vector3(0,1,0)),
						manager,
						physicsManager )
						,Hit(false)
{
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						CreateInfo;
	CreateInfo.m_mass =						100.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, CreateInfo.m_mass, massProperties);
	CreateInfo.m_mass =						massProperties.m_mass;
	CreateInfo.m_centerOfMass =				massProperties.m_centerOfMass;
	CreateInfo.m_inertiaTensor =			massProperties.m_inertiaTensor;
	CreateInfo.m_solverDeactivation =		CreateInfo.SOLVER_DEACTIVATION_MEDIUM;
	CreateInfo.m_shape =					Hbox;
	CreateInfo.m_restitution =				0.0f;
	CreateInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_MOVING;
	CreateInfo.m_motionType =				hkpMotion::MOTION_BOX_INERTIA;
	CreateInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	CreateInfo.m_position = 				hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(CreateInfo);
	Body->setUserData(hkUlong(this));
	RecptorFront = mOrintation * Ogre::Vector3::UNIT_X;
	RecptorSide = mOrintation * Ogre::Vector3::UNIT_Z;
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
}
Exemple #5
0
Sphere AABB::MaximalContainedSphere() const
{
	vec halfSize = HalfSize();
	return Sphere(CenterPoint(), Min(halfSize.x, halfSize.y, halfSize.z));
}
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
  std::vector<sf::Shape> shapes;
  std::map<std::string, Point> points;
  float lat_min, lat_max, lon_min, lon_max;
  XMLDocument doc("map.osm");
  if (doc.GetName() == "osm") {
    doc.Enter();
    while (doc.Next()) {
      if (doc.GetName() == "bounds") {
        std::string minlat = doc.GetProperty("minlat");
        lat_min = atof(minlat.c_str());
        std::string minlon = doc.GetProperty("minlon");
        lon_min = atof(minlon.c_str());
        std::string maxlat = doc.GetProperty("maxlat");
        lat_max = atof(maxlat.c_str());
        std::string maxlon = doc.GetProperty("maxlon");
        lon_max = atof(maxlon.c_str());
      } else if (doc.GetName() == "node") {
        std::string lat = doc.GetProperty("lat");
        float lattitude = atof(lat.c_str());
        std::string lon = doc.GetProperty("lon");
        float longitude = atof(lon.c_str());
        std::string id(doc.GetProperty("id"));
        points[id] = Point(lattitude, longitude);
      } else if (doc.GetName() == "way") {
        std::cout << "Adding shape" << std::endl;
        std::string type = "";
        doc.Enter();
        while (doc.Next()) {
          if (doc.GetName() == "tag") {
            if (doc.GetProperty("k") == "building") {
              if (doc.GetProperty("v") == "yes") {
                type = "building";
                break;
              }
            } else if (doc.GetProperty("k") == "natural") {
              if (doc.GetProperty("v") == "water") {
                type = "water";
                break;
              }
            } else if (doc.GetProperty("k") == "landuse") {
              if (doc.GetProperty("v") == "grass") {
                type = "grass";
                break;
              } else if (doc.GetProperty("v") == "residential") {
                type = "residential";
                break;
              }
            }
          }
        }
        doc.First();
        sf::Shape shape;
        shape.EnableFill(false);
        shape.EnableOutline(false);
        //shape.SetOutlineWidth(2);
        sf::Color col(255, 255, 255);
        if (type == "building") {
          std::cout << "Type = building" << std::endl;
          col = sf::Color(100, 100, 100, 50);
          shape.EnableFill(true);
        } else if (type == "water") {
          std::cout << "Type = water" << std::endl;
          col = sf::Color(100, 100, 255, 50);
          shape.EnableFill(true);
        } else if (type == "grass") {
          std::cout << "Type = grass" << std::endl;
          col = sf::Color(100, 255, 100, 50);
          shape.EnableFill(true);
        } else if (type == "residential") {
          std::cout << "Type = grass" << std::endl;
          col = sf::Color(200, 200, 200, 50);
          shape.EnableFill(true);
        }
        Shape shp;
        while (doc.Next()) {
          if (doc.GetName() == "nd") {
            std::string node_id = doc.GetProperty("ref");
            const Point& point = points[node_id];
            shp.add_node(point);
          }
        }
        shp.partition();

        for (std::vector<Polygon>::const_iterator p = shp.polygons_.begin(); p != shp.polygons_.end(); ++p) {
          sf::Shape new_shape = shape;
          for (std::vector<Point>::const_iterator q = p->nodes_.begin(); q != p->nodes_.end(); ++q) {
            float scale = 2000.0/(lat_max-lat_min);
            float x = (q->lat - lat_min)*scale;
            float y = (q->lon - lon_min)*scale;
            new_shape.AddPoint(x, y, col, col);
          }
          shapes.push_back(new_shape);
        }

        std::cout << "  pushing shape" << std::endl;
        shapes.push_back(shape);
        doc.Leave();
      }
    }
  }
  float scale = 2000.0/(lat_max-lat_min);
    
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Views");

    // Create a view with the same size as the window, located somewhere in the center of the background
    sf::Vector2f Center(1000, 1000);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        // Move the view using arrow keys
        float Offset = 200.f * App.GetFrameTime();
        if (App.GetInput().IsKeyDown(sf::Key::Up))    View.Move( 0,      -Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  View.Move( 0,       Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Left))  View.Move(-Offset,  0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) View.Move( Offset,  0);

        // Zoom and unzoom using + and - keys
        if (App.GetInput().IsKeyDown(sf::Key::Add))      View.Zoom(1.001f);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.999f);

        if (App.GetInput().IsKeyDown(sf::Key::A))      View.Zoom(1.011f);
        if (App.GetInput().IsKeyDown(sf::Key::Z)) View.Zoom(0.989f);

        // Set the view
        App.SetView(View);

        // Clear screen
        App.Clear();

        for (std::vector<sf::Shape>::iterator p = shapes.begin(); p != shapes.end(); ++p) {
          App.Draw(*p);
        }

        // Finally, display rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
Exemple #7
0
float BoundingBox::DistanceToPoint(const Vector3& point) const
{
    const Vector3 offset = Center() - point;
    const Vector3 absOffset(Abs(offset.x_), Abs(offset.y_), Abs(offset.z_));
    return VectorMax(Vector3::ZERO, absOffset - HalfSize()).Length();
}
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Views");

// Load a sound buffer from a wav file
    sf::SoundBuffer Buffer;
    if (!Buffer.LoadFromFile("sound.wav"))
        return EXIT_FAILURE;

// Load the sprite image from a file
    sf::Image Image;
    if (!Image.LoadFromFile("sprite.png"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(Image);

    // Change its properties
    //Sprite.SetColor(sf::Color(0, 255, 255, 128));
    Sprite.SetPosition(200.f, 100.f);
    //Sprite.SetScale(2.f, 2.f);
    // Create a sprite for the background
    sf::Image BackgroundImage;
    if (!BackgroundImage.LoadFromFile("background.jpg"))
        return EXIT_FAILURE;
    sf::Sprite Background(BackgroundImage);

    // Create another sprite for the cursor
    sf::Image CursorImage;
    if (!CursorImage.LoadFromFile("cursor.tga"))
        return EXIT_FAILURE;
    sf::Sprite Cursor(CursorImage);

    // Resize the background, so that it's much bigger than the window
    Background.Resize(2000, 2000);

    // Define a text for displaying some instructions
    sf::String Text("Use the arrow keys to move the camera\nUse the + and - keys to zoom and unzoom");
    Text.Move(10, 500);
    Text.SetColor(sf::Color::White);

    // Create a view with the same size as the window, located somewhere in the center of the background
    sf::Vector2f Center(1000, 1000);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);

    // To start, put the cursor at the center
    Cursor.SetCenter(32, 32);
    Cursor.SetPosition(Center);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }
    sf::Sound Sound(Buffer);
           // Get elapsed time
        float ElapsedTime = App.GetFrameTime();
// Move the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-50 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 50 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    Sprite.Move(0, -50 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.Move(0,  50 * ElapsedTime);

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Add))      Sprite.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);


        // Create a sound instance and play it
        if (App.GetInput().IsKeyDown(sf::Key::Space)) Sound.Play();

        // Move the view using arrow keys
        float Offset = 200.f * App.GetFrameTime();
        if (App.GetInput().IsKeyDown(sf::Key::Up))    View.Move( 0,      -Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  View.Move( 0,       Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Left))  View.Move(-Offset,  0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) View.Move( Offset,  0);

        // Zoom and unzoom using + and - keys
       // if (App.GetInput().IsKeyDown(sf::Key::Add))      View.Zoom(1.001f);
       // if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.999f);

        // Set the view
        App.SetView(View);

        // Clear screen
        App.Clear();

        // Draw background
        App.Draw(Background);

        // Draw cursor
       // sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
       // Cursor.SetPosition(CursorPos);
       // App.Draw(Cursor);

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

        // Draw some instructions
        App.Draw(Text);

        // Display sprite in our window
        App.Draw(Sprite);


        // Finally, display rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}