コード例 #1
0
ファイル: stack.c プロジェクト: GizmoTheGreen/glshim
void glPopAttrib() {
    ERROR_IN_BLOCK();
    glstack_t *cur = tack_pop(&state.stack.attrib);
    if (cur == NULL) {
        ERROR(GL_STACK_UNDERFLOW);
    }

    if (cur->mask & GL_COLOR_BUFFER_BIT) {
#ifndef USE_ES2
        enable_disable(GL_ALPHA_TEST, cur->alpha_test);
        glAlphaFunc(cur->alpha_test_func, cur->alpha_test_ref);
#endif

        enable_disable(GL_BLEND, cur->blend);
        glBlendFunc(cur->blend_src_func, cur->blend_dst_func);

        enable_disable(GL_DITHER, cur->dither);
#ifndef USE_ES2
        enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op);
        glLogicOp(cur->logic_op);
#endif

        GLfloat *c;
        glClearColor(v4(cur->clear_color));
        glColorMask(v4(cur->color_mask));
    }

    if (cur->mask & GL_CURRENT_BIT) {
        glColor4f(v4(cur->color));
#ifndef USE_ES2
        glNormal3f(v3(cur->normal));
#endif
        for (int i = 0; i < MAX_TEX; i++) {
            glMultiTexCoord2f(GL_TEXTURE0 + i, v2(cur->tex[i]));
        }
    }

    if (cur->mask & GL_DEPTH_BUFFER_BIT) {
        enable_disable(GL_DEPTH_TEST, cur->depth_test);
        glDepthFunc(cur->depth_func);
        glClearDepth(cur->clear_depth);
        glDepthMask(cur->depth_mask);
    }

    if (cur->mask & GL_ENABLE_BIT) {
        int i;
        GLint max_clip_planes;
        glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes);
        for (i = 0; i < max_clip_planes; i++) {
            enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i));
        }

        GLint max_lights;
        glGetIntegerv(GL_MAX_LIGHTS, &max_lights);
        for (i = 0; i < max_lights; i++) {
            enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i));
        }

        enable_disable(GL_ALPHA_TEST, cur->alpha_test);
        enable_disable(GL_BLEND, cur->blend);
        enable_disable(GL_CULL_FACE, cur->cull_face);
        enable_disable(GL_DEPTH_TEST, cur->depth_test);
        enable_disable(GL_DITHER, cur->dither);
        enable_disable(GL_FOG, cur->fog);
        enable_disable(GL_LIGHTING, cur->lighting);
        enable_disable(GL_LINE_SMOOTH, cur->line_smooth);
        enable_disable(GL_LINE_STIPPLE, cur->line_stipple);
        enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op);
        enable_disable(GL_MULTISAMPLE, cur->multisample);
        enable_disable(GL_NORMALIZE, cur->normalize);
        enable_disable(GL_POINT_SMOOTH, cur->point_smooth);
        enable_disable(GL_POLYGON_OFFSET_FILL, cur->polygon_offset_fill);
        enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage);
        enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one);
        enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage);
        enable_disable(GL_SCISSOR_TEST, cur->scissor_test);
        enable_disable(GL_STENCIL_TEST, cur->stencil_test);
        enable_disable(GL_TEXTURE_2D, cur->texture_2d);
    }

#ifndef USE_ES2
    if (cur->mask & GL_FOG_BIT) {
        enable_disable(GL_FOG, cur->fog);
        glFogfv(GL_FOG_COLOR, cur->fog_color);
        glFogf(GL_FOG_DENSITY, cur->fog_density);
        glFogf(GL_FOG_START, cur->fog_start);
        glFogf(GL_FOG_END, cur->fog_end);
        glFogf(GL_FOG_MODE, cur->fog_mode);
    }
#endif

    if (cur->mask & GL_HINT_BIT) {
        enable_disable(GL_PERSPECTIVE_CORRECTION_HINT, cur->perspective_hint);
        enable_disable(GL_POINT_SMOOTH_HINT, cur->point_smooth_hint);
        enable_disable(GL_LINE_SMOOTH_HINT, cur->line_smooth_hint);
        enable_disable(GL_FOG_HINT, cur->fog_hint);
        enable_disable(GL_GENERATE_MIPMAP_HINT, cur->mipmap_hint);
    }

    if (cur->mask & GL_LINE_BIT) {
        enable_disable(GL_LINE_SMOOTH, cur->line_smooth);
        // TODO: stipple stuff here
        glLineWidth(cur->line_width);
    }

    if (cur->mask & GL_MULTISAMPLE_BIT) {
        enable_disable(GL_MULTISAMPLE, cur->multisample);
        enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage);
        enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one);
        enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage);
    }

#ifndef USE_ES2
    if (cur->mask & GL_POINT_BIT) {
        enable_disable(GL_POINT_SMOOTH, cur->point_smooth);
        glPointSize(cur->point_size);
    }
#endif

    if (cur->mask & GL_SCISSOR_BIT) {
        enable_disable(GL_SCISSOR_TEST, cur->scissor_test);
        glScissor(v4(cur->scissor_box));
    }

    if (cur->mask & GL_TEXTURE_BIT) {
        glBindTexture(GL_TEXTURE_2D, cur->texture);
    }

    free(cur->clip_planes_enabled);
    free(cur->clip_planes);
    free(cur->lights_enabled);
    free(cur->lights);
    free(cur);
}
コード例 #2
0
ファイル: BBTestVector.cpp プロジェクト: leag37/BlockBlock
	/** 
	 * Test constructing and destructing a vector
	 */
	void TestVector::TestConstructor()
	{
		// Plain Old Data
		//---------------
		
		// Default constructor
		Vector<int> v1;
		AssertEquals(0u, v1.Size());

		// Fill constructor
		Vector<int> v2(3u);
		AssertEquals(3u, v2.Size());
		AssertEquals(3u, v2.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(0, v2[i]);
		}

		// Fill constructor with value
		Vector<int> v3(3u, 3);
		AssertEquals(3u, v3.Size());
		AssertEquals(3u, v3.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v3[i]);
		}
		 
		// Copy constructor
		Vector<int> v4(v3);
		AssertEquals(3u, v4.Size());
		AssertEquals(3u, v4.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v4[i]);
		}
		 
		// Assignment
		Vector<int> v5 = v4;
		AssertEquals(3u, v5.Size());
		AssertEquals(3u, v5.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v5[i]);
		}
		
		// Class
		//------
		
		// Default simple object
		SimpleClass c1 = SimpleClass();
		SimpleClass c2 = SimpleClass(1, 2);

		// Default constructor
		Vector<SimpleClass> v6;
		AssertEquals(0u, v6.Size());

		// Fill constructor
		Vector<SimpleClass> v7(3u);
		AssertEquals(3u, v7.Size());
		AssertEquals(3u, v7.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c1, v7[i]);
		}

		// Fill constructor with value
		Vector<SimpleClass> v8(3u, c2);
		AssertEquals(3u, v8.Size());
		AssertEquals(3u, v8.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v8[i]);
		}
		 
		// Copy constructor
		Vector<SimpleClass> v9(v8);
		AssertEquals(3u, v9.Size());
		AssertEquals(3u, v9.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v9[i]);
		}
		 
		// Assignment
		Vector<SimpleClass> v10 = v9;
		AssertEquals(3u, v10.Size());
		AssertEquals(3u, v10.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v10[i]);
		}
	}
コード例 #3
0
ファイル: scene.cpp プロジェクト: DreamTeamHelha/ProjectCpp
bool Scene::loadMap()
{
    // chargement des images
    QPixmap *grassTile = new QPixmap(QCoreApplication::applicationDirPath() + "/data/tiles/GrassTile.png");
    if (grassTile->isNull())
    {
       return false;
    }

    QPixmap *roadTile = new QPixmap(QCoreApplication::applicationDirPath() + "/data/tiles/RoadTile.png");
    if (roadTile->isNull())
    {
        return false;
    }
    QPixmap *mudTile = new QPixmap(QCoreApplication::applicationDirPath() + "/data/tiles/MudTile.png");
    if (mudTile->isNull())
    {
        return false;
    }

    // remplissage de la scène graphique avec les tuiles
    for(int x=0;x<m_tilemap->width();x++)
    {
        for(int y=0;y<m_tilemap->height();y++)
        {
            QGraphicsPixmapItem *item;
            switch(m_tilemap->tile(x,y))
            {
            case GroundType::Asphalt :  item = new QGraphicsPixmapItem(*roadTile);
                      break;
            case GroundType::Mud :      item = new QGraphicsPixmapItem( *mudTile);
                      break;
            default : item = new QGraphicsPixmapItem(*grassTile);
            }
            item->setPos(x*32,y*32);
            this->graphicsScene()->addItem(item);
        }
    }

    // ajoute des "murs" autour de la scène pour éviter que des objets ne sortent de la zone de jeu
    Vector v1;
    Vector v2(m_tilemap->width()*32,0.f);
    Vector v3(0.f,m_tilemap->height()*32);
    Vector v4(m_tilemap->width()*32,m_tilemap->height()*32);

    b2BodyDef bodyDef;
    bodyDef.type = b2_staticBody;
    b2Body *body = physicsWorld()->CreateBody(&bodyDef);
    b2EdgeShape lineUp;
    lineUp.Set(v1,v2);
    body->CreateFixture(&lineUp,1);
    b2EdgeShape lineLeft;
    lineLeft.Set(v1,v3);
    body->CreateFixture(&lineLeft,1);
    b2EdgeShape lineRight;
    lineRight.Set(v2,v4);
    body->CreateFixture(&lineRight,1);
    b2EdgeShape lineBottom;
    lineBottom.Set(v3,v4);
    body->CreateFixture(&lineBottom,1);

    return true;
}
コード例 #4
0
ファイル: GodRays.cpp プロジェクト: kidd32pg/natureal
void GodRays::end()
{
	// kreslit zas do standardniho zadniho bufferu
	
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	glDrawBuffer(GL_BACK);
	// viewport zpátky
	glViewport(0,0,g_WinWidth, g_WinHeight);
	v4 lposScreen = glCoordToScreenSpace(v4(	light->positionFixedToSkybox.x, 
												light->positionFixedToSkybox.y,
												light->positionFixedToSkybox.z,
												1.0)
										);
	//printf("x=%f, y=%f \n", lposScreen.x, lposScreen.y);
	
	// blend textures and draw them
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, g_WinWidth, 0, g_WinHeight, -1,1);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glTranslatef(0.0, -.1, 0.0), 
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, originalColor);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, forRaysColor);
	glColor4f(1.f,1.f,1.f,1.f);
	shader->use(true);
	shader->setUniform1i(originalColorLocation, 0);
 	shader->setUniform1i(forRaysColorLocation, 1);
	
	shader->setUniform2f(lightPosLocation, lposScreen.x,lposScreen.y );
	shader->setUniform1f(lightDOTviewLocation, lightDirDOTviewDirValue);
	glBegin(GL_QUADS);
		glTexCoord2f(0.f, 0.f); glVertex2i(0,0);
		glTexCoord2f(1.f, 0.f); glVertex2i(0+g_WinWidth,0);
		glTexCoord2f(1.f, 1.f); glVertex2i(0+g_WinWidth,0+g_WinHeight);
		glTexCoord2f(0.f, 1.f); glVertex2i(0,0+g_WinHeight);
	glEnd();

	shader->use(false);
	
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glActiveTexture(GL_TEXTURE0);


#if TEST
	// show godrays textures
	
	show_texture(originalColor, 400, 0, 200, 200);
	show_texture(originalDepth, 200, 0, 200, 200);
    show_texture(forRaysColor, 0, 0, 200, 200);
