Пример #1
0
void CSphere:: getColor(GzRender* render, GzRay ray, GzCoord hitPoint, GzColor* intensity)
{
	GzCoord normal; //need to calculate normal at hitpoint
	GzColor resultIntensity;
	
	getSurfaceNormal(hitPoint, &normal);

	//PhongIllumination(render,ray,normal,&resultIntensity);

	resultIntensity[RED] *= 256;
	resultIntensity[GREEN] *= 256;
	resultIntensity[BLUE] *= 256;

	memcpy(intensity,resultIntensity,sizeof(GzColor));

}
Пример #2
0
void CTriangle::getColor(GzRender* render, GzRay ray, GzCoord hitPoint, GzColor* intensity)
{
	GzColor resultIntensity;
	GzCoord norm;
	GzCoord temp;
	memcpy(&temp, &hitPoint, sizeof(GzCoord));

	getSurfaceNormal(hitPoint,&temp);

	//PhongIllumination(render,ray,temp,&resultIntensity);

	resultIntensity[RED] *= 256;
	resultIntensity[GREEN] *= 256;
	resultIntensity[BLUE] *= 256;

	memcpy(intensity,resultIntensity,sizeof(GzColor));
}
int PressureIndependMultiYield::isLoadReversal(void)
{
  if(activeSurfaceNum == 0) return 0;

  static Vector surfaceNormal(6);
  getSurfaceNormal(currentStress, surfaceNormal);

  //(((trialStress.deviator() - currentStress.deviator()) && surfaceNormal) < 0)
  // return 1;
  static Vector a(6);
  a = trialStress.deviator();
  a-= currentStress.deviator();
  if((a && surfaceNormal) < 0)
    return 1;

  return 0;
}
Пример #4
0
bool FaceRule::testElementNodeOrder(const Element* e)
{
    return getSurfaceNormal(e)[2] < 0;
}
Пример #5
0
const Zeni::Vector3f Utils::getSurfaceNormal(const Zeni::Point3f vertices[3]) {
	return getSurfaceNormal(vertices[0], vertices[1], vertices[2]);
}
Пример #6
0
const Zeni::Point3f Utils::getFaceLineSegmentIntersection(const Zeni::Collision::Line_Segment &lineSegment, const Zeni::Point3f &p1, const Zeni::Point3f &p2, const Zeni::Point3f &p3) {
	// Interpolate along line segment to the interpolation value returned by the collision
	Zeni::Collision::Plane facePlane(p1, getSurfaceNormal(p1, p2, p3));
	return lineSegment.get_end_point_a().interpolate_to(lineSegment.nearest_point(facePlane).second, lineSegment.get_end_point_b());
}
void Heightmap::create(TextureAsset * file, std::string heightmapFilename, float _x, float _y)
{
    if(texture && mesh)
    {
        return;
    }

    scale = _x;

    const auto imageType = FreeImage_GetFIFFromFilename(heightmapFilename.c_str());
    const auto bitmap = FreeImage_Load(imageType, heightmapFilename.c_str());

    GLint textureHeight = FreeImage_GetHeight(bitmap);
    GLint textureWidth = FreeImage_GetWidth(bitmap);
    auto z = -textureHeight / 2;
    auto x = -textureWidth / 2;

    texture = new GPU_Sampler(SINGLE_SAMPLER);
    mesh = new GPU_Transfer();
    size = vec2(textureWidth, textureHeight);

    vector<Vertex> list;
    vector<Vertex> uvs;

    faces.reserve(textureWidth * textureHeight * 2);
    list.reserve(textureWidth * textureHeight * 2 * 3);
    uvs.reserve(textureWidth * textureHeight * 2 * 2);
    vn.reserve(textureWidth * textureHeight * 2 * 3);

    auto uvx = 0;
    auto uvy = 0;

    for (auto i = 0; i < textureWidth+1; i++)
    {
        terrain_heights.push_back(vector<float>());
        faces.push_back(vector<HeightmapSurface *>());

        for (auto a = 0; a < textureHeight + 1; a++, z++)
        {
            float heights[] = {
                getY(bitmap, i, a, _y), 			getY(bitmap, i, a + 1, _y),
                getY(bitmap, i + 1, a + 1, _y), 	getY(bitmap, i, a, _y),
                getY(bitmap, i + 1, a + 1, _y),		getY(bitmap, i+1, a, _y)
            };

            auto heighest_height = 0.0;

            for (auto b = 0; b < 6; b++)
            {
                if (heights[b] * heights[b] > heighest_height*heighest_height) 
                {
                    heighest_height = heights[b];	
                }
            }

            terrain_heights[i].push_back(heighest_height); 

            list.push_back(Vertex(x,		heights[0], z - 1));
            list.push_back(Vertex(x,		heights[1], z));
            list.push_back(Vertex(x + 1,	heights[2], z));
            list.push_back(Vertex(x,		heights[3], z - 1));
            list.push_back(Vertex(x + 1,	heights[4], z));
            list.push_back(Vertex(x + 1,	heights[5], z - 1));

            uvs.push_back(Vertex(uvx, uvy, 0.0));
            uvs.push_back(Vertex(uvx, uvy+1, 0.0));
            uvs.push_back(Vertex(uvx+1, uvy+1, 0.0));
            uvs.push_back(Vertex(uvx, uvy, 0.0));
            uvs.push_back(Vertex(uvx+1, uvy+1, 0.0));
            uvs.push_back(Vertex(uvx+1, uvy, 0.0));
        
            auto surface = new HeightmapSurface();
            auto v1 = getSurfaceNormal(Vertex(x, heights[0], z - 1), Vertex(x, heights[1], z), Vertex(x + 1, heights[2], z));
            auto v2 = getSurfaceNormal(Vertex(x, heights[3], z - 1), Vertex(x + 1, heights[4], z), Vertex(x + 1, heights[5], z - 1));

            surface->normal = v1 + v2;
            surface->vertices = { 
                Vertex(x,		heights[0],		z - 1),
                Vertex(x,		heights[1],		z),
                Vertex(x + 1,	heights[2],		z),
                Vertex(x,		heights[3],		z - 1),
                Vertex(x + 1,	heights[4],		z),
                Vertex(x + 1,	heights[5],		z - 1)
            };

            faces[i].push_back(surface);
            ++uvy;
        }

        uvy = 0;
        uvx++;
        z = -textureHeight / 2;
        x++;
    }

    for (auto& v : list) 
    {
        v.x *= _x;
        v.z *= _x;
    }

    averageNormals(list);

    mesh->setTextureCords(uvs);
    mesh->setVertices(list);
    mesh->setNormals(vn);
    mesh->send();

    texture->setTransferQuality(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
    texture->setBitmapData(file->getPixels(),
        file->getWidth(),
        file->getHeight(),
        file->getBPP(),
        file->getMask()
    );

    texture->send();
    vertexCount = list.size();
    FreeImage_Unload(bitmap);
}