示例#1
0
TEST(ChunkTests, InterpolatesNoiseInputsCorrectly) {
  const unsigned VOXELS_PER_CHUNK = Units::chunkToVoxel(1);
  DummyChunk ch1(0, 0, 0);
  glm::vec3 v000(ch1.getNoiseModuleInput(glm::vec3(0, 0, 0)));
  glm::vec3 v100(ch1.getNoiseModuleInput(glm::vec3(1, 0, 0)));
  glm::vec3 v200(ch1.getNoiseModuleInput(glm::vec3(2, 0, 0)));
  
  EXPECT_EQ(glm::vec3(0.0, 0.0, 0.0), v000);
  EXPECT_EQ(glm::vec3(1.f / (float)VOXELS_PER_CHUNK, 0.0, 0.0), v100);
  EXPECT_EQ(glm::vec3((1.f / (float)VOXELS_PER_CHUNK) * 2, 0.0, 0.0), v200);
}
示例#2
0
osg::Node* createBase(const osg::Vec3& center,float radius)
{



    int numTilesX = 10;
    int numTilesY = 10;

    float width = 2*radius;
    float height = 2*radius;

    osg::Vec3 v000(center - osg::Vec3(width*0.5f,height*0.5f,0.0f));
    osg::Vec3 dx(osg::Vec3(width/((float)numTilesX),0.0,0.0f));
    osg::Vec3 dy(osg::Vec3(0.0f,height/((float)numTilesY),0.0f));

    // fill in vertices for grid, note numTilesX+1 * numTilesY+1...
    osg::Vec3Array* coords = new osg::Vec3Array;
    int iy;
    for(iy=0;iy<=numTilesY;++iy)
    {
        for(int ix=0;ix<=numTilesX;++ix)
        {
            coords->push_back(v000+dx*(float)ix+dy*(float)iy);
        }
    }

    //Just two colours - black and white.
    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // white
    colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black

    osg::ref_ptr<osg::DrawElementsUShort> whitePrimitives = new osg::DrawElementsUShort(GL_QUADS);
    osg::ref_ptr<osg::DrawElementsUShort> blackPrimitives = new osg::DrawElementsUShort(GL_QUADS);

    int numIndicesPerRow=numTilesX+1;
    for(iy=0;iy<numTilesY;++iy)
    {
        for(int ix=0;ix<numTilesX;++ix)
        {
            osg::DrawElementsUShort* primitives = ((iy+ix)%2==0) ? whitePrimitives.get() : blackPrimitives.get();
            primitives->push_back(ix    +(iy+1)*numIndicesPerRow);
            primitives->push_back(ix    +iy*numIndicesPerRow);
            primitives->push_back((ix+1)+iy*numIndicesPerRow);
            primitives->push_back((ix+1)+(iy+1)*numIndicesPerRow);
        }
    }

    // set up a single normal
    osg::Vec3Array* normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));

    osg::Geometry* geom = new osg::Geometry;
    geom->setVertexArray(coords);

    geom->setColorArray(colors, osg::Array::BIND_PER_PRIMITIVE_SET);

    geom->setNormalArray(normals, osg::Array::BIND_OVERALL);

    geom->addPrimitiveSet(whitePrimitives.get());
    geom->addPrimitiveSet(blackPrimitives.get());

    osg::Geode* geode = new osg::Geode;
    geode->addDrawable(geom);

    return geode;
}
void cObjectFactoryPlane::resizePlane(
		float p_size_x,
		float p_size_z
	)
{
	size_x = p_size_x;
	size_z = p_size_z;

	mass = 1.0f;
	inv_mass = 1.0f;

	int segments_x = 10;
	int segments_z = 10;

	// resize vertex list, 3 triangles
	resizeTriangleList(2*segments_x*segments_z);

	// compute size of one small plate
	float psize_x = size_x / (float)segments_x;
	float psize_z = size_z / (float)segments_z;

	float phsize_x = psize_x*0.5f;
	float phsize_z = psize_z*0.5f;

	CVector<3,float> v000(-phsize_x, 0, -phsize_z);
	CVector<3,float> v100(phsize_x, 0, -phsize_z);
	CVector<3,float> v001(-phsize_x, 0, phsize_z);
	CVector<3,float> v101(phsize_x, 0, phsize_z);

	int triangle_iter = 0;

	for (int seg_z = 0; seg_z < segments_z; seg_z++)
	{
		float z = -phsize_z*(float)(segments_z-1) + psize_z*(float)seg_z;

		for (int seg_x = 0; seg_x < segments_x; seg_x++)
		{
			float x = -phsize_x*(float)(segments_x-1) + psize_x*(float)seg_x;

			setTriangleDataVT(triangle_iter,
					CVector<3,float>(-phsize_x+x, 0, phsize_z+z),
					CVector<3,float>(phsize_x+x, 0, phsize_z+z),
					CVector<3,float>(phsize_x+x, 0, -phsize_z+z),
					CVector<2,float>(((float)(seg_x)/(float)segments_x), ((float)(seg_z+1)/(float)segments_z)),
					CVector<2,float>(((float)(seg_x+1)/(float)segments_x), ((float)(seg_z+1)/(float)segments_z)),
					CVector<2,float>(((float)(seg_x+1)/(float)segments_x), ((float)(seg_z)/(float)segments_z))
					);	triangle_iter++;

			setTriangleDataVT(triangle_iter,
					CVector<3,float>(phsize_x+x, 0, -phsize_z+z),
					CVector<3,float>(-phsize_x+x, 0, -phsize_z+z),
					CVector<3,float>(-phsize_x+x, 0, phsize_z+z),
					CVector<2,float>(((float)(seg_x+1)/(float)segments_x), ((float)(seg_z)/(float)segments_z)),
					CVector<2,float>(((float)(seg_x)/(float)segments_x), ((float)(seg_z)/(float)segments_z)),
					CVector<2,float>(((float)(seg_x)/(float)segments_x), ((float)(seg_z+1)/(float)segments_z))
					);	triangle_iter++;
		}
	}

	setTexcoordsValid(true);

	computeTriangleFlatNormals();
	setNormalsValid(true);

	setupBoundingSphereRadius();
}
示例#4
0
osg::Node* createBase(const osg::Vec3& center,float radius)
{

    int numTilesX = 10;
    int numTilesY = 10;
    
    float width = 2*radius;
    float height = 2*radius;
    
    osg::Vec3 v000(center - osg::Vec3(width*0.5f,height*0.5f,0.0f));
    osg::Vec3 dx(osg::Vec3(width/((float)numTilesX),0.0,0.0f));
    osg::Vec3 dy(osg::Vec3(0.0f,height/((float)numTilesY),0.0f));
    
    // fill in vertices for grid, note numTilesX+1 * numTilesY+1...
    osg::Vec3Array* coords = new osg::Vec3Array;
    int iy;
    for(iy=0;iy<=numTilesY;++iy)
    {
        for(int ix=0;ix<=numTilesX;++ix)
        {
            coords->push_back(v000+dx*(float)ix+dy*(float)iy);
        }
    }
    
    //Just two colours - black and white.
    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // white
    colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black
    int numColors=colors->size();
    
    
    int numIndicesPerRow=numTilesX+1;
    osg::UByteArray* coordIndices = new osg::UByteArray; // assumes we are using less than 256 points...
    osg::UByteArray* colorIndices = new osg::UByteArray;
    for(iy=0;iy<numTilesY;++iy)
    {
        for(int ix=0;ix<numTilesX;++ix)
        {
            // four vertices per quad.
            coordIndices->push_back(ix    +(iy+1)*numIndicesPerRow);
            coordIndices->push_back(ix    +iy*numIndicesPerRow);
            coordIndices->push_back((ix+1)+iy*numIndicesPerRow);
            coordIndices->push_back((ix+1)+(iy+1)*numIndicesPerRow);
            
            // one color per quad
            colorIndices->push_back((ix+iy)%numColors);
        }
    }
    

    // set up a single normal
    osg::Vec3Array* normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
    

    osg::Geometry* geom = new osg::Geometry;
    geom->setVertexArray(coords);
    geom->setVertexIndices(coordIndices);
    
    geom->setColorArray(colors);
    geom->setColorIndices(colorIndices);
    geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
    
    geom->setNormalArray(normals);
    geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
    
    geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,coordIndices->size()));
    
    osg::Geode* geode = new osg::Geode;
    geode->addDrawable(geom);
    
    return geode;
}