#endif	

	
	
}
コード例 #5
0
int main (int, char**)
{
  UnitTest t (72);

  Variant v0 (true);
  Variant v1 (42);
  Variant v2 (3.14);
  Variant v3 ("foo");
  Variant v4 (1234567890, Variant::type_date);
  Variant v5 (1200, Variant::type_duration);

  Variant v00 = v0 != v0;
  t.is (v00.type (), Variant::type_boolean, "true != true --> boolean");
  t.is (v00.get_bool (), false,             "true != true --> false");

  Variant v01 = v0 != v1;
  t.is (v01.type (), Variant::type_boolean, "true != 42 --> boolean");
  t.is (v01.get_bool (), true,              "true != 42 --> true");

  Variant v02 = v0 != v2;
  t.is (v02.type (), Variant::type_boolean, "true != 3.14 --> boolean");
  t.is (v02.get_bool (), true,              "true != 3.14 --> true");

  Variant v03 = v0 != v3;
  t.is (v03.type (), Variant::type_boolean, "true != 'foo' --> boolean");
  t.is (v03.get_bool (), true,              "true != 'foo' --> true");

  Variant v04 = v0 != v4;
  t.is (v04.type (), Variant::type_boolean, "true != 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "true != 1234567890 --> true");

  Variant v05 = v0 != v5;
  t.is (v05.type (), Variant::type_boolean, "true != 1200 --> boolean");
  t.is (v05.get_bool (), true,              "true != 1200 --> true");

  Variant v10 = v1 != v0;
  t.is (v10.type (), Variant::type_boolean, "42 != true --> boolean");
  t.is (v10.get_bool (), true,              "42 != true --> true");

  Variant v11 = v1 != v1;
  t.is (v11.type (), Variant::type_boolean, "42 != 42 --> boolean");
  t.is (v11.get_bool (), false,             "42 != 42 --> false");

  Variant v12 = v1 != v2;
  t.is (v12.type (), Variant::type_boolean, "42 != 3.14 --> boolean");
  t.is (v12.get_bool (), true,              "42 != 3.14 --> true");

  Variant v13 = v1 != v3;
  t.is (v13.type (), Variant::type_boolean, "42 != 'foo' --> boolean");
  t.is (v13.get_bool (), true,              "42 != 'foo' --> true");

  Variant v14 = v1 != v4;
  t.is (v04.type (), Variant::type_boolean, "42 != 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "42 != 1234567890 --> true");

  Variant v15 = v1 != v5;
  t.is (v15.type (), Variant::type_boolean, "42 != 1200 --> boolean");
  t.is (v15.get_bool (), true,              "42 != 1200 --> true");

  Variant v20 = v2 != v0;
  t.is (v20.type (), Variant::type_boolean, "3.14 != true --> boolean");
  t.is (v20.get_bool (), true,              "3.14 != true --> true");

  Variant v21 = v2 != v1;
  t.is (v21.type (), Variant::type_boolean, "3.14 != 42 --> boolean");
  t.is (v21.get_bool (), true,              "3.14 != 42 --> true");

  Variant v22 = v2 != v2;
  t.is (v22.type (), Variant::type_boolean, "3.14 != 3.14 --> boolean");
  t.is (v22.get_bool (), false,             "3.14 != 3.14 --> false");

  Variant v23 = v2 != v3;
  t.is (v23.type (), Variant::type_boolean, "3.14 != 'foo' --> boolean");
  t.is (v23.get_bool (), true,              "3.14 != 'foo' --> true");

  Variant v24 = v2 != v4;
  t.is (v24.type (), Variant::type_boolean, "3.14 != 1234567890 --> boolean");
  t.is (v24.get_bool (), true,              "3.14 != 1234567890 --> true");

  Variant v25 = v2 != v5;
  t.is (v25.type (), Variant::type_boolean, "3.14 != 1200 --> boolean");
  t.is (v25.get_bool (), true,              "3.14 != 1200 --> true");

  Variant v30 = v3 != v0;
  t.is (v30.type (), Variant::type_boolean, "'foo' != true --> boolean");
  t.is (v30.get_bool (), true,              "'foo' != true --> true");

  Variant v31 = v3 != v1;
  t.is (v31.type (), Variant::type_boolean, "'foo' != 42 --> boolean");
  t.is (v31.get_bool (), true,              "'foo' != 42 --> true");

  Variant v32 = v3 != v2;
  t.is (v32.type (), Variant::type_boolean, "'foo' != 3.14 --> boolean");
  t.is (v32.get_bool (), true,              "'foo' != 3.14 --> true");

  Variant v33 = v3 != v3;
  t.is (v33.type (), Variant::type_boolean, "'foo' != 'foo' --> boolean");
  t.is (v33.get_bool (), false,             "'foo' != 'foo' --> false");

  Variant v34 = v3 != v4;
  t.is (v34.type (), Variant::type_boolean, "'foo' != 1234567890 --> boolean");
  t.is (v34.get_bool (), true,              "'foo' != 1234567890 --> true");

  Variant v35 = v3 != v5;
  t.is (v35.type (), Variant::type_boolean, "'foo' != 1200 --> boolean");
  t.is (v35.get_bool (), true,              "'foo' != 1200 --> true");

  Variant v40 = v4 != v0;
  t.is (v40.type (), Variant::type_boolean, "1234567890 != true --> boolean");
  t.is (v40.get_bool (), true,              "1234567890 != true --> true");

  Variant v41 = v4 != v1;
  t.is (v41.type (), Variant::type_boolean, "1234567890 != 42 --> boolean");
  t.is (v41.get_bool (), true,              "1234567890 != 42 --> true");

  Variant v42 = v4 != v2;
  t.is (v42.type (), Variant::type_boolean, "1234567890 != 3.14 --> boolean");
  t.is (v42.get_bool (), true,              "1234567890 != 3.14 --> true");

  Variant v43 = v4 != v3;
  t.is (v43.type (), Variant::type_boolean, "1234567890 != 'foo' --> boolean");
  t.is (v43.get_bool (), true,              "1234567890 != 'foo' --> true");

  Variant v44 = v4 != v4;
  t.is (v44.type (), Variant::type_boolean, "1234567890 != 1234567890 --> boolean");
  t.is (v44.get_bool (), false,             "1234567890 != 1234567890 --> false");

  Variant v45 = v4 != v5;
  t.is (v45.type (), Variant::type_boolean, "1234567890 != 1200 --> boolean");
  t.is (v45.get_bool (), true,              "1234567890 != 1200 --> true");

  Variant v50 = v5 != v0;
  t.is (v50.type (), Variant::type_boolean, "1200 != true --> boolean");
  t.is (v50.get_bool (), true,              "1200 != true --> true");

  Variant v51 = v5 != v1;
  t.is (v51.type (), Variant::type_boolean, "1200 != 42 --> boolean");
  t.is (v51.get_bool (), true,              "1200 != 42 --> true");

  Variant v52 = v5 != v2;
  t.is (v52.type (), Variant::type_boolean, "1200 != 3.14 --> boolean");
  t.is (v52.get_bool (), true,              "1200 != 3.14 --> true");

  Variant v53 = v5 != v3;
  t.is (v53.type (), Variant::type_boolean, "1200 != 'foo' --> boolean");
  t.is (v53.get_bool (), true,              "1200 != 'foo' --> true");

  Variant v54 = v5 != v4;
  t.is (v04.type (), Variant::type_boolean, "1200 != 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "1200 != 1234567890 --> true");

  Variant v55 = v5 != v5;
  t.is (v55.type (), Variant::type_boolean, "1200 != 1200 --> boolean");
  t.is (v55.get_bool (), false,             "1200 != 1200 --> false");

  return 0;
}
コード例 #6
0
   void QuatGenMetricTest::testGenTimingSetRot()
   {
      double bokd = 1;
      float bokf = 1;
      gmtl::Quat<double> q1;
      const long iters(25000);
      CPPUNIT_METRIC_START_TIMING();

      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q1, gmtl::makeNormal( gmtl::AxisAngled( bokd, bokd, bokd, bokd ) ) );
         bokd += q1[2];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q2; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q2, gmtl::makeNormal( gmtl::AxisAnglef( bokf, bokf, bokf, bokf ) ) );
         bokf -= q2[3];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q3; bokd = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q3, gmtl::makeNormal( gmtl::AxisAngled( bokd, gmtl::Vec<double, 3>( bokd, bokd, bokd ) ) ) );
         bokd *= q3[1] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q4; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q4, gmtl::makeNormal( gmtl::AxisAnglef( bokf, gmtl::Vec<float, 3>( bokf, bokf, bokf ) ) ) );
         bokf += q4[1] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q5;
      gmtl::Vec<double, 3> v4(1,2,3), v5(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q5, gmtl::makeNormal( v4 ), gmtl::makeNormal( v5 ) );
         v4[2] += q5[1] + 1.2;
         v5[0] -= q5[2] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,vec3d,vec3d)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q6;
      gmtl::Vec<float, 3> v6(1,2,3), v7(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q6, gmtl::makeNormal( v6 ), gmtl::makeNormal( v7 ) );
         v6[2] += q6[1] + 1.2f;
         v7[0] -= q6[2] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,vec3f,vec3f)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      // force intelligent compilers to do all the iterations (ie. to not optimize them out),
      // by using the variables computed...
      CPPUNIT_ASSERT( bokf != 0.998f );
      CPPUNIT_ASSERT( bokd != 0.0998 );
      CPPUNIT_ASSERT( q1[0] != 10000.0f );
      CPPUNIT_ASSERT( q2[1] != 10000.0f );
      CPPUNIT_ASSERT( q3[2] != 10000.0f );
      CPPUNIT_ASSERT( q4[3] != 10000.0f );
      CPPUNIT_ASSERT( q5[0] != 10000.0f );
      CPPUNIT_ASSERT( q6[1] != 10000.0f );
   }
