pair<bool, Vec3> Planar::intersect(Ray &ray){ // declare the impact point Vec3 impact_point = ray.getOrigin(); // normalize the vector (n is already normalized) Vec3 l0 = ray.getOrigin(); Vec3 l = ray.getDirection(); // calcul the denominator float denom = l * n; // if the ray and the normal vector of the planar isn't parallel if (denom > 1e-6) { // calcul t for determinate if the ray intersect the planar float t = ((position - l0) * n) / denom; // calcul the impact point impact_point = l0 + l * t; // verif if the impact point is in the square if (impact_point.getX() < maxCoordinates().getX() && impact_point.getX() > minCoordinates().getX() && impact_point.getY() < maxCoordinates().getY() && impact_point.getY() > minCoordinates().getY() /*&& impact_point.getZ() <= maxCoordinates().getZ() && impact_point.getZ() >= minCoordinates().getZ()*/){ return pair<bool, Vec3>(t >= 0, impact_point); } else{ return pair<bool, Vec3>(false, impact_point); } } return pair<bool, Vec3>(false, impact_point); }
///===================================================== /// ///===================================================== const Vec2s AnimatedTexture::CalcTextureCoordinatesAtSpriteNumber(unsigned int spriteNumber) const{ Vec2 minCoordinates((float)(spriteNumber % m_cellsPerRow) * m_inverseCellsPerRow, floor((float)spriteNumber * m_inverseCellsPerRow) * m_inverseCellsPerColumn); Vec2s textureCoordinates; textureCoordinates.push_back(minCoordinates + Vec2(0.0001f, m_inverseCellsPerColumn - 0.0002f)); //small additions are to fix black outlines around textures; textureCoordinates.push_back(minCoordinates + Vec2(m_inverseCellsPerRow - 0.0002f, m_inverseCellsPerColumn - 0.0002f)); textureCoordinates.push_back(minCoordinates + Vec2(m_inverseCellsPerRow - 0.0002f, 0.0001f)); textureCoordinates.push_back(minCoordinates + Vec2(0.0001f, 0.0001f)); return textureCoordinates; }
///===================================================== /// ///===================================================== const Vec2s AnimatedTexture::CalcTextureCoordinatesAtPercentComplete(double percentComplete) const{ unsigned int cellNumber = (unsigned int)((double)m_numberOfSprites * percentComplete); Vec2 minCoordinates((float)(cellNumber % m_cellsPerRow) * m_inverseCellsPerRow, floor((float)cellNumber * m_inverseCellsPerRow) * m_inverseCellsPerColumn); Vec2s textureCoordinates; textureCoordinates.push_back(minCoordinates + Vec2(0.0001f, m_inverseCellsPerColumn - 0.0002f)); //small additions are to fix black outlines around textures; textureCoordinates.push_back(minCoordinates + Vec2(m_inverseCellsPerRow - 0.0002f, m_inverseCellsPerColumn - 0.0002f)); textureCoordinates.push_back(minCoordinates + Vec2(m_inverseCellsPerRow - 0.0002f, 0.0001f)); textureCoordinates.push_back(minCoordinates + Vec2(0.0001f, 0.0001f)); return textureCoordinates; }
///===================================================== /// ///===================================================== const Vec2 AnimatedTexture::CalcMinimumTextureCoordinatesAtSpriteNumber(unsigned int spriteNumber) const{ Vec2 minCoordinates((float)(spriteNumber % m_cellsPerRow) * m_inverseCellsPerRow, floor((float)spriteNumber * m_inverseCellsPerRow) * m_inverseCellsPerColumn); return minCoordinates; }
///===================================================== /// ///===================================================== const Vec2 AnimatedTexture::CalcMinimumTextureCoordinatesAtPercentComplete(double percentComplete) const{ unsigned int cellNumber = (unsigned int)((double)m_numberOfSprites * percentComplete); Vec2 minCoordinates((float)(cellNumber % m_cellsPerRow) * m_inverseCellsPerRow, floor((float)cellNumber * m_inverseCellsPerRow) * m_inverseCellsPerColumn); return minCoordinates; }