Ejemplo n.º 1
0
unsigned int createRB(EntityManager& em, const std::shared_ptr<Texture>& texture,
	b2Vec2 position = b2Vec2(200.0f, 200.0f), b2Vec2 scale = b2Vec2(1.0f, 1.0f))
{
	unsigned int id = em.create_entity<Transform, Graphics, PhysicsBodyComponent>();

	b2Vec2 half_size(texture->getWidth() * 0.5f * scale.x,
		texture->getHeight() * 0.5f * scale.y);

	b2PolygonShape* shape = new b2PolygonShape();
	shape->SetAsBox(half_size.x, half_size.y, half_size, 0.0f);

	b2Body& body = *em.get_component<PhysicsBodyComponent>(id)->body;
	body.SetType(b2_dynamicBody);
	body.SetLinearDamping(2.0f);
	body.SetAngularDamping(0.5f);
	body.CreateFixture(shape, 0.25f);
	body.SetTransform(position, 0.0f);

	em.get_component<Transform>(id)->scale = scale;

	em.get_component<Graphics>(id)->texture = texture;

	return id;
}
Ejemplo n.º 2
0
void MainWindow::create_actions()
{
    // file menu

    new_model_action = new QAction(tr("New voxel model"), this);
    connect(new_model_action, SIGNAL(triggered()), this, SLOT(new_model()));
 
    open_model_action = new QAction(tr("Open voxel model"), this);
    connect(open_model_action, SIGNAL(triggered()), this, SLOT(open_model()));

    clone_model_action = new QAction(tr("Clone voxel model"), this);
    connect(clone_model_action, SIGNAL(triggered()), this, SLOT(clone_model()));
 
    save_action = new QAction(tr("&Save"), this);
    save_action->setShortcuts(QKeySequence::Save);
    connect(save_action, SIGNAL(triggered()), this, SLOT(save()));
 
    save_as_action = new QAction(tr("Save &As..."), this);
    save_as_action->setShortcuts(QKeySequence::SaveAs);
    connect(save_as_action, SIGNAL(triggered()), this, SLOT(save_as()));
 
    exit_action = new QAction(tr("E&xit"), this);
    exit_action->setShortcuts(QKeySequence::Quit);
    exit_action->setStatusTip(tr("Exit the application"));
    connect(exit_action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
 
/*        cut_action = new QAction(tr("Cu&t"), this);
    cut_action->setShortcuts(QKeySequence::Cut);
    cut_action->setStatusTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cut_action, SIGNAL(triggered()), this, SLOT(cut()));
 
    copy_action = new QAction(tr("&Copy"), this);
    copy_action->setShortcuts(QKeySequence::Copy);
    copy_action->setStatusTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copy_action, SIGNAL(triggered()), this, SLOT(copy()));
 
    paste_action = new QAction(tr("&Paste"), this);
    paste_action->setShortcuts(QKeySequence::Paste);
    paste_action->setStatusTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(paste_action, SIGNAL(triggered()), this, SLOT(paste()));*/

    // model menu

    double_size_action = new QAction(tr("Double size"), this);
    // new_action->setShortcuts(QKeySequence::New);
    connect(double_size_action, SIGNAL(triggered()), this, 
        SLOT(double_size()));
 
    half_size_action = new QAction(tr("Half size"), this);
    // open_action->setShortcuts(QKeySequence::Open);
    connect(half_size_action, SIGNAL(triggered()), this, 
        SLOT(half_size()));
 
    optimize_action = new QAction(tr("Optimize dimensions"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(optimize_action, SIGNAL(triggered()), this,
        SLOT(optimize()));

    rotate_action = new QAction(tr("Rotate 90 degrees"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(rotate_action, SIGNAL(triggered()), this,
        SLOT(rotate()));

}
void afxZodiacTerrainRenderer::render(SceneRenderState* state)
{
   PROFILE_SCOPE(afxRenderZodiacTerrainMgr_render);

   // Early out if no terrain zodiacs to draw.
   if (terrain_zodes.size() == 0)
     return;

   initShader();
   if (!zodiac_shader)
     return;

   bool is_reflect_pass = state->isReflectPass();

   // Automagically save & restore our viewport and transforms.
   GFXTransformSaver saver;

   MatrixF proj = GFX->getProjectionMatrix();

   // Set up world transform
   MatrixF world = GFX->getWorldMatrix();
   proj.mul(world);
   shader_consts->set(projection_sc, proj);

   //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
   // RENDER EACH ZODIAC
   //
   for (S32 zz = 0; zz < terrain_zodes.size(); zz++)
   {
      TerrainZodiacElem& elem = terrain_zodes[zz];

      TerrainBlock* block = (TerrainBlock*) elem.block;

      afxZodiacMgr::ZodiacSpec* zode = &afxZodiacMgr::terr_zodes[elem.zode_idx];
      if (!zode)
         continue;

      if (is_reflect_pass)
      {
         if ((zode->zflags & afxZodiacData::SHOW_IN_REFLECTIONS) == 0)
            continue;
      }
      else
      {
         if ((zode->zflags & afxZodiacData::SHOW_IN_NON_REFLECTIONS) == 0)
            continue;
      }

      F32 fadebias = zode->calcDistanceFadeBias(elem.camDist);
      if (fadebias < 0.01f)
        continue;

      F32 cos_ang = mCos(elem.ang);
      F32 sin_ang = mSin(elem.ang);

      GFXStateBlock* sb = chooseStateBlock(zode->zflags & afxZodiacData::BLEND_MASK, is_reflect_pass);

      GFX->setShader(zodiac_shader->getShader());
      GFX->setStateBlock(sb);
      GFX->setShaderConstBuffer(shader_consts);

      // set the texture
      GFX->setTexture(0, *zode->txr);
      ColorF zode_color = (ColorF)zode->color;
      zode_color.alpha *= fadebias;
      shader_consts->set(color_sc, zode_color);

      Point3F half_size(zode->radius_xy,zode->radius_xy,zode->radius_xy);

      F32 inv_radius = 1.0f/zode->radius_xy;

      GFXPrimitive cell_prim;
      GFXVertexBufferHandle<TerrVertex> cell_verts;
      GFXPrimitiveBufferHandle  primBuff;
      elem.cell->getRenderPrimitive(&cell_prim, &cell_verts, &primBuff);

      U32 n_nonskirt_tris = TerrCellSpy::getMinCellSize()*TerrCellSpy::getMinCellSize()*2;

      const Point3F* verts = ((TerrCell*)elem.cell)->getZodiacVertexBuffer();
      const U16 *tris = block->getZodiacPrimitiveBuffer();
      if (!tris)
         continue; 

      PrimBuild::begin(GFXTriangleList, 3*n_nonskirt_tris);

      /////////////////////////////////
      U32 n_overlapping_tris = 0;
      U32 idx = 0;
      for (U32 i = 0; i < n_nonskirt_tris; i++)
      {
        Point3F tri_v[3];
        tri_v[0] = verts[tris[idx++]];
        tri_v[1] = verts[tris[idx++]];
        tri_v[2] = verts[tris[idx++]];

        elem.mRenderObjToWorld.mulP(tri_v[0]);
        elem.mRenderObjToWorld.mulP(tri_v[1]);
        elem.mRenderObjToWorld.mulP(tri_v[2]);

        if (!afxTriBoxOverlap2D(zode->pos, half_size, tri_v[0], tri_v[1], tri_v[2]))
          continue;

        n_overlapping_tris++;

        for (U32 j = 0; j < 3; j++)
        {
          // compute UV
          F32 u1 = (tri_v[j].x - zode->pos.x)*inv_radius;
          F32 v1 = (tri_v[j].y - zode->pos.y)*inv_radius;
          F32 ru1 = u1*cos_ang - v1*sin_ang;
          F32 rv1 = u1*sin_ang + v1*cos_ang;

          F32 uu = (ru1 + 1.0f)/2.0f;
          F32 vv = 1.0f - (rv1 + 1.0f)/2.0f;

          PrimBuild::texCoord2f(uu, vv);
          PrimBuild::vertex3fv(tri_v[j]);
        }
      }

      /////////////////////////////////

      PrimBuild::end(false);
   }
   //
   // RENDER EACH ZODIAC
   //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
}