コード例 #7
0
ファイル: variant_and.t.cpp プロジェクト: austinwagner/task
int main (int, char**)
{
  UnitTest t (76);

  Variant v0 (true);
  Variant v1 (42);
  Variant v2 (3.14);
  Variant v3 ("foo");
  Variant v4 (1234567890, Variant::type_date);
  Variant v5 (1200, Variant::type_duration);

  // Truth table.
  Variant vFalse (false);
  Variant vTrue (true);
  t.is (vFalse && vFalse, false, "false && false --> false");
  t.is (vFalse && vTrue,  false, "false && true --> false");
  t.is (vTrue && vFalse,  false, "true && false --> false");
  t.is (vTrue && vTrue,   true,  "true && true --> true");

  Variant v00 = v0 && v0;
  t.is (v00.type (), Variant::type_boolean, "true && true --> boolean");
  t.is (v00.get_bool (), true,              "true && true --> true");

  Variant v01 = v0 && v1;
  t.is (v01.type (), Variant::type_boolean, "true && 42 --> boolean");
  t.is (v01.get_bool (), true,              "true && 42 --> true");

  Variant v02 = v0 && v2;
  t.is (v02.type (), Variant::type_boolean, "true && 3.14 --> boolean");
  t.is (v02.get_bool (), true,              "true && 3.14 --> true");

  Variant v03 = v0 && v3;
  t.is (v03.type (), Variant::type_boolean, "true && 'foo' --> boolean");
  t.is (v03.get_bool (), true,              "true && 'foo' --> true");

  Variant v04 = v0 && v4;
  t.is (v04.type (), Variant::type_boolean, "true && 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "true && 1234567890 --> true");

  Variant v05 = v0 && v5;
  t.is (v05.type (), Variant::type_boolean, "true && 1200 --> boolean");
  t.is (v05.get_bool (), true,              "true && 1200 --> true");

  Variant v10 = v1 && v0;
  t.is (v10.type (), Variant::type_boolean, "42 && true --> boolean");
  t.is (v10.get_bool (), true,              "42 && true --> true");

  Variant v11 = v1 && v1;
  t.is (v11.type (), Variant::type_boolean, "42 && 42 --> boolean");
  t.is (v11.get_bool (), true,              "42 && 42 --> true");

  Variant v12 = v1 && v2;
  t.is (v12.type (), Variant::type_boolean, "42 && 3.14 --> boolean");
  t.is (v12.get_bool (), true,              "42 && 3.14 --> true");

  Variant v13 = v1 && v3;
  t.is (v13.type (), Variant::type_boolean, "42 && 'foo' --> boolean");
  t.is (v13.get_bool (), true,              "42 && 'foo' --> true");

  Variant v14 = v1 && v4;
  t.is (v04.type (), Variant::type_boolean, "42 && 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "42 && 1234567890 --> true");

  Variant v15 = v1 && v5;
  t.is (v15.type (), Variant::type_boolean, "42 && 1200 --> boolean");
  t.is (v15.get_bool (), true,              "42 && 1200 --> true");

  Variant v20 = v2 && v0;
  t.is (v20.type (), Variant::type_boolean, "3.14 && true --> boolean");
  t.is (v20.get_bool (), true,              "3.14 && true --> true");

  Variant v21 = v2 && v1;
  t.is (v21.type (), Variant::type_boolean, "3.14 && 42 --> boolean");
  t.is (v21.get_bool (), true,              "3.14 && 42 --> true");

  Variant v22 = v2 && v2;
  t.is (v22.type (), Variant::type_boolean, "3.14 && 3.14 --> boolean");
  t.is (v22.get_bool (), true,              "3.14 && 3.14 --> true");

  Variant v23 = v2 && v3;
  t.is (v23.type (), Variant::type_boolean, "3.14 && 'foo' --> boolean");
  t.is (v23.get_bool (), true,              "3.14 && 'foo' --> true");

  Variant v24 = v2 && v4;
  t.is (v24.type (), Variant::type_boolean, "3.14 && 1234567890 --> boolean");
  t.is (v24.get_bool (), true,              "3.14 && 1234567890 --> true");

  Variant v25 = v2 && v5;
  t.is (v25.type (), Variant::type_boolean, "3.14 && 1200 --> boolean");
  t.is (v25.get_bool (), true,              "3.14 && 1200 --> true");

  Variant v30 = v3 && v0;
  t.is (v30.type (), Variant::type_boolean, "'foo' && true --> boolean");
  t.is (v30.get_bool (), true,              "'foo' && true --> true");

  Variant v31 = v3 && v1;
  t.is (v31.type (), Variant::type_boolean, "'foo' && 42 --> boolean");
  t.is (v31.get_bool (), true,              "'foo' && 42 --> true");

  Variant v32 = v3 && v2;
  t.is (v32.type (), Variant::type_boolean, "'foo' && 3.14 --> boolean");
  t.is (v32.get_bool (), true,              "'foo' && 3.14 --> true");

  Variant v33 = v3 && v3;
  t.is (v33.type (), Variant::type_boolean, "'foo' && 'foo' --> boolean");
  t.is (v33.get_bool (), true,              "'foo' && 'foo' --> true");

  Variant v34 = v3 && v4;
  t.is (v34.type (), Variant::type_boolean, "'foo' && 1234567890 --> boolean");
  t.is (v34.get_bool (), true,              "'foo' && 1234567890 --> true");

  Variant v35 = v3 && v5;
  t.is (v35.type (), Variant::type_boolean, "'foo' && 1200 --> boolean");
  t.is (v35.get_bool (), true,              "'foo' && 1200 --> true");

  Variant v40 = v4 && v0;
  t.is (v40.type (), Variant::type_boolean, "1234567890 && true --> boolean");
  t.is (v40.get_bool (), true,              "1234567890 && true --> true");

  Variant v41 = v4 && v1;
  t.is (v41.type (), Variant::type_boolean, "1234567890 && 42 --> boolean");
  t.is (v41.get_bool (), true,              "1234567890 && 42 --> true");

  Variant v42 = v4 && v2;
  t.is (v42.type (), Variant::type_boolean, "1234567890 && 3.14 --> boolean");
  t.is (v42.get_bool (), true,              "1234567890 && 3.14 --> true");

  Variant v43 = v4 && v3;
  t.is (v43.type (), Variant::type_boolean, "1234567890 && 'foo' --> boolean");
  t.is (v43.get_bool (), true,              "1234567890 && 'foo' --> true");

  Variant v44 = v4 && v4;
  t.is (v44.type (), Variant::type_boolean, "1234567890 && 1234567890 --> boolean");
  t.is (v44.get_bool (), true,              "1234567890 && 1234567890 --> true");

  Variant v45 = v4 && v5;
  t.is (v45.type (), Variant::type_boolean, "1234567890 && 1200 --> boolean");
  t.is (v45.get_bool (), true,              "1234567890 && 1200 --> true");

  Variant v50 = v5 && v0;
  t.is (v50.type (), Variant::type_boolean, "1200 && true --> boolean");
  t.is (v50.get_bool (), true,              "1200 && true --> true");

  Variant v51 = v5 && v1;
  t.is (v51.type (), Variant::type_boolean, "1200 && 42 --> boolean");
  t.is (v51.get_bool (), true,              "1200 && 42 --> true");

  Variant v52 = v5 && v2;
  t.is (v52.type (), Variant::type_boolean, "1200 && 3.14 --> boolean");
  t.is (v52.get_bool (), true,              "1200 && 3.14 --> true");

  Variant v53 = v5 && v3;
  t.is (v53.type (), Variant::type_boolean, "1200 && 'foo' --> boolean");
  t.is (v53.get_bool (), true,              "1200 && 'foo' --> true");

  Variant v54 = v5 && v4;
  t.is (v04.type (), Variant::type_boolean, "1200 && 1234567890 --> boolean");
  t.is (v04.get_bool (), true,              "1200 && 1234567890 --> true");

  Variant v55 = v5 && v5;
  t.is (v55.type (), Variant::type_boolean, "1200 && 1200 --> boolean");
  t.is (v55.get_bool (), true,              "1200 && 1200 --> true");

  return 0;
}
コード例 #8
0
ファイル: ClampNode.cpp プロジェクト: vmichele/LEGO_CREATOR
osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v5);
    vertices->push_back(v6);

    // Top face
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left part back
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v10);

    // Left part left ext
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v10);
    vertices->push_back(v11);

    // Left part front
    vertices->push_back(v4);
    vertices->push_back(v11);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Left part left int
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Right part back
    vertices->push_back(v6);
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v16);

    // Left part left ext
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v16);
    vertices->push_back(v17);

    // Left part front
    vertices->push_back(v5);
    vertices->push_back(v17);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Left part left int
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Bottom front
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v25);
    vertices->push_back(v24);

    // Bottom right
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v26);
    vertices->push_back(v25);

    // Bottom back
    vertices->push_back(v22);
    vertices->push_back(v23);
    vertices->push_back(v27);
    vertices->push_back(v26);

    // Bottom left
    vertices->push_back(v23);
    vertices->push_back(v20);
    vertices->push_back(v24);
    vertices->push_back(v27);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry;
    
    // Match vertices
    clampGeometry->setVertexArray(vertices);
    
    // Create colors
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);
    
    // Match color
    clampGeometry->setColorArray(colors);
    clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    
    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    double w = pw - mwp;
    double h = phmp - mhp;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    
    // Match normals
    clampGeometry->setNormalArray(normals);
    clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4));

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4));

    // Retesslate to create hole
    osgUtil::Tessellator tesslator;
    tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
    tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
    tesslator.retessellatePolygons(*clampGeometry);

    // Create 17 GL_QUADS, i.e. 18*4 vertices
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4));

    // Return the tile whithout plot
    return clampGeometry.release();
}
コード例 #9
0
void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
{
	SShadowVolume* svp = 0;

	// builds the shadow volume and adds it to the shadow volume list.

	if (ShadowVolumes.size() > (u32)ShadowVolumesUsed)
	{
		// get the next unused buffer
		svp = &ShadowVolumes[ShadowVolumesUsed];
		if (svp->size >= IndexCount*5)
			svp->count = 0;
		else
		{
			svp->size = IndexCount*5;
			svp->count = 0;
			delete [] svp->vertices;
			svp->vertices = new core::vector3df[svp->size];
		}

		++ShadowVolumesUsed;
	}
	else
	{
		// add a buffer
		SShadowVolume tmp;
		// lets make a rather large shadowbuffer
		tmp.size = IndexCount*5;
		tmp.count = 0;
		tmp.vertices = new core::vector3df[tmp.size];
		ShadowVolumes.push_back(tmp);
		svp = &ShadowVolumes[ShadowVolumes.size()-1];
		++ShadowVolumesUsed;
	}

	const s32 faceCount = (s32)(IndexCount / 3);

	if (!Edges || faceCount * 6 > EdgeCount)
	{
		delete [] Edges;
		EdgeCount = faceCount * 6;
		Edges = new u16[EdgeCount];
	}

	s32 numEdges = 0;
	const core::vector3df ls = light * Infinity; // light scaled

	//if (UseZFailMethod)
	//	createZFailVolume(faceCount, numEdges, light, svp);
	//else
	//	createZPassVolume(faceCount, numEdges, light, svp, false);

	// the createZFailVolume does currently not work 100% correctly,
	// so we create createZPassVolume with caps if the zfail method
	// is used
	createZPassVolume(faceCount, numEdges, light, svp, UseZFailMethod);

	for (s32 i=0; i<numEdges; ++i)
	{
		core::vector3df &v1 = Vertices[Edges[2*i+0]];
		core::vector3df &v2 = Vertices[Edges[2*i+1]];
		core::vector3df v3(v1 - ls);
		core::vector3df v4(v2 - ls);

		// Add a quad (two triangles) to the vertex list
		if (svp->vertices && svp->count < svp->size-5)
		{
			svp->vertices[svp->count++] = v1;
			svp->vertices[svp->count++] = v2;
			svp->vertices[svp->count++] = v3;

			svp->vertices[svp->count++] = v2;
			svp->vertices[svp->count++] = v4;
			svp->vertices[svp->count++] = v3;
		}
	}
}
コード例 #10
0
ファイル: World.cpp プロジェクト: kucerad/natu-renderer
void World::init()
{
	printf("INITIALIZING WORLD:\n");
	shaderManager.init();

	/*
	// create LOD buffers
	glGenTextures(1, &db_LOD_ID );
		glBindTexture(GL_TEXTURE_2D, db_LOD_ID );
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, g_WinWidth * LOD_REDUCTION, g_WinHeight * LOD_REDUCTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
	glGenTextures(1, &cb_LOD_ID );
		glBindTexture(GL_TEXTURE_2D, cb_LOD_ID );
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_WinWidth * LOD_REDUCTION, g_WinHeight * LOD_REDUCTION, 0, GL_RGB, GL_FLOAT, 0);
	 glGenFramebuffersEXT(1, &fb_LOD_ID);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb_LOD_ID);
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, db_LOD_ID, 0);
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, cb_LOD_ID, 0);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	*/
	p_terrain = new Terrain(&textureManager,&shaderManager);
	
	p_activeCamera = new Camera();
	p_activeCamera->setup(HUMAN_POSITION, HUMAN_DIRECTION, v3(0.0,1.f,0.f), &g_WinWidth, &g_WinHeight, 60.0, 0.1f, 1000.f);
	//p_activeCamera->setup(v3(-100.0,60.f,60.f), v3(1.0,-0.7f,-0.4f), v3(0.0,1.f,0.f), &g_WinWidth, &g_WinHeight, 60.0, 1.f, 1000.f);
	//p_activeCamera->setup(LIGHT_POSITION, -LIGHT_POSITION, v3(0.0,1.f,0.f), &g_WinWidth, &g_WinHeight, 60.0, 1.f, 1000.f);
	p_activeCamera->setTerrain(p_terrain);
	p_activeCamera->setMode(g_cameraMode);
	g_viewer_position = & (p_activeCamera->position);
	g_viewer_direction= & (p_activeCamera->direction);

	// sun
	p_activeLight = new Light(&textureManager);
	p_activeLight->init(); // setup framebuffers for shadow mapping
	p_activeLight->setup(GL_LIGHT0, &g_light_position, &g_light_direction, sunAmb, sunDif, sunSpe, 180, 0.0);
	p_activeLight->turnOn();
	p_activeLight->initShadowMapping(p_activeCamera, SHADOWMAP_RESOLUTION_X);
	
	
	// sky
	p_skybox = new SkyBox(&textureManager, &shaderManager, SKYBOX_TEX_FILENAMES);
	p_skybox->init();
	p_skybox->p_activeCamera = p_activeCamera;
	p_skybox->p_light = p_activeLight;

	p_terrain->init();

	p_godRays = new GodRays(&shaderManager, p_activeLight);
	p_fog	  = new Fog(g_fog_density, g_fog_start, g_fog_end, v4(0.55, 0.55, 0.6, 1.0)*0.6);
	int count = 0;
	// plant grass	
	printf("Planting grass...\n");
	p_grass_prototype = new Grass(&textureManager,&shaderManager);
	p_grass_prototype->init();
	p_grass_growth = p_grass_prototype->getCopy();
	grass_planter.init(	p_terrain,
						p_grass_prototype,
						p_grass_growth,
						GRASS_MIN_HEIGHT,
						GRASS_MAX_HEIGHT,
						GRASS_MIN_DIST,
						500,
						500 );
	count = grass_planter.plantVegetationCount(g_GrassCount);
	printf("\tcount: %i\n", count);

	// plant trees
	printf("Planting trees1...\n");
	p_tree1_prototype = new Tree1(&textureManager,&shaderManager);
	p_tree1_prototype->init();
	p_tree1_growth = p_tree1_prototype->getCopy();
	tree1_planter.init(	p_terrain,
						p_tree1_prototype,
						p_tree1_growth,
						TREE1_MIN_HEIGHT,
						TREE1_MAX_HEIGHT,
						TREE1_MIN_DIST,
						100,
						100 );
 	count = tree1_planter.plantVegetationCount(g_Tree1Count);
	printf("\tcount: %i\n", count);

	// plant trees
	printf("Planting trees2...\n");
	p_tree2_prototype = new Tree2(&textureManager,&shaderManager);
	p_tree2_prototype->init();
	p_tree2_growth = p_tree2_prototype->getCopy();
	tree2_planter.init(	p_terrain,
						p_tree2_prototype,
						p_tree2_growth,
						TREE2_MIN_HEIGHT,
						TREE2_MAX_HEIGHT,
						TREE2_MIN_DIST,
						100,
						100 );
 	count = tree2_planter.plantVegetationCount(g_Tree2Count);
	printf("\tcount: %i\n", count);

//===============================================================================
// TREE INIT
//===============================================================================
	printf("---- DYNAMIC TREE INIT BEGIN ----\n");
	p_dtree = new DTree(&textureManager, &shaderManager);
		p_dtree->loadOBJT( DYN_TREE::OBJT_FILENAME );
		//p_dtree->init();
		p_dtree->viewer_direction = &p_activeCamera->direction;
		p_dtree->viewer_position = &p_activeCamera->position;

	// positions
		dtree_planter.init(p_terrain, p_dtree);
		dtree_planter.size_factor = g_tree_areaFactor;
		dtree_planter.createCandidates(g_dtreemin, g_dtreemax, g_tree_dither, g_tree_mean_distance);
		dtree_planter.setInstanceCount(g_TreeDCount);
		
	p_dtree->init(); 
	printf("----- END DYNAMIC TREE INIT ----\n");
//===============================================================================
// END TREE INIT 
//===============================================================================

	// SOUNDs
	printf("Starting sound... \n");
	p_backgroundSound = new Sound();
	p_backgroundSound->play();
	printf("Sound is playing... \n");

	printf("WORLD CREATED:\n");

}
コード例 #11
0
ファイル: Tc2.cpp プロジェクト: kuailexs/symbiandump-mw2
void CHttpTestCase2::DoRunL()
	{
	// Literals used in the function
	_LIT8(KWapTestUrl,			"http://WapTestIP/perl/dumpform.pl");

	// Replace the host name in the URL
	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();

	TUriParser8 testURI;
	testURI.Parse(newUrlPtr8);

	//open a Session
	RHTTPSession mySession;
	mySession.OpenL();
	CleanupClosePushL(mySession);
	iEngine->Utils().LogIt(_L("Session Created (TC2)"));
	iEngine->Utils().LogIt(_L("Session (Default) parameters: RHTTPProxy aProxy = RHTTPProxy(), MHTTPSessionCallback* aCallback = NULL"));

	// Get the mySession'string pool handle;
	iMyStrP = mySession.StringPool();

	//get strings used in this test
	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable());
	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable());
	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable());

	// Create , open and push in the CS a Transaction in mySession 
	RHTTPTransaction myTransaction;
	myTransaction = mySession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
	CleanupClosePushL(myTransaction);
	iEngine->Utils().LogIt(_L("Transaction Created in mySession"));

	// Get a handle of the request in myTransaction
	RHTTPRequest myRequest = myTransaction.Request();
	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
	// provide  some headers 
	THTTPHdrVal v2(textPlain);
	THTTPHdrVal v3(textHtml);
	THTTPHdrVal v4(6);
	THTTPHdrVal v5(mimeType);

	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2 );
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), v4);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5);

	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
	iEngine->Utils().LogIt(_L("Method:Post"));
	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
	iEngine->Utils().LogIt(_L("Content-Length: 4"));
	myRequest.SetBody(*this);
	iEngine->Utils().LogIt(_L("Transaction terminated"));

	// Close strings used in this session before closing the session
	//close transaction and session
	myTransaction.Close();
	iEngine->Utils().LogIt(_L("Transaction terminated"));
	mySession.Close();
	iEngine->Utils().LogIt(_L("Session terminated"));
	if (iTestFail==1)
		{
		User::Leave(-1);
		}
	CleanupStack::Pop(2); // mySession,myTansaction
	CleanupStack::PopAndDestroy(newUrl8);
	}
コード例 #12
0
ファイル: main.cpp プロジェクト: netp/esinf
int main (int argc, char * const argv[]) {    
	Vertice<int, int> v1( 1, 1 );
	Vertice<int, int> v2( 2, 2 );
	Vertice<int, int> v3( 3, 3 );
	Vertice<int, int> v4( 4, 4 );
	Vertice<int, int> v5( 5, 5 );

	Ramo<int, int> r1( 1, &v3 );
	Ramo<int, int> r2( 6, &v2 );
	Ramo<int, int> r3( 3, &v4 );
	Ramo<int, int> r4( 4, &v4 );
	Ramo<int, int> r5( 1, &v5 );
	Ramo<int, int> r6( 5, &v4 );

	ListAdjGrafo<int, int> g2;

	g2.juntar_vertice( v1.get_conteudo());
	g2.juntar_vertice( v2.get_conteudo());
	g2.juntar_vertice( v3.get_conteudo());
	g2.juntar_vertice( v4.get_conteudo());
	g2.juntar_vertice( v5.get_conteudo());
	
	g2.juntar_ramo(r1.get_conteudo(), v1.get_conteudo(), v3.get_conteudo());
	g2.juntar_ramo(r2.get_conteudo(), v1.get_conteudo(), v2.get_conteudo());
	g2.juntar_ramo(r3.get_conteudo(), v2.get_conteudo(), v4.get_conteudo());
	g2.juntar_ramo(r4.get_conteudo(), v3.get_conteudo(), v4.get_conteudo());
	g2.juntar_ramo(r1.get_conteudo(), v3.get_conteudo(), v5.get_conteudo());
	g2.juntar_ramo(r6.get_conteudo(), v5.get_conteudo(), v4.get_conteudo());

	g2.escreve_grafo();
	
	cout << endl
		<< "----------------------------------"
		<< endl
	;

	ListAdjGrafo<int, int> g;
	
	g.juntar_vertice( 1 );
	g.juntar_vertice( 2 );
	g.juntar_vertice( 3 );
	g.juntar_vertice( 4 );
	g.juntar_vertice( 5 );

	g.juntar_ramo(1, 1, 3 );
	g.juntar_ramo(6, 1, 2 );
	g.juntar_ramo(3, 2, 4 );
	g.juntar_ramo(4, 3, 4 );
	g.juntar_ramo(1, 3, 5);
	g.juntar_ramo(5, 5, 4);
	
	g.escreve_grafo();

	cout << endl
		<< "O grau de entrada do vertice "
		<< g.encontra_vertice_chave(3)
		<< g.grau_entrada(4)
	;
	
	cout << endl
		<< "----------------------------------"
		<< endl
	;
	
	g.visita_largura(v1);
		
}
コード例 #13
0
void
dmz::StarfighterPluginSpaceBoxOSG::_create_box () {

   const String ImageName (_rc.find_file (_imgRc));

   osg::ref_ptr<osg::Image> img =
      (ImageName ? osgDB::readImageFile (ImageName.get_buffer ()) : 0);

   if (img.valid ()) {

      osg::Geode* geode = new osg::Geode ();

      osg::Geometry* geom = new osg::Geometry;

      osg::Vec4Array* colors = new osg::Vec4Array;
      colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
      geom->setColorArray (colors);
      geom->setColorBinding (osg::Geometry::BIND_OVERALL);

      osg::StateSet *stateset = geom->getOrCreateStateSet ();
      stateset->setMode (GL_BLEND, osg::StateAttribute::ON);

#if 0
      osg::ref_ptr<osg::Material> material = new osg::Material;

      material->setEmission (
         osg::Material::FRONT_AND_BACK,
         osg::Vec4 (1.0, 1.0, 1.0, 1.0));

      stateset->setAttributeAndModes (material.get (), osg::StateAttribute::ON);
#endif

      osg::Texture2D *tex = new osg::Texture2D (img.get ());
      tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
      tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);

      stateset->setTextureAttributeAndModes (0, tex, osg::StateAttribute::ON);

      stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK));

      osg::Vec3Array *vertices = new osg::Vec3Array;
      osg::Vec2Array *tcoords = new osg::Vec2Array;
      osg::Vec3Array* normals = new osg::Vec3Array;

      const float Off (_offset);

      osg::Vec3 v1 (-Off, -Off, -Off);
      osg::Vec3 v2 ( Off, -Off, -Off);
      osg::Vec3 v3 ( Off,  Off, -Off);
      osg::Vec3 v4 (-Off,  Off, -Off);
      osg::Vec3 v5 (-Off, -Off,  Off);
      osg::Vec3 v6 ( Off, -Off,  Off);
      osg::Vec3 v7 ( Off,  Off,  Off);
      osg::Vec3 v8 (-Off,  Off,  Off);

      osg::Vec3 n1 ( 1.0,  1.0,  1.0);
      osg::Vec3 n2 (-1.0,  1.0,  1.0);
      osg::Vec3 n3 (-1.0, -1.0,  1.0);
      osg::Vec3 n4 ( 1.0, -1.0,  1.0);
      osg::Vec3 n5 ( 1.0,  1.0, -1.0);
      osg::Vec3 n6 (-1.0,  1.0, -1.0);
      osg::Vec3 n7 (-1.0, -1.0, -1.0);
      osg::Vec3 n8 ( 1.0, -1.0, -1.0);

      n1.normalize ();
      n2.normalize ();
      n3.normalize ();
      n4.normalize ();
      n5.normalize ();
      n6.normalize ();
      n7.normalize ();
      n8.normalize ();

//      const float F1 (5.0f);
//      const float F2 (2.5f);
      const float F1 (5.0f);
      const float F2 (2.5f);
      int count = 0;

      // 1
      vertices->push_back (v1);
      vertices->push_back (v2);
      vertices->push_back (v3);
      vertices->push_back (v4);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n2);
      normals->push_back (n3);
      normals->push_back (n4);
      count += 4;

      // 2
      vertices->push_back (v4);
      vertices->push_back (v3);
      vertices->push_back (v7);
      vertices->push_back (v8);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n4);
      normals->push_back (n3);
      normals->push_back (n7);
      normals->push_back (n8);
      count += 4;

      // 3
      vertices->push_back (v8);
      vertices->push_back (v7);
      vertices->push_back (v6);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n8);
      normals->push_back (n7);
      normals->push_back (n6);
      normals->push_back (n5);
      count += 4;

      // 4
      vertices->push_back (v5);
      vertices->push_back (v6);
      vertices->push_back (v2);
      vertices->push_back (v1);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n5);
      normals->push_back (n6);
      normals->push_back (n2);
      normals->push_back (n1);
      count += 4;

      // 5
      vertices->push_back (v3);
      vertices->push_back (v2);
      vertices->push_back (v6);
      vertices->push_back (v7);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n3);
      normals->push_back (n2);
      normals->push_back (n6);
      normals->push_back (n7);
      count += 4;

      // 6
      vertices->push_back (v1);
      vertices->push_back (v4);
      vertices->push_back (v8);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n4);
      normals->push_back (n8);
      normals->push_back (n5);
      count += 4;

      geom->setNormalArray (normals);
      geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
      geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count));
      geom->setVertexArray (vertices);
      geom->setTexCoordArray (0, tcoords);
      geode->addDrawable (geom);

      _box = new osg::MatrixTransform ();

      _box->addChild (geode);
   }
   else { _log.error << "Failed to load: " << _imgRc << ":" << ImageName << endl; }
}
コード例 #14
0
ファイル: Value.cpp プロジェクト: ncultra/Pegasus-2.5
void test01(const T& x)
{
    CIMValue v(x);
    CIMValue v2(v);
    CIMValue v3;
    // Create a null constructor
    CIMType type = v.getType();            // get the type of v
    CIMValue v4(type,false);
    v3 = v2;
    CIMValue v5;
    v5 = v4;
#ifdef IO
    if (verbose)
    {
	cout << "\n----------------------\n";
	XmlWriter::printValueElement(v3, cout);
    }
#endif
    try
    {
        T t;
        v3.get(t);
        assert (!v.isNull());
        assert (!v.isArray());
        assert (!v2.isNull());
        assert(t == x);
        assert (v3.typeCompatible(v2));
        // Confirm that the constructor created Null, not array and correct type
        assert (v4.isNull());
        assert (!v4.isArray());
        assert (v4.typeCompatible(v));
        assert (v5.isNull());
        assert (!v5.isArray());
        assert (v5.typeCompatible(v));

        // Test toMof
        Array<char> mofout;
        mofout.clear();
        MofWriter::appendValueElement(mofout, v);
        mofout.append('\0');

        // Test toXml
        Array<char> out;
        XmlWriter::appendValueElement(out, v);
        XmlWriter::appendValueElement(out, v);

        // Test toString
        String valueString = v.toString();
#ifdef IO
        if (verbose)
        {
            cout << "MOF = [" << mofout.getData() << "]" << endl;
            cout << "toString Output [" << valueString << "]" << endl;
        }
#endif

    // There should be no exceptions to this point in the test.
    }
    catch(Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }

    // From here forward, in the future we may have exceptions because
    // of the isNull which should generate an exception on the getdata.
    // ATTN: KS 12 Feb 2002 This is work in progress until we complete
    // adding the exception return to the CIMValue get functions.
    try
    {
        // Test for isNull and the setNullValue function
        CIMType type = v.getType();
        v.setNullValue(type, false);
        assert(v.isNull());

        // get the String and XML outputs for v
        String valueString2 = v.toString();
        Array<char> xmlBuffer;
        XmlWriter::appendValueElement(xmlBuffer, v);
        xmlBuffer.append('\0');

        Array<char> mofOutput2;
        MofWriter::appendValueElement(mofOutput2, v);
        mofOutput2.append('\0');
#ifdef IO
        if (verbose)
        {
            cout << "MOF NULL = [" << mofOutput2.getData() << "]" << endl;
            cout << "toString NULL Output [" << valueString2 << "]" << endl;
            cout << " XML NULL = [" << xmlBuffer.getData() << "]" << endl;
        }
#endif
        v.clear();
        assert(v.isNull());
        //v2.clear();
        //assert(v2.isNull();

    }
    catch(Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }

}
コード例 #15
0
dgFloat32 FastRayTest::PolygonIntersectSimd (const dgVector& normal, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount) const
{
	_ASSERTE (m_p0.m_w == m_p1.m_w);
	simd_128 normal1 ((simd_128&)normal & simd_128 (-1, -1, -1, 0));
	simd_128 dist (((simd_128&)normal1).DotProduct((simd_128&)m_diff));
	if ((dist < simd_128(m_dirError)).GetSignMask() & 1) {
		dgInt32 stride = dgInt32 (strideInBytes / sizeof (dgFloat32));

		simd_128 v0 (&polygon[indexArray[indexCount - 1] * stride]);
		simd_128 p0v0 (v0 - (simd_128&)m_p0);
		simd_128 tOut = normal1.DotProduct(p0v0);

		simd_128 zero (dgFloat32 (0.0f));
		// this only work for convex polygons and for single side faces 
		// walk the polygon around the edges and calculate the volume 
		simd_128 test ((tOut < zero) & (tOut > dist));
		if (test.GetSignMask()) {
			dgInt32 i3 = indexCount - 1; 
			dgInt32 i2 = indexCount - 2; 
			dgInt32 i1 = indexCount - 3; 
			dgInt32 i0 = (indexCount > 3) ? indexCount - 4 : 2; 
			for (dgInt32 i4 = 0; i4 < indexCount; i4 += 4) {
				simd_128 v0 (&polygon[indexArray[i0] * stride]);
				simd_128 v1 (&polygon[indexArray[i1] * stride]);
				simd_128 v2 (&polygon[indexArray[i2] * stride]);
				simd_128 v3 (&polygon[indexArray[i3] * stride]);
				simd_128 v4 (&polygon[indexArray[i4] * stride]);

				simd_128 p0v0 (v0 - (simd_128&)m_p0);
				simd_128 p0v1 (v1 - (simd_128&)m_p0);
				simd_128 p0v2 (v2 - (simd_128&)m_p0);
				simd_128 p0v3 (v3 - (simd_128&)m_p0);
				simd_128 p0v4 (v4 - (simd_128&)m_p0);

				simd_128 p0v0_x;
				simd_128 p0v0_y;
				simd_128 p0v0_z;
				simd_128 p0v1_x;
				simd_128 p0v1_y;
				simd_128 p0v1_z;

				Transpose4x4Simd_128 (p0v0_x, p0v0_y, p0v0_z, test, p0v0, p0v1, p0v2, p0v3);
				Transpose4x4Simd_128 (p0v1_x, p0v1_y, p0v1_z, test, p0v1, p0v2, p0v3, p0v4);

				simd_128 volume = (m_ray_yyyy * p0v1_z - m_ray_zzzz * p0v1_y) * p0v0_x + 
							      (m_ray_zzzz * p0v1_x - m_ray_xxxx * p0v1_z) * p0v0_y + 
								  (m_ray_xxxx * p0v1_y - m_ray_yyyy * p0v1_x) * p0v0_z;


				// if a least one volume is negative it mean the line cross the polygon outside this edge and do not hit the face
				if ((volume < (simd_128&)m_tolerance).GetSignMask()) {
					return 1.2f;
				}
				i3 = i4 + 3; 
				i2 = i4 + 2; 
				i1 = i4 + 1; 
				i0 = i4 + 0; 
			}

			//the line is to the left of all the polygon edges, 
			//then the intersection is the point we the line intersect the plane of the polygon
			tOut = tOut / dist;
			dgFloat32 ret;
			tOut.StoreScalar(&ret);
			_ASSERTE (ret >= dgFloat32 (0.0f));
			_ASSERTE (ret <= dgFloat32 (1.0f));
			return ret;
		}
	}
	return dgFloat32 (1.2f);
}
コード例 #16
0
int main(int argc, char* argv[])
{
// store the invoking program name
   char* prg_name = argv[0];

// create an object of cpuClock and start it
   cpuClock clock;
   clock.Start();

//
   int i;

// declare an object of the test class
   aVectorBasis vb;

   std::cout << "Default basis constructed (vb): " << vb << std::endl;

   aVector v1, v2, v3;

   v1 = aVector(5.23, 1.34, 1.45);
   v2 = aVector(2.23, 2.34, 2.45);
//   v3 = aVector(3.23, 3.34, 3.45);

   v3 = v1^v2;
   v2 = v3^v1;

   std::cout << "Coplanarity: " << v1*(v2^v3) << std::endl;
   try
   {
      vb.Set(v1, v2, v3);

      std::cout << "Basis set to three new vectors (vb): " << vb << std::endl;

      aVectorBasis vb2 = vb;

      std::cout << "This basis (vb2): " << std::endl
           << vb2 << " is a copy of" << std::endl
           << "           (vb ): " << std::endl
           << vb  << std::endl;


      v1 = aVector(22.23, 22.34, 22.45);

      std::cout << "v1 and v2 are: " << std::endl
           << v1 << std::endl
           << v2 << std::endl;

      v3 = v1^v2;
      v2 = v3^v1;

      std::cout.precision(16);
      std::cout << "v1, v2 and v3 are: " << std::endl
           << v1 << std::endl
           << v2 << std::endl
           << v3 << std::endl;

      vb2.Set(v1, v2, v3);
      std::cout << "vb2 is set to:    " << std::endl
           << vb2 << std::endl
           << "vb  is unchanged: " << std::endl
           << vb << std::endl;

   // now try some transformation (rotate by 45 degrees about z axis
      v1 = aVector( 1.0, 1.0, 0.0);
      v2 = aVector(-1.0, 1.0, 0.0);
      v3 = aVector( 0.0, 0.0, 1.0);
      aVectorBasis vb2d(v1, v2, v3);

      v1 = aVector(0.0, 1.0, 0.0);  // the old y axis
      v2 = vb2d.ToLocal(v1);        // vb2d.ToNew(v1);

      std::cout << "on transformation:    " << v2 << std::endl;
      v2 = vb2d.ToWorld(v2);        // ToOld(v2);
      std::cout << "on transforming back: " << v2 << std::endl;

   // now take a random vector. a random basis and transform
   // the random vector to and fro and check
   // take an orthogonal system
      v1 = aVector( 1.0, 25., 0.52 );
      v2 = aVector( 893.15, 420.35, 35.525);
//      v3 = aVector(40.5, 1200.25, 0040.125);
      v3 = v1^v2;
      v2 = v3^v1;

      aVector v4(1.225, 0.255, 0.224);

      vb.Set(v1, v2, v3);
      std::cout << "vector before transformation is: " << std::endl
           << "    " << v4 << std::endl;

      v4 = vb.ToLocal(v4);       // ToNew(v4);
      std::cout << "vector after  transformation is: " << std::endl
           << "    " << v4 << std::endl;

   // transform back the same vector
      v4 = vb.ToWorld(v4);       // ToOld(v4);
      std::cout << "vector after  inverse transformation is: " << std::endl
           << "    " << v4 << std::endl;

   // now take e1, e2 and e3 and transform them into the new basis
   // this gives us three new vectors (as seen from the new basis).
   // let this form a newer basis. dump the new basis and the newer
   // basis and see what they are. note that newer basis is the
   // OLD basis

   // first dump the new basis
      std::cout << std::endl
           << "The new basis is" << std::endl
           << vb << std::endl;
   // now get the newer basis
      v1 = vb.ToLocal( aVector( 1.0, 0.0, 0.0 ) ); // ToNew( aVector( 1.0, 0.0, 0.0 ) );   // e1
      v2 = vb.ToLocal( aVector( 0.0, 1.0, 0.0 ) ); // ToNew( aVector( 0.0, 1.0, 0.0 ) );   // e2
      v3 = vb.ToLocal( aVector( 0.0, 0.0, 1.0 ) ); // ToNew( aVector( 0.0, 0.0, 1.0 ) );   // e3

      vb.Set(v1, v2, v3);

      std::cout << std::endl
           << "The newer basis is" << std::endl
           << vb << std::endl;
   }
   catch (char* s)
   {
      std::cout << s << std::endl;
   }

// stop the clock and display cpu time
   clock.Stop();
   clock.Display();

// write a closure message and finish the program
   std::cout << "Program <"
        << prg_name
        << "> completed successfully :-)"
        << std::endl;
   return 0;
}
コード例 #17
0
ファイル: Socket.cpp プロジェクト: remram44/network
SockAddress SockAddress::v4(const char *address)
{
    return v4(ntohl(inet_addr(address)));
}
コード例 #18
0
GMVector2D GMVector2D::transform(const GMMatrix& matrix) const
{
    GMVector4D v4(*this, 0.0, 1.0);
    v4 = v4.transform(matrix);
    return GMVector2D(v4.x, v4.y);
}
コード例 #19
0
ファイル: meshtool.cpp プロジェクト: SangitaSingh/elmerfem
  double CalcTetBadnessGrad (const Point3d & p1, const Point3d & p2,
			     const Point3d & p3, const Point3d & p4, double h,
			     int pi, Vec<3> & grad)
  {
    double vol, l, ll, lll;
    double err;

    const Point3d *pp1, *pp2, *pp3, *pp4;

    pp1 = &p1;
    pp2 = &p2;
    pp3 = &p3;
    pp4 = &p4;
  
    switch (pi)
      {
      case 2:
	{
	  swap (pp1, pp2);
	  swap (pp3, pp4);
	  break;
	}
      case 3:
	{
	  swap (pp1, pp3);
	  swap (pp2, pp4);
	  break;
	}
      case 4:
	{
	  swap (pp1, pp4);
	  swap (pp3, pp2);
	  break;
	}
      }
  

    Vec3d v1 (*pp1, *pp2);
    Vec3d v2 (*pp1, *pp3);
    Vec3d v3 (*pp1, *pp4);

    Vec3d v4 (*pp2, *pp3);
    Vec3d v5 (*pp2, *pp4);
    Vec3d v6 (*pp3, *pp4);

    vol = -Determinant (v1, v2, v3) / 6;  

    Vec3d gradvol;
    Cross (v5, v4, gradvol);
    gradvol *= (-1.0/6.0);


    double ll1 = v1.Length2();
    double ll2 = v2.Length2();
    double ll3 = v3.Length2();
    double ll4 = v4.Length2();
    double ll5 = v5.Length2();
    double ll6 = v6.Length2();

    ll = ll1 + ll2 + ll3 + ll4 + ll5 + ll6;
    l = sqrt (ll);
    lll = l * ll;

    if (vol <= 1e-24 * lll)
      { 
	grad = Vec3d (0, 0, 0);
	return 1e24;
      }



    Vec3d gradll1 (*pp2, *pp1);
    Vec3d gradll2 (*pp3, *pp1);
    Vec3d gradll3 (*pp4, *pp1);
    gradll1 *= 2;
    gradll2 *= 2;
    gradll3 *= 2;

    Vec3d gradll (gradll1);
    gradll += gradll2;
    gradll += gradll3;

    /*
    Vec3d gradll;
    gradll = v1+v2+v3;
    gradll *= -2;
    */

    err = 0.0080187537 * lll / vol; 


    gradll *= (0.0080187537 * 1.5 * l / vol);
    Vec3d graderr(gradll);
    gradvol *= ( -0.0080187537 * lll / (vol * vol) );
    graderr += gradvol;
  
    if (h > 0)
      {
	/*
	Vec3d gradll1 (*pp2, *pp1);
	Vec3d gradll2 (*pp3, *pp1);
	Vec3d gradll3 (*pp4, *pp1);
	gradll1 *= 2;
	gradll2 *= 2;
	gradll3 *= 2;
	*/
	err += ll / (h*h) + 
	  h*h * ( 1 / ll1 + 1 / ll2 + 1 / ll3 + 
		  1 / ll4 + 1 / ll5 + 1 / ll6 ) - 12;

	graderr += (1/(h*h) - h*h/(ll1*ll1)) * gradll1;
	graderr += (1/(h*h) - h*h/(ll2*ll2)) * gradll2;
	graderr += (1/(h*h) - h*h/(ll3*ll3)) * gradll3;
	cout << "?";
      }


    double errpow;
    if (teterrpow == 2)
      {
        errpow = err*err;   
        grad = (2 * err) * graderr;
      }
    else
      {
        errpow = pow (err, teterrpow);
        grad = (teterrpow * errpow / err) * graderr;
      }
    return errpow;
  }
コード例 #20
0
GMVector2D GMVector2D::transform(const GMQuat& quat) const
{
    GMVector4D v4(*this, 0.0, 1.0);
    v4 = v4.transform(quat);
    return GMVector2D(v4.x, v4.y);
}
コード例 #21
0
//majorAxis and minorAxis is the estimated particle size in px
void ProgSortByStatistics::processInprocessInputPrepareSPTH(MetaData &SF, bool trained)
{
    //#define DEBUG
    PCAMahalanobisAnalyzer tempPcaAnalyzer0;
    PCAMahalanobisAnalyzer tempPcaAnalyzer1;
    PCAMahalanobisAnalyzer tempPcaAnalyzer2;
    PCAMahalanobisAnalyzer tempPcaAnalyzer3;
    PCAMahalanobisAnalyzer tempPcaAnalyzer4;

    //Morphology
    tempPcaAnalyzer0.clear();
    //Signal to noise ratio
    tempPcaAnalyzer1.clear();
    tempPcaAnalyzer2.clear();
    tempPcaAnalyzer3.clear();
    //Histogram analysis, to detect black points and saturated parts
    tempPcaAnalyzer4.clear();

    double sign = 1;//;-1;
    int numNorm = 3;
    int numDescriptors0=numNorm;
    int numDescriptors2=4;
    int numDescriptors3=11;
    int numDescriptors4 = 10;

    MultidimArray<float> v0(numDescriptors0);
    MultidimArray<float> v2(numDescriptors2);
    MultidimArray<float> v3(numDescriptors3);
    MultidimArray<float> v4(numDescriptors4);

    if (verbose>0)
    {
        std::cout << " Sorting particle set by new xmipp method..." << std::endl;
    }

    int nr_imgs = SF.size();
    if (verbose>0)
        init_progress_bar(nr_imgs);

    int c = XMIPP_MAX(1, nr_imgs / 60);
    int imgno = 0, imgnoPCA=0;

    bool thereIsEnable=SF.containsLabel(MDL_ENABLED);
    bool first=true;

    // We assume that at least there is one particle
    size_t Xdim, Ydim, Zdim, Ndim;
    getImageSize(SF,Xdim,Ydim,Zdim,Ndim);

    //Initialization:
    MultidimArray<double> nI, modI, tempI, tempM, ROI;
    MultidimArray<bool> mask;
    nI.resizeNoCopy(Ydim,Xdim);
    modI.resizeNoCopy(Ydim,Xdim);
    tempI.resizeNoCopy(Ydim,Xdim);
    tempM.resizeNoCopy(Ydim,Xdim);
    mask.resizeNoCopy(Ydim,Xdim);
    mask.initConstant(true);

    MultidimArray<double> autoCorr(2*Ydim,2*Xdim);
    MultidimArray<double> smallAutoCorr;

    Histogram1D hist;
    Matrix2D<double> U,V,temp;
    Matrix1D<double> D;

    MultidimArray<int> radial_count;
    MultidimArray<double> radial_avg;
    Matrix1D<int> center(2);
    MultidimArray<int> distance;
    int dim;
    center.initZeros();

    v0.initZeros(numDescriptors0);
    v2.initZeros(numDescriptors2);
    v3.initZeros(numDescriptors3);
    v4.initZeros(numDescriptors4);

    ROI.resizeNoCopy(Ydim,Xdim);
    ROI.setXmippOrigin();
    FOR_ALL_ELEMENTS_IN_ARRAY2D(ROI)
    {
        double temp = std::sqrt(i*i+j*j);
        if ( temp < (Xdim/2))
            A2D_ELEM(ROI,i,j)= 1;
        else
            A2D_ELEM(ROI,i,j)= 0;
    }

    Image<double> img;
    FourierTransformer transformer(FFTW_BACKWARD);

    FOR_ALL_OBJECTS_IN_METADATA(SF)
    {
        if (thereIsEnable)
        {
            int enabled;
            SF.getValue(MDL_ENABLED,enabled,__iter.objId);
            if ( (enabled==-1)  )
            {
                imgno++;
                continue;
            }
        }

        img.readApplyGeo(SF,__iter.objId);
        if (targetXdim!=-1 && targetXdim!=XSIZE(img()))
        	selfScaleToSize(LINEAR,img(),targetXdim,targetXdim,1);

        MultidimArray<double> &mI=img();
        mI.setXmippOrigin();
        mI.statisticsAdjust(0,1);
        mask.setXmippOrigin();
        //The size of v1 depends on the image size and must be declared here
        int numDescriptors1 = XSIZE(mI)/2; //=100;
        MultidimArray<float> v1(numDescriptors1);
        v1.initZeros(numDescriptors1);

        double var = 1;
        normalize(transformer,mI,tempI,modI,0,var,mask);
        modI.setXmippOrigin();
        tempI.setXmippOrigin();
        nI = sign*tempI*(modI*modI);
        tempM = (modI*modI);

        A1D_ELEM(v0,0) = (tempM*ROI).sum();
        int index = 1;
        var+=2;
        while (index < numNorm)
        {
            normalize(transformer,mI,tempI,modI,0,var,mask);
            modI.setXmippOrigin();
            tempI.setXmippOrigin();
            nI += sign*tempI*(modI*modI);
            tempM += (modI*modI);
            A1D_ELEM(v0,index) = (tempM*ROI).sum();
            index++;
            var+=2;
        }

        nI /= tempM;
        tempPcaAnalyzer0.addVector(v0);
        nI=(nI*ROI);

        auto_correlation_matrix(mI,autoCorr);
        if (first)
        {
            radialAveragePrecomputeDistance(autoCorr, center, distance, dim);
            first=false;
        }
        fastRadialAverage(autoCorr, distance, dim, radial_avg, radial_count);

        for (int n = 0; n < numDescriptors1; ++n)
            A1D_ELEM(v1,n)=(float)DIRECT_A1D_ELEM(radial_avg,n);

        tempPcaAnalyzer1.addVector(v1);

#ifdef DEBUG

        //String name = "000005@Images/Extracted/run_002/extra/BPV_1386.stk";
        String name = "000010@Images/Extracted/run_001/extra/KLH_Dataset_I_Training_0028.stk";
        //String name = "001160@Images/Extracted/run_001/DefaultFamily5";

        std::cout << img.name() << std::endl;

        if (img.name()==name2)
        {
            FileName fpName    = "test_1.txt";
            mI.write(fpName);
            fpName    = "test_2.txt";
            nI.write(fpName);
            fpName    = "test_3.txt";
            tempM.write(fpName);
            fpName    = "test_4.txt";
            ROI.write(fpName);
            //exit(1);
        }
#endif
        nI.binarize(0);
        int im = labelImage2D(nI,nI,8);
        compute_hist(nI, hist, 0, im, im+1);
        size_t l;
        int k,i,j;
        hist.maxIndex(l,k,i,j);
        A1D_ELEM(hist,j)=0;
        hist.maxIndex(l,k,i,j);
        nI.binarizeRange(j-1,j+1);

        double x0=0,y0=0,majorAxis=0,minorAxis=0,ellipAng=0;
        size_t area=0;
        fitEllipse(nI,x0,y0,majorAxis,minorAxis,ellipAng,area);

        A1D_ELEM(v2,0)=majorAxis/((img().xdim) );
        A1D_ELEM(v2,1)=minorAxis/((img().xdim) );
        A1D_ELEM(v2,2)= (fabs((img().xdim)/2-x0)+fabs((img().ydim)/2-y0))/((img().xdim)/2);
        A1D_ELEM(v2,3)=area/( (double)((img().xdim)/2)*((img().ydim)/2) );

        for (int n=0 ; n < numDescriptors2 ; n++)
        {
            if ( std::isnan(std::abs(A1D_ELEM(v2,n))))
                A1D_ELEM(v2,n)=0;
        }

        tempPcaAnalyzer2.addVector(v2);

        //mI.setXmippOrigin();
        //auto_correlation_matrix(mI*ROI,autoCorr);
        //auto_correlation_matrix(nI,autoCorr);
        autoCorr.window(smallAutoCorr,-5,-5, 5, 5);
        smallAutoCorr.copy(temp);
        svdcmp(temp,U,D,V);

        for (int n = 0; n < numDescriptors3; ++n)
            A1D_ELEM(v3,n)=(float)VEC_ELEM(D,n); //A1D_ELEM(v3,n)=(float)VEC_ELEM(D,n)/VEC_ELEM(D,0);

        tempPcaAnalyzer3.addVector(v3);


        double minVal=0.;
        double maxVal=0.;
        mI.computeDoubleMinMax(minVal,maxVal);
        compute_hist(mI, hist, minVal, maxVal, 100);

        for (int n=0 ; n <= numDescriptors4-1 ; n++)
        {
            A1D_ELEM(v4,n)= (hist.percentil((n+1)*10));
        }
        tempPcaAnalyzer4.addVector(v4);

#ifdef DEBUG

        if (img.name()==name1)
        {
            FileName fpName    = "test.txt";
            mI.write(fpName);
            fpName    = "test3.txt";
            nI.write(fpName);
        }
#endif
        imgno++;
        imgnoPCA++;

        if (imgno % c == 0 && verbose>0)
            progress_bar(imgno);
    }

    tempPcaAnalyzer0.evaluateZScore(2,20,trained);
    tempPcaAnalyzer1.evaluateZScore(2,20,trained);
    tempPcaAnalyzer2.evaluateZScore(2,20,trained);
    tempPcaAnalyzer3.evaluateZScore(2,20,trained);
    tempPcaAnalyzer4.evaluateZScore(2,20,trained);

    pcaAnalyzer.push_back(tempPcaAnalyzer0);
    pcaAnalyzer.push_back(tempPcaAnalyzer1);
    pcaAnalyzer.push_back(tempPcaAnalyzer1);
    pcaAnalyzer.push_back(tempPcaAnalyzer3);
    pcaAnalyzer.push_back(tempPcaAnalyzer4);

}
コード例 #22
0
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
コード例 #23
0
ファイル: datedemo.cpp プロジェクト: Eric-Schnipke/snippets
void test()
{
      cout << " zDate Class Demo \n\n";

      // default constructor, Jan 1 0000
      zDate a;
      cout << a << endl;
      // Various versions of the constructors
      zDate x(zDate::oct,20,1962);
      cout << x << endl;
      // constructor with a julian
      zDate z( 2450000L );
      cout << z << endl;
      // make a date with system date (tests copy constructor)
      zDate s(zDate::Today());
      cout << s << endl;
      // init with the day of year
      zDate y(33, 1996);
      cout << y << endl;
      // init from current system time
      time_t secs_now = time(NULL);
      zDate n(localtime(&secs_now));
      cout << n << endl;

      // using date addition and subtraction
      zDate adder = x + 10;
      cout << adder << endl;
      adder = adder - 25;
      cout << adder << endl;

      //using subtraction of two date objects
      zDate a1(zDate::Today());
      zDate a2 = a1 + 14;
      cout << (a1 - a2) << endl;
      cout << (a2 += 10) << endl;

      a1++;
      cout << "Tommorrow= " << a1 << endl;

      a1 = zDate(zDate::jul, 14, 1991);
      cout << "a1 (7-14-91) < a2 (" << a2
             << ")? ==> " << ((a1 < a2) ? "TRUE" : "FALSE") << endl;
      cout << "a1 (7-14-91) > a2 ("<< a2
             << ")? ==> " << ((a1 > a2) ? "TRUE" : "FALSE") << endl;
      cout << "a1 (7-14-91) < 8-01-91 ? ==> "
             << ((a1 < zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl;
      cout << "a1 (7-14-91) > 8-01-91 ? ==> "
             << ((a1 > zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl;
      cout << "a1 (7-14-91) == 7-14-91 ? ==> "
             << ((a1==zDate(zDate::jul, 14, 1991)) ? "TRUE" : "FALSE") << endl;
      zDate a3 = a1;

      cout << "a1 (" << a1 << ") == a3 (" << a3
             << ") ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << endl;
      zDate a4 = a1;
      ++a4;
      cout << "a1 ("<< a1 <<") == a4 (" << a4
             << ") ? ==> " << ((a1==a4) ? "TRUE" : "FALSE") << endl;

      zDate a5(zDate::Today());
      cout << "Today is: " << a5 << endl;
      a4 = zDate::Today();
      cout << "Today (a4) is: " << a4 << endl;

      cout << "Today + 4 is: " << (a4 += 4) << endl;
      a4 = zDate::Today();
      cout << "Today - 4 is: " << (a4 -= 4) << endl;
      cout << "=========== Leap Year Test ===========\n";
      a1 = zDate(zDate::jan, 15, 1992);
      cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
      cout << "\t" << "day of year:  " << a1.DayOfYear() << endl;

      a1 = zDate(zDate::feb, 16, 1993);
      cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
      cout << "\t" << "day of year:  " << a1.DayOfYear() << endl;

      zDate v4(zDate::Today());
      cout << "---------- Add Stuff -----------\n";
      cout << "Start => " << v4 << endl;
      cout << "Add  4 Weeks  => " << v4.AddWeeks(4) << endl;
      cout << "Sub 52 Weeks  => " << v4.AddWeeks(-52)  << endl;
      cout << "Add  2 Years  => " << v4.AddYears(2)    << endl;

      cout << flush;

      cout << "---------- Misc Stuff -----------\n";
      cout << "The date aboves' day of the month is => " << v4.Day() << endl;
      cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
      cout << "This day happens to be " << v4.DayOfWeek() << " day of week" << endl;
      cout << "on the " << v4.WeekOfYear() << " week of the year," << endl;
      cout << "on the " << v4.WeekOfMonth() << " week of the month, " << endl;
      cout << "which is the "<< (int)v4.Month() << "nth month in the year.\n";
      cout << "The year alone is " << v4.Year() << endl;
      cout << "And this is the " << v4.DayOfYear() << " day of year" << endl;
      cout << "of a year with " << v4.DaysInYear() << " days in it" << endl;
      cout << "which makes exatcly " << v4.WeeksInYear() << " weeks" << endl;

      zDate birthday(zDate::jul, 16, 1973);
      cout << "The age test: i was born on " << birthday
             << " which makes me " << v4.Age(birthday) << " years old" << endl;

      zDate       D2(zDate::jul, 4, 1776);
      int         I1 = 4;

      cout << "Before: I1 = " << I1 << ",  D2 = " << D2 << endl;
      cout << "---------- Postfix '++' test -----------\n";
      cout << "Test : I1++ = " << I1++ << ",  D2++ = " << D2++ << endl;
      cout << "After: I1   = " << I1 << ",  D2   = " << D2 << endl;

      cout << "---------- Prefix '++' test -----------\n";
      cout << "Test : ++I1 = " << ++I1 << ",  ++D2 = " << ++D2 << endl;
      cout << "After:   I1 = " << I1 << ",    D2 = " << D2 << endl;

      cout << "---------- Postfix '--' test -----------\n";
      cout << "Test : I1-- = " << I1-- << ",  D2-- = " << D2-- << endl;
      cout << "After: I1   = " << I1 << ",  D2   = " << D2 << endl;

      cout << "---------- Prefix '--' test -----------\n";
      cout << "Test : --I1 = " << --I1 << ",  --D2 = " << --D2 << endl;
      cout << "After:   I1 = " << I1 << ",    D2 = " << D2 << endl;

      cout << "Last day of this year is dayno "
             << zDate(zDate::dec, 31, 1996).DayOfYear() << endl;
      cout << "Last day of prev year is dayno "
             << zDate(zDate::dec, 31, 1995).DayOfYear() << endl;

      cout << "Today the moon is " << zDate::Today().MoonPhase() << endl;

      zDate today = zDate::Today();

      cout << "DST for " << today.Year() << " starts on " << today.BeginDST()
             << " and ends on " << today.EndDST() << endl;
      cout << "Today, " << today << ", DST is "
             << (today.IsDST() ? "" : "not") << "in effect" << endl;

      zDate date1(zDate::aug, 31, 1996);
      cout << "Adding 6 months to " << date1 << " results in "
             << date1.AddMonths(6) << endl;

      zDate date2(zDate::mar, 31, 1996);
      cout << "Subtracting 1 month from " << date2 << " results in "
             << date2.AddMonths(-1) << endl;

      zDate date3(zDate::jul, 4, 1776);
      cout << "Adding 2400 months to " << date3 << " results in "
             << date3.AddMonths(2400) << endl;

      cout << "Today's day number is " << zDate::Today().DayNumber() << endl;

      zDate date4(zDate::feb, 29, 1996);
      cout << date4 << " subtract two years = " << date4.AddYears(-2) << endl;

      cout << "In 1996, DST began on " << zDate::BeginDST(1996) << endl;

      zDate date5(zDate::sep, 26, 1996);
      cout << "Moon phase on " << date5 << " was " << date5.MoonPhase() << endl;

      zDate date6(zDate::oct, 3, 1996);
      cout << date6 << " + 55 days is " << (date6 + 55) << endl;

      zDate date7(zDate::oct, 4, 1996);
      cout << date7 << " + 217 days is ";
      date7 += 217;
      cout << date7 << endl;
      date7 = zDate(zDate::oct, 4, 1996);
      cout << "Same date - (-217) days is ";
      date7 -= -217;
      cout << date7 << endl;

      cout << "For 1996, Easter is on " << zDate::Easter(1996) << endl;
}
コード例 #24
0
ファイル: BspNodes.cpp プロジェクト: bhlzlx/WildMagic
//----------------------------------------------------------------------------
void BspNodes::CreateScene ()
{
	// Create the scene graph.
	//
	// 1. The rectangles represent the BSP planes of the BSP tree.  They
	//    share a VertexColor3Effect.  You can see a plane from either side
	//    (backface culling disabled).  The planes do not interfere with view
	//    of the solid objects (wirestate enabled).
	//
	// 2. The sphere, tetrahedron, and cube share a TextureEffect.  These
	//    objects are convex.  The backfacing triangles are discarded
	//    (backface culling enabled).  The front facing triangles are drawn
	//    correctly by convexity, so depthbuffer reads are disabled and
	//    depthbuffer writes are enabled.  The BSP-based sorting of objects
	//    guarantees that front faces of convex objects in the foreground
	//    are drawn after the front faces of convex objects in the background,
	//    which allows us to set the depthbuffer state as we have.  That is,
	//    BSPNode sorts from back to front.
	//
	// 3. The torus has backface culling enabled and depth buffering enabled.
	//    This is necessary, because the torus is not convex.
	//
	// 4. Generally, if all objects are opaque, then you want to draw from
	//    front to back with depth buffering fully enabled.  You need to
	//    reverse-order the elements of the visible set before drawing.  If
	//    any of the objects are semitransparent, then drawing back to front
	//    is the correct order to handle transparency.  However, you do not
	//    get the benefit of early z-rejection for opaque objects.  A better
	//    BSP sorter needs to be built to produce a visible set with opaque
	//    objects listed first (front-to-back order) and semitransparent
	//    objects listed last (back-to-front order).
	//
	// scene
	//     ground
	//     bsp0
	//         bsp1
	//             bsp3
	//                 torus
	//                 rectangle3
	//                 sphere
	//             rectangle1
	//             tetrahedron
	//         rectangle0
	//         bsp2
	//             cube
	//             rectangle2
	//             octahedron

	mScene = new0 Node();

	// Create the ground.  It covers a square with vertices (1,1,0), (1,-1,0),
	// (-1,1,0), and (-1,-1,0).  Multiply the texture coordinates by a factor
	// to enhance the wrap-around.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

	StandardMesh sm(vformat);
	VertexBufferAccessor vba;

	TriMesh* ground = sm.Rectangle(2, 2, 16.0f, 16.0f);
	vba.ApplyTo(ground);
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float2& tcoord = vba.TCoord<Float2>(0, i);
		tcoord[0] *= 128.0f;
		tcoord[1] *= 128.0f;
	}

	std::string path = Environment::GetPathR("Horizontal.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	ground->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
	                          Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));
	mScene->AttachChild(ground);

	// Partition the region above the ground into 5 convex pieces.  Each plane
	// is perpendicular to the ground (not required generally).
	VertexColor3Effect* vceffect = new0 VertexColor3Effect();
	vceffect->GetCullState(0, 0)->Enabled = false;
	vceffect->GetWireState(0, 0)->Enabled = true;

	Vector2f v0(-1.0f, 1.0f);
	Vector2f v1(1.0f, -1.0f);
	Vector2f v2(-0.25f, 0.25f);
	Vector2f v3(-1.0f, -1.0f);
	Vector2f v4(0.0f, 0.0f);
	Vector2f v5(1.0f, 0.5f);
	Vector2f v6(-0.75f, -7.0f/12.0f);
	Vector2f v7(-0.75f, 0.75f);
	Vector2f v8(1.0f, 1.0f);

	BspNode* bsp0 = CreateNode(v0, v1, vceffect, Float3(1.0f, 0.0f, 0.0f));
	BspNode* bsp1 = CreateNode(v2, v3, vceffect, Float3(0.0f, 0.5f, 0.0f));
	BspNode* bsp2 = CreateNode(v4, v5, vceffect, Float3(0.0f, 0.0f, 1.0f));
	BspNode* bsp3 = CreateNode(v6, v7, vceffect, Float3(0.0f, 0.0f, 0.0f));

	bsp0->AttachPositiveChild(bsp1);
	bsp0->AttachNegativeChild(bsp2);
	bsp1->AttachPositiveChild(bsp3);

	// Attach an object in each convex region.
	float height = 0.1f;
	Vector2f center;
	TriMesh* mesh;

	// The texture effect for the convex objects.
	Texture2DEffect* cvxeffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);
	cvxeffect->GetDepthState(0, 0)->Enabled = false;
	cvxeffect->GetDepthState(0, 0)->Writable = true;

	// The texture effect for the torus.
	Texture2DEffect* toreffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);

	// The texture image shared by the objects.
	path = Environment::GetPathR("Flower.wmtf");
	texture = Texture2D::LoadWMTF(path);

	// Region 0: Create a torus mesh.
	mesh = sm.Torus(16, 16, 1.0f, 0.25f);
	mesh->SetEffectInstance(toreffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v2 + v6 + v7)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachPositiveChild(mesh);

	// Region 1: Create a sphere mesh.
	mesh = sm.Sphere(32, 16, 1.0f);
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v3 + v6 + v7)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachNegativeChild(mesh);

	// Region 2: Create a tetrahedron.
	mesh = sm.Tetrahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v2 + v3)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp1->AttachNegativeChild(mesh);

	// Region 3: Create a hexahedron (cube).
	mesh = sm.Hexahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v4 + v5)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachPositiveChild(mesh);

	// Region 4: Create an octahedron.
	mesh = sm.Octahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v4 + v5 + v8)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachNegativeChild(mesh);

	mScene->AttachChild(bsp0);
}
コード例 #25
0
ファイル: CIcosahedron.cpp プロジェクト: rroc/rtdof
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}
コード例 #26
0
int main()
{

  typedef make_variant_shrink_over<
    boost::mpl::vector<double,float,int,bool,char> 
    >::type r1type;
  BOOST_MPL_ASSERT((boost::mpl::equal<r1type ,boost::variant<double,bool,char> > ));
  //BOOST_MPL_ASSERT((boost::is_same<r1type ,boost::variant<double,bool,char> > ));
  r1type val1(1.1);
  std::cout << val1 << std::endl;
  std::cout << val1.which() << std::endl;

  val1='a';
  std::cout << val1 << std::endl;
  std::cout << val1.which() << std::endl;

  val1=false;
  std::cout << val1 << std::endl;
  std::cout << val1.which() << std::endl;




  typedef make_variant_shrink_over<boost::mpl::vector<double,float,int> >::type r2type;
  BOOST_MPL_ASSERT((boost::mpl::equal<r2type ,double > ));
  BOOST_MPL_ASSERT((boost::is_same<r2type ,double > ));
  r2type d1=1.1,d2=2.2;
  d2=d1+d2;
  std::cout << d2 << std::endl;
    
  
  typedef make_variant_shrink_over<boost::mpl::vector<bool,char,std::string> >::type r3type;
  BOOST_MPL_ASSERT((boost::mpl::equal<r3type ,boost::variant<bool,char,std::string> > )); 
  //BOOST_MPL_ASSERT((boost::is_same<r3type ,boost::variant<bool,charstd::string> > )); 
  r3type v3('a');
  v3="v3";
  //std::cout << v3<std::string > ;
  std::cout << v3 << std::endl;
  v3=false;
  std::cout << v3 << std::endl;


  typedef make_variant_shrink_over<boost::mpl::vector<int,double,double,char,char,std::string> >::type r4type;
  BOOST_MPL_ASSERT((boost::mpl::equal<r4type ,boost::variant<double,char,std::string> > )); 
  
  r4type v4("v4");
  std::cout << v4 << std::endl;
  std::cout << v4.which() << std::endl;

  //v4=false;
  //std::cout << v4 << std::endl;
  //std::cout << v4.which() << std::endl;

  v4='4';
  std::cout << v4 << std::endl;
  std::cout << v4.which() << std::endl;

  v4=4.44;
  std::cout << v4 << std::endl;
  std::cout << v4.which() << std::endl;

  // v4=4;
  // std::cout << v4 << std::endl;
  // std::cout << v4.which() << std::endl;

  //v4=v4+v4;

#if 1

  typedef make_variant_shrink_over<
    boost::mpl::vector<double,float,bool,char> 
    ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence<      
      boost::mpl::vector<bool,char,std::string>  //your prefer order
      >::type 
    >::type r5type;
   BOOST_MPL_ASSERT((boost::mpl::equal<r5type ,boost::variant<char,double,float> > ));
   //BOOST_MPL_ASSERT((boost::is_same<r5type ,boost::variant<char,double,float> > ));

#endif

#if 1
  typedef make_variant_shrink_over<
    boost::mpl::vector<char,int>//::type
    ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence<      
      boost::mpl::vector<bool,char,int> //::type  //your prefer order
      >::type
    >::type r6type;
   BOOST_MPL_ASSERT((boost::mpl::equal<r6type ,int > ));
   BOOST_MPL_ASSERT((boost::is_same<r6type ,int > ));
  r6type i1=1,i2=2;
  i2=i1+i2;
#endif
    
#if 1 
  typedef make_variant_shrink_over<
    boost::mpl::vector<char,std::string,double,int>
    ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence<      
      boost::mpl::vector<bool,char,int,std::string>  //your prefer order
      >::type
    >::type r7type;
   BOOST_MPL_ASSERT((boost::mpl::equal<r7type ,boost::variant<std::string,double> > )); 
  
  r7type v7("v777");
  std::cout << v7 << std::endl;
  std::cout << v7.which() << std::endl;

  //assert( v7.which() == 0 );  
  //v7=7.7777;
  //boost::get<double>(v7);
  //boost::get<int>(v7);
  //std::cout << v7<double> << std::endl;
#endif

#if 1
    typedef make_variant_shrink_over<
      boost::mpl::vector<float,bool,boost::rational<long> >       
      ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence<      
	boost::mpl::vector<
         bool , int , long , boost::rational<int>  ,  boost::rational<long>
	 >  //your prefer order
	>::type
     >::type r8type;
    BOOST_MPL_ASSERT((boost::mpl::equal<r8type ,boost::variant<boost::rational<long> ,float> > ));
#endif

#if 1
    typedef make_variant_shrink_over<
      boost::mpl::vector< int , boost::rational<int> >
      ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence<      
	boost::mpl::vector<
         bool , int , long , boost::rational<int>  ,  boost::rational<long>  
	 >  //your prefer order
	>::type
     >::type r9type;
    BOOST_MPL_ASSERT((boost::is_same<r9type ,boost::rational<int> > ));
#endif


    typedef boost::mpl::lambda<is_generalizable_to_custom<boost::mpl::_1 , boost::mpl::_2 > >::type is_generalizable_to_custom_mpl_lambda;

    typedef make_variant_shrink_over<
    boost::mpl::vector<double,float,bool,char> 
    ,is_generalizable_to_custom_mpl_lambda
    >::type r10type;

    BOOST_MPL_ASSERT((boost::mpl::equal<r10type ,boost::variant<double,char> >));

    r10type v10(10.1);
    std::cout << v10 << std::endl;
    std::cout << v10.which() << std::endl;
    boost::get<double>(v10);
    //v10=10;
    v10='a';
    std::cout << v10 << std::endl;
    std::cout << v10.which() << std::endl;
    boost::get<char>(v10);

    typedef make_variant_shrink_over<
    boost::mpl::vector<double,float> 
    ,is_generalizable_to_custom_mpl_lambda
    >::type r11type;
    BOOST_MPL_ASSERT((boost::is_same<r11type ,double > ));



}
コード例 #27
0
static int test_uvec_precision()
{
	int Error(0);

	{
		glm::u8vec2 v1;
		glm::lowp_u8vec2 v2(v1);
		glm::mediump_u8vec2 v3(v1);
		glm::highp_u8vec2 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u8vec2(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec2(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec2(v4))) ? 0 : 1;
	}

	{
		glm::u8vec3 v1;
		glm::lowp_u8vec3 v2(v1);
		glm::mediump_u8vec3 v3(v1);
		glm::highp_u8vec3 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u8vec3(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec3(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec3(v4))) ? 0 : 1;
	}
	
	{
		glm::u8vec4 v1;
		glm::lowp_u8vec4 v2(v1);
		glm::mediump_u8vec4 v3(v1);
		glm::highp_u8vec4 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u8vec4(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec4(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u8vec4(v4))) ? 0 : 1;
	}

	{
		glm::u16vec2 v1;
		glm::lowp_u16vec2 v2(v1);
		glm::mediump_u16vec2 v3(v1);
		glm::highp_u16vec2 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u16vec2(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec2(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec2(v4))) ? 0 : 1;
	}

	{
		glm::u16vec3 v1;
		glm::lowp_u16vec3 v2(v1);
		glm::mediump_u16vec3 v3(v1);
		glm::highp_u16vec3 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u16vec3(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec3(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec3(v4))) ? 0 : 1;
	}
	
	{
		glm::u16vec4 v1;
		glm::lowp_u16vec4 v2(v1);
		glm::mediump_u16vec4 v3(v1);
		glm::highp_u16vec4 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u16vec4(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec4(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u16vec4(v4))) ? 0 : 1;
	}

	{
		glm::u32vec2 v1;
		glm::lowp_u32vec2 v2(v1);
		glm::mediump_u32vec2 v3(v1);
		glm::highp_u32vec2 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u32vec2(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec2(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec2(v4))) ? 0 : 1;
	}

	{
		glm::u32vec3 v1;
		glm::lowp_u32vec3 v2(v1);
		glm::mediump_u32vec3 v3(v1);
		glm::highp_u32vec3 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u32vec3(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec3(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec3(v4))) ? 0 : 1;
	}
	
	{
		glm::u32vec4 v1;
		glm::lowp_u32vec4 v2(v1);
		glm::mediump_u32vec4 v3(v1);
		glm::highp_u32vec4 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u32vec4(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec4(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u32vec4(v4))) ? 0 : 1;
	}
	
	{
		glm::u64vec2 v1;
		glm::lowp_u64vec2 v2(v1);
		glm::mediump_u64vec2 v3(v1);
		glm::highp_u64vec2 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u64vec2(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec2(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec2(v4))) ? 0 : 1;
	}

	{
		glm::u64vec3 v1;
		glm::lowp_u64vec3 v2(v1);
		glm::mediump_u64vec3 v3(v1);
		glm::highp_u64vec3 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u64vec3(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec3(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec3(v4))) ? 0 : 1;
	}
	
	{
		glm::u64vec4 v1;
		glm::lowp_u64vec4 v2(v1);
		glm::mediump_u64vec4 v3(v1);
		glm::highp_u64vec4 v4(v1);

		Error += glm::all(glm::equal(v1, glm::u64vec4(v2))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec4(v3))) ? 0 : 1;
		Error += glm::all(glm::equal(v1, glm::u64vec4(v4))) ? 0 : 1;
	}
	
	return Error;
}
コード例 #28
0
ファイル: vector_test.cpp プロジェクト: Quanteek/OpenNN-CMake
void VectorTest::test_constructor(void)
{
   message += "test_constructor\n";

   std::string file_name = "../data/vector.dat";

   // Default 

   Vector<bool> v1;

   assert_true(v1.size() == 0, LOG);   

   // Size

   Vector<bool> v2(1);

   assert_true(v2.size() == 1, LOG);

   // Size initialization

   Vector<bool> v3(1, false);

   assert_true(v3.size() == 1, LOG);
   assert_true(v3[0] == false, LOG);

   // File

   Vector<int> v4(3, 0);
   v4.save(file_name);

   Vector<int> w4(file_name);
   
   assert_true(w4.size() == 3, LOG);
   assert_true(w4 == 0, LOG);

   // Sequential

   Vector<int> v6(10, 5, 50);

   assert_true(v6.size() == 9, LOG);
   assert_true(v6[0] == 10, LOG);
   assert_true(v6[8] == 50, LOG);

   Vector<double> v7(3.0, 0.2, 3.8);

   assert_true(v7.size() == 5, LOG);
   assert_true(v7[0] == 3.0, LOG);
   assert_true(v7[4] == 3.8, LOG);

   Vector<int> v8(9, -1, 1);

   assert_true(v8.size() == 9, LOG);
   assert_true(v8[0] == 9, LOG);
   assert_true(v8[8] == 1, LOG);

   // Copy

   Vector<std::string> v5(1, "hello");

   Vector<std::string> w5(v5);

   assert_true(w5.size() == 1, LOG);
   assert_true(w5[0] == "hello", LOG);

}
コード例 #29
0
ファイル: sparse_vector.cpp プロジェクト: 13221325403/openbr
template<typename Scalar,typename StorageIndex> void sparse_vector(int rows, int cols)
{
  double densityMat = (std::max)(8./(rows*cols), 0.01);
  double densityVec = (std::max)(8./(rows), 0.1);
  typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
  typedef Matrix<Scalar,Dynamic,1> DenseVector;
  typedef SparseVector<Scalar,0,StorageIndex> SparseVectorType;
  typedef SparseMatrix<Scalar,0,StorageIndex> SparseMatrixType;
  Scalar eps = 1e-6;

  SparseMatrixType m1(rows,rows);
  SparseVectorType v1(rows), v2(rows), v3(rows);
  DenseMatrix refM1 = DenseMatrix::Zero(rows, rows);
  DenseVector refV1 = DenseVector::Random(rows),
              refV2 = DenseVector::Random(rows),
              refV3 = DenseVector::Random(rows);

  std::vector<int> zerocoords, nonzerocoords;
  initSparse<Scalar>(densityVec, refV1, v1, &zerocoords, &nonzerocoords);
  initSparse<Scalar>(densityMat, refM1, m1);

  initSparse<Scalar>(densityVec, refV2, v2);
  initSparse<Scalar>(densityVec, refV3, v3);

  Scalar s1 = internal::random<Scalar>();

  // test coeff and coeffRef
  for (unsigned int i=0; i<zerocoords.size(); ++i)
  {
    VERIFY_IS_MUCH_SMALLER_THAN( v1.coeff(zerocoords[i]), eps );
    //VERIFY_RAISES_ASSERT( v1.coeffRef(zerocoords[i]) = 5 );
  }
  {
    VERIFY(int(nonzerocoords.size()) == v1.nonZeros());
    int j=0;
    for (typename SparseVectorType::InnerIterator it(v1); it; ++it,++j)
    {
      VERIFY(nonzerocoords[j]==it.index());
      VERIFY(it.value()==v1.coeff(it.index()));
      VERIFY(it.value()==refV1.coeff(it.index()));
    }
  }
  VERIFY_IS_APPROX(v1, refV1);
  
  // test coeffRef with reallocation
  {
    SparseVectorType v4(rows);
    DenseVector v5 = DenseVector::Zero(rows);
    for(int k=0; k<rows; ++k)
    {
      int i = internal::random<int>(0,rows-1);
      Scalar v = internal::random<Scalar>();
      v4.coeffRef(i) += v;
      v5.coeffRef(i) += v;
    }
    VERIFY_IS_APPROX(v4,v5);
  }

  v1.coeffRef(nonzerocoords[0]) = Scalar(5);
  refV1.coeffRef(nonzerocoords[0]) = Scalar(5);
  VERIFY_IS_APPROX(v1, refV1);

  VERIFY_IS_APPROX(v1+v2, refV1+refV2);
  VERIFY_IS_APPROX(v1+v2+v3, refV1+refV2+refV3);

  VERIFY_IS_APPROX(v1*s1-v2, refV1*s1-refV2);

  VERIFY_IS_APPROX(v1*=s1, refV1*=s1);
  VERIFY_IS_APPROX(v1/=s1, refV1/=s1);

  VERIFY_IS_APPROX(v1+=v2, refV1+=refV2);
  VERIFY_IS_APPROX(v1-=v2, refV1-=refV2);

  VERIFY_IS_APPROX(v1.dot(v2), refV1.dot(refV2));
  VERIFY_IS_APPROX(v1.dot(refV2), refV1.dot(refV2));

  VERIFY_IS_APPROX(m1*v2, refM1*refV2);
  VERIFY_IS_APPROX(v1.dot(m1*v2), refV1.dot(refM1*refV2));
  {
    int i = internal::random<int>(0,rows-1);
    VERIFY_IS_APPROX(v1.dot(m1.col(i)), refV1.dot(refM1.col(i)));
  }


  VERIFY_IS_APPROX(v1.squaredNorm(), refV1.squaredNorm());
  
  VERIFY_IS_APPROX(v1.blueNorm(), refV1.blueNorm());

  // test aliasing
  VERIFY_IS_APPROX((v1 = -v1), (refV1 = -refV1));
  VERIFY_IS_APPROX((v1 = v1.transpose()), (refV1 = refV1.transpose().eval()));
  VERIFY_IS_APPROX((v1 += -v1), (refV1 += -refV1));
  
  // sparse matrix to sparse vector
  SparseMatrixType mv1;
  VERIFY_IS_APPROX((mv1=v1),v1);
  VERIFY_IS_APPROX(mv1,(v1=mv1));
  VERIFY_IS_APPROX(mv1,(v1=mv1.transpose()));
  
  // check copy to dense vector with transpose
  refV3.resize(0);
  VERIFY_IS_APPROX(refV3 = v1.transpose(),v1.toDense()); 
  VERIFY_IS_APPROX(DenseVector(v1),v1.toDense()); 

  // test conservative resize
  {
    std::vector<StorageIndex> inc;
    if(rows > 3)
      inc.push_back(-3);
    inc.push_back(0);
    inc.push_back(3);
    inc.push_back(1);
    inc.push_back(10);

    for(std::size_t i = 0; i< inc.size(); i++) {
      StorageIndex incRows = inc[i];
      SparseVectorType vec1(rows);
      DenseVector refVec1 = DenseVector::Zero(rows);
      initSparse<Scalar>(densityVec, refVec1, vec1);

      vec1.conservativeResize(rows+incRows);
      refVec1.conservativeResize(rows+incRows);
      if (incRows > 0) refVec1.tail(incRows).setZero();

      VERIFY_IS_APPROX(vec1, refVec1);

      // Insert new values
      if (incRows > 0)
        vec1.insert(vec1.rows()-1) = refVec1(refVec1.rows()-1) = 1;

      VERIFY_IS_APPROX(vec1, refVec1);
    }
  }

}
コード例 #30
0
int CLuaFunctionDefs::CreateWater ( lua_State* luaVM )
{
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        CResource* pResource = pLuaMain->GetResource ();
        if ( pResource )
        {
            int iArgument1  = lua_type ( luaVM, 1 );
            int iArgument2  = lua_type ( luaVM, 2 );
            int iArgument3  = lua_type ( luaVM, 3 );
            int iArgument4  = lua_type ( luaVM, 4 );
            int iArgument5  = lua_type ( luaVM, 5 );
            int iArgument6  = lua_type ( luaVM, 6 );
            int iArgument7  = lua_type ( luaVM, 7 );
            int iArgument8  = lua_type ( luaVM, 8 );
            int iArgument9  = lua_type ( luaVM, 9 );
            int iArgument10 = lua_type ( luaVM, 10 );
            int iArgument11 = lua_type ( luaVM, 11 );
            int iArgument12 = lua_type ( luaVM, 12 );
            if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
                ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
                ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
                ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) &&
                ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) &&
                ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) &&
                ( iArgument7 == LUA_TNUMBER || iArgument7 == LUA_TSTRING ) &&
                ( iArgument8 == LUA_TNUMBER || iArgument8 == LUA_TSTRING ) &&
                ( iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING ) )
            {
                CVector v1 ( (float)lua_tonumber(luaVM, 1), (float)lua_tonumber(luaVM, 2), (float)lua_tonumber(luaVM, 3) );
                CVector v2 ( (float)lua_tonumber(luaVM, 4), (float)lua_tonumber(luaVM, 5), (float)lua_tonumber(luaVM, 6) );
                CVector v3 ( (float)lua_tonumber(luaVM, 7), (float)lua_tonumber(luaVM, 8), (float)lua_tonumber(luaVM, 9) );
                if ( ( iArgument10 == LUA_TNUMBER || iArgument10 == LUA_TSTRING ) &&
                    ( iArgument11 == LUA_TNUMBER || iArgument11 == LUA_TSTRING ) &&
                    ( iArgument12 == LUA_TNUMBER || iArgument12 == LUA_TSTRING ) )
                {
                    CVector v4 ( (float)lua_tonumber(luaVM, 10), (float)lua_tonumber(luaVM, 11), (float)lua_tonumber(luaVM, 12) );
                    bool bShallow = false;
                    if ( lua_type ( luaVM, 13 ) == LUA_TBOOLEAN && lua_toboolean ( luaVM, 13 ) )
                        bShallow = true;
                    lua_pushelement ( luaVM, CStaticFunctionDefinitions::CreateWater (
                        *pResource, &v1, &v2, &v3, &v4, bShallow ) );
                    return 1;
                }
                else
                {
                    bool bShallow = false;
                    if ( lua_type ( luaVM, 10 ) == LUA_TBOOLEAN && lua_toboolean ( luaVM, 10 ) )
                        bShallow = true;
                    lua_pushelement ( luaVM, CStaticFunctionDefinitions::CreateWater (
                        *pResource, &v1, &v2, &v3, NULL, bShallow ) );
                    return 1;
                }
            }
            else
                m_pScriptDebugging->LogBadType ( luaVM, "createWater" );
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}