Commit 738951ff authored by hybrid's avatar hybrid

Fixed some type issues with sqrt. Fixed rect.isValid to work with all types...

Fixed some type issues with sqrt. Fixed rect.isValid to work with all types and avoid useless tests. Cleaned up some variable uses and scopes.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1004 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 31afde95
......@@ -22,7 +22,6 @@ namespace irr
namespace io
{
class IFileSystem;
class IReadFile;
class IAttributes;
class IWriteFile;
......@@ -31,7 +30,6 @@ namespace io
namespace gui
{
class IGUIFont;
class IGUIFontBitmap;
class IGUIEnvironment;
} // end namespace gui
......
......@@ -10,14 +10,14 @@
#include <math.h>
#if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#define sqrtf(X) (f32)sqrt(X)
#define sinf(X) (f32)sin(X)
#define cosf(X) (f32)cos(X)
#define ceilf(X) (f32)ceil(X)
#define floorf(X) (f32)floor(X)
#define powf(X,Y) (f32)pow(X,Y)
#define fmodf(X,Y) (f32)fmod(X,Y)
#define fabsf(X) (f32)fabs(X)
#define sqrtf(X) (f32)sqrt((f64)(X))
#define sinf(X) (f32)sin((f64)(X))
#define cosf(X) (f32)cos((f64)(X))
#define ceilf(X) (f32)ceil((f64)(X))
#define floorf(X) (f32)floor((f64)(X))
#define powf(X,Y) (f32)pow((f64)(X),(f64)(Y))
#define fmodf(X,Y) (f32)fmod((f64)(X),(f64)(Y))
#define fabsf(X) (f32)fabs((f64)(X))
#endif
namespace irr
......@@ -83,7 +83,7 @@ namespace core
return a < b ? b : a;
}
//! returns minimum of three values. Own implementation to get rid of the STL (VS6 problems)
//! returns maximum of three values. Own implementation to get rid of the STL (VS6 problems)
template<class T>
inline const T& max_(const T& a, const T& b, const T& c)
{
......
......@@ -104,7 +104,7 @@ class line3d
if (d < 0.0)
return false;
outdistance = v - sqrt(d);
outdistance = v - sqrt((f64)d);
return true;
}
......
......@@ -472,7 +472,7 @@ inline void quaternion::fromAngleAxis(f32 angle, const vector3df& axis)
inline void quaternion::toAngleAxis(f32 &angle, core::vector3df &axis) const
{
f32 scale = sqrt (X*X + Y*Y + Z*Z);
f32 scale = sqrtf(X*X + Y*Y + Z*Z);
if (core::iszero(scale) || W > 1.0f || W < -1.0f)
{
......
......@@ -14,10 +14,10 @@ namespace irr
namespace core
{
//! Rectangle template.
//! Rectangle template.
/** Mostly used by 2D GUI elements and for 2D drawing methods.
It has 2 positions instead of position and dimension
and a fast method for collision detection with other rectangles and points.
It has 2 positions instead of position and dimension and a fast
method for collision detection with other rectangles and points.
*/
template <class T>
class rect
......@@ -32,9 +32,6 @@ namespace core
rect(const position2d<T>& upperLeft, const position2d<T>& lowerRight)
: UpperLeftCorner(upperLeft), LowerRightCorner(lowerRight) {}
rect(const rect<T>& other)
: UpperLeftCorner(other.UpperLeftCorner), LowerRightCorner(other.LowerRightCorner) {}
rect(const position2d<T>& pos, const dimension2d<T>& size)
: UpperLeftCorner(pos), LowerRightCorner(pos.X + size.Width, pos.Y + size.Height) {}
......@@ -42,12 +39,10 @@ namespace core
rect<T> operator+(const position2d<T>& pos) const
{
rect<T> ret(*this);
ret.UpperLeftCorner += pos;
ret.LowerRightCorner += pos;
return ret;
return ret+=pos;
}
const rect<T>& operator+=(const position2d<T>& pos)
rect<T>& operator+=(const position2d<T>& pos)
{
UpperLeftCorner += pos;
LowerRightCorner += pos;
......@@ -57,40 +52,31 @@ namespace core
rect<T> operator-(const position2d<T>& pos) const
{
rect<T> ret(*this);
ret.UpperLeftCorner -= pos;
ret.LowerRightCorner -= pos;
return ret;
return ret-=pos;
}
const rect<T>& operator-=(const position2d<T>& pos)
rect<T>& operator-=(const position2d<T>& pos)
{
UpperLeftCorner -= pos;
LowerRightCorner -= pos;
return *this;
}
bool operator == (const rect<T>& other) const
bool operator==(const rect<T>& other) const
{
return (UpperLeftCorner == other.UpperLeftCorner &&
LowerRightCorner == other.LowerRightCorner);
}
bool operator != (const rect<T>& other) const
bool operator!=(const rect<T>& other) const
{
return (UpperLeftCorner != other.UpperLeftCorner ||
LowerRightCorner != other.LowerRightCorner);
}
const rect<T>& operator = (const rect<T>& other)
{
UpperLeftCorner = other.UpperLeftCorner;
LowerRightCorner = other.LowerRightCorner;
return *this;
}
// compares size of rectangles
bool operator < (const rect<T>& other) const
bool operator<(const rect<T>& other) const
{
return getArea() < other.getArea();
}
......@@ -212,15 +198,11 @@ namespace core
//! Returns if the rect is valid to draw. It could be invalid
//! if the UpperLeftCorner is lower or more right than the
//! LowerRightCorner, or if the area described by the rect is 0.
//! LowerRightCorner, or if any dimension is 0.
bool isValid() const
{
// thx to jox for a correction to this method
T xd = LowerRightCorner.X - UpperLeftCorner.X;
T yd = LowerRightCorner.Y - UpperLeftCorner.Y;
return !(xd <= 0 || yd <= 0 || (xd == 0 && yd == 0));
return ((LowerRightCorner.X >= UpperLeftCorner.X) &&
(LowerRightCorner.Y >= UpperLeftCorner.Y));
}
//! Returns the center of the rectangle
......@@ -251,11 +233,15 @@ namespace core
//! \param y: Y Coordinate of the point to add to this box.
void addInternalPoint(T x, T y)
{
if (x>LowerRightCorner.X) LowerRightCorner.X = x;
if (y>LowerRightCorner.Y) LowerRightCorner.Y = y;
if (x<UpperLeftCorner.X) UpperLeftCorner.X = x;
if (y<UpperLeftCorner.Y) UpperLeftCorner.Y = y;
if (x>LowerRightCorner.X)
LowerRightCorner.X = x;
if (y>LowerRightCorner.Y)
LowerRightCorner.Y = y;
if (x<UpperLeftCorner.X)
UpperLeftCorner.X = x;
if (y<UpperLeftCorner.Y)
UpperLeftCorner.Y = y;
}
......
......@@ -180,7 +180,7 @@ public:
if (tmp == 0.0)
return 90.0;
tmp = tmp / sqrt((X*X + Y*Y) * (b.X*b.X + b.Y*b.Y));
tmp = tmp / sqrt((f64)((X*X + Y*Y) * (b.X*b.X + b.Y*b.Y)));
if (tmp < 0.0)
tmp = -tmp;
......
......@@ -77,7 +77,7 @@ namespace core
void set(const vector3d<T>& p) { X=p.X; Y=p.Y; Z=p.Z;}
//! Returns length of the vector.
T getLength() const { return (T) sqrt(X*X + Y*Y + Z*Z); }
T getLength() const { return (T) sqrt((f64)(X*X + Y*Y + Z*Z)); }
//! Returns squared length of the vector.
/** This is useful because it is much faster than
......@@ -242,7 +242,7 @@ namespace core
if (angle.Y < 0.0f) angle.Y += 360.0f;
if (angle.Y >= 360.0f) angle.Y -= 360.0f;
f32 z1 = (f32)sqrt(X*X + Z*Z);
f32 z1 = sqrtf(X*X + Z*Z);
angle.X = (T)atan2(z1, Y);
angle.X *= (f32)RADTODEG64;
......
......@@ -296,9 +296,6 @@ void CAnimatedMeshSceneNode::render()
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
u32 i,g;
if (Shadow && PassCount==1)
Shadow->setMeshToRenderFrom(m);
......@@ -311,12 +308,12 @@ void CAnimatedMeshSceneNode::render()
// overwrite half transparency
if ( DebugDataVisible & scene::EDS_HALF_TRANSPARENCY )
{
for ( g=0; g<m->getMeshBufferCount(); ++g)
for (u32 g=0; g<m->getMeshBufferCount(); ++g)
{
mat = Materials[g];
mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
driver->setMaterial(mat);
driver->drawMeshBuffer ( m->getMeshBuffer ( g ) );
driver->drawMeshBuffer ( m->getMeshBuffer(g) );
}
renderMeshes = 0;
}
......@@ -325,7 +322,7 @@ void CAnimatedMeshSceneNode::render()
// render original meshes
if ( renderMeshes )
{
for ( i=0; i<m->getMeshBufferCount(); ++i)
for (u32 i=0; i<m->getMeshBufferCount(); ++i)
{
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(Materials[i].MaterialType);
bool transparent = (rnd && rnd->isTransparent());
......@@ -357,11 +354,10 @@ void CAnimatedMeshSceneNode::render()
// show bounding box
if ( DebugDataVisible & scene::EDS_BBOX_BUFFERS )
{
for ( g=0; g< m->getMeshBufferCount(); ++g)
for (u32 g=0; g< m->getMeshBufferCount(); ++g)
{
driver->draw3DBox( m->getMeshBuffer(g)->getBoundingBox(),
video::SColor(0,190,128,128)
);
video::SColor(0,190,128,128) );
}
}
......@@ -377,7 +373,7 @@ void CAnimatedMeshSceneNode::render()
// draw skeleton
for ( g=0; g < ((ISkinnedMesh*)Mesh)->getAllJoints().size(); g +=1 )
for (u32 g=0; g < ((ISkinnedMesh*)Mesh)->getAllJoints().size(); ++g)
{
ISkinnedMesh::SJoint *joint=((ISkinnedMesh*)Mesh)->getAllJoints()[g];
......@@ -447,12 +443,12 @@ void CAnimatedMeshSceneNode::render()
core::matrix4 m2;
// draw normals
for ( g=0; g<m->getMeshBufferCount(); ++g)
for (u32 g=0; g<m->getMeshBufferCount(); ++g)
{
scene::IMeshBuffer* mb = m->getMeshBuffer(g);
const scene::IMeshBuffer* mb = m->getMeshBuffer(g);
const u32 vSize = video::getVertexPitchFromType(mb->getVertexType());
const video::S3DVertex* v = ( const video::S3DVertex*)mb->getVertices();
for ( i = 0; i != mb->getVertexCount(); ++i )
for ( u32 i=0; i != mb->getVertexCount(); ++i )
{
AlignToUpVector ( m2, v->Normal );
......@@ -476,14 +472,12 @@ void CAnimatedMeshSceneNode::render()
mat.Wireframe = true;
driver->setMaterial(mat);
for ( g=0; g<m->getMeshBufferCount(); ++g)
for (u32 g=0; g<m->getMeshBufferCount(); ++g)
{
driver->drawMeshBuffer ( m->getMeshBuffer ( g ) );
driver->drawMeshBuffer( m->getMeshBuffer(g) );
}
}
}
}
......@@ -848,7 +842,7 @@ void CAnimatedMeshSceneNode::updateAbsolutePosition()
if ( taglist )
{
MD3Special.AbsoluteTagList.Container.set_used ( taglist->size () );
for ( u32 i = 0; i!= taglist->size (); ++i )
for ( u32 i=0; i!= taglist->size (); ++i )
{
MD3Special.AbsoluteTagList[i].position = parent.position + (*taglist)[i].position + relative.position;
MD3Special.AbsoluteTagList[i].rotation = parent.rotation * (*taglist)[i].rotation * relative.rotation;
......
......@@ -944,8 +944,6 @@ void CD3D9Driver::draw2DImage(const video::ITexture* texture,
core::position2d<s32> sourcePos = sourceRect.UpperLeftCorner;
core::dimension2d<s32> sourceSize(sourceRect.getSize());
core::dimension2d<s32> renderTargetSize = getCurrentRenderTargetSize();
if (clipRect)
{
if (targetPos.X < clipRect->UpperLeftCorner.X)
......@@ -995,6 +993,8 @@ void CD3D9Driver::draw2DImage(const video::ITexture* texture,
targetPos.X = 0;
}
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
if (targetPos.X + sourceSize.Width > renderTargetSize.Width)
{
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
......@@ -1022,11 +1022,11 @@ void CD3D9Driver::draw2DImage(const video::ITexture* texture,
// ok, we've clipped everything.
// now draw it.
f32 xPlus = - renderTargetSize.Width / 2.f;
f32 xFact = 1.0f / (renderTargetSize.Width / 2.f);
s32 xPlus = -renderTargetSize.Width / 2;
f32 xFact = 2.0f / renderTargetSize.Width;
f32 yPlus = renderTargetSize.Height-(renderTargetSize.Height / 2.f);
f32 yFact = 1.0f / (renderTargetSize.Height / 2.f);
s32 yPlus = renderTargetSize.Height / 2;
f32 yFact = 2.0f / renderTargetSize.Height;
core::rect<f32> tcoords;
tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)+0.5f) / texture->getOriginalSize().Width ;
......@@ -1069,11 +1069,11 @@ void CD3D9Driver::draw2DRectangle(const core::rect<s32>& position,
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
s32 xPlus = -(renderTargetSize.Width>>1);
f32 xFact = 1.0f / (renderTargetSize.Width>>1);
s32 xPlus = -renderTargetSize.Width / 2;
f32 xFact = 2.0f / renderTargetSize.Width;
s32 yPlus = renderTargetSize.Height-(renderTargetSize.Height>>1);
f32 yFact = 1.0f / (renderTargetSize.Height>>1);
s32 yPlus = renderTargetSize.Height / 2;
f32 yFact = 2.0f / renderTargetSize.Height;
S3DVertex vtx[4];
vtx[0] = S3DVertex((f32)(pos.UpperLeftCorner.X+xPlus) * xFact, (f32)(yPlus-pos.UpperLeftCorner.Y) * yFact , 0.0f, 0.0f, 0.0f, 0.0f, colorLeftUp, 0.0f, 0.0f);
......@@ -1108,11 +1108,11 @@ void CD3D9Driver::draw2DLine(const core::position2d<s32>& start,
// thanks to Vash TheStampede who sent in his implementation
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
const s32 xPlus = -(renderTargetSize.Width>>1);
const f32 xFact = 1.0f / (renderTargetSize.Width>>1);
const s32 xPlus = -renderTargetSize.Width / 2;
const f32 xFact = 2.0f / renderTargetSize.Width;
const s32 yPlus = renderTargetSize.Height-(renderTargetSize.Height>>1);
const f32 yFact = 1.0f / (renderTargetSize.Height>>1);
const s32 yPlus = renderTargetSize.Height / 2;
const f32 yFact = 2.0f / renderTargetSize.Height;
S3DVertex vtx[2];
vtx[0] = S3DVertex((f32)(start.X + xPlus) * xFact,
......
......@@ -708,7 +708,6 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
core::position2d<s32> targetPos(pos);
core::position2d<s32> sourcePos(sourceRect.UpperLeftCorner);
core::dimension2d<s32> sourceSize(sourceRect.getSize());
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
if (clipRect)
{
if (targetPos.X < clipRect->UpperLeftCorner.X)
......@@ -758,6 +757,8 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
targetPos.X = 0;
}
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
if (targetPos.X + sourceSize.Width > renderTargetSize.Width)
{
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
......@@ -793,7 +794,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
tcoords.LowerRightCorner.X = (sourcePos.X + sourceSize.Width) / static_cast<f32>(ss.Width);
tcoords.LowerRightCorner.Y = (sourcePos.Y + sourceSize.Height) / static_cast<f32>(ss.Height);
core::rect<s32> poss(targetPos, sourceSize);
const core::rect<s32> poss(targetPos, sourceSize);
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
......@@ -820,6 +821,73 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
//! The same, but with a four element array of colors, one for each vertex
void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
video::SColor* colors, bool useAlphaChannelOfTexture)
{
if (!texture)
return;
const core::dimension2d<s32>& ss = texture->getOriginalSize();
core::rect<f32> tcoords;
tcoords.UpperLeftCorner.X = sourceRect.UpperLeftCorner.X / static_cast<f32>(ss.Width);
tcoords.UpperLeftCorner.Y = sourceRect.UpperLeftCorner.Y / static_cast<f32>(ss.Height);
tcoords.LowerRightCorner.X = sourceRect.LowerRightCorner.X / static_cast<f32>(ss.Width);
tcoords.LowerRightCorner.Y = sourceRect.LowerRightCorner.Y / static_cast<f32>(ss.Height);
video::SColor temp[4] =
{
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF
};
video::SColor* useColor = colors ? colors : temp;
setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 || useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
setTexture(0, texture);
if (clipRect)
{
if (!clipRect->isValid())
return;
glEnable(GL_SCISSOR_TEST);
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height-clipRect->LowerRightCorner.Y,
clipRect->getWidth(), clipRect->getHeight());
}
glBegin(GL_QUADS);
glColor4ub(useColor[0].getRed(), useColor[0].getGreen(), useColor[0].getBlue(), useColor[0].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
glVertex2f(GLfloat(destRect.UpperLeftCorner.X), GLfloat(destRect.UpperLeftCorner.Y));
glColor4ub(useColor[3].getRed(), useColor[3].getGreen(), useColor[3].getBlue(), useColor[3].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
glVertex2f(GLfloat(destRect.LowerRightCorner.X), GLfloat(destRect.UpperLeftCorner.Y));
glColor4ub(useColor[2].getRed(), useColor[2].getGreen(), useColor[2].getBlue(), useColor[2].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
glVertex2f(GLfloat(destRect.LowerRightCorner.X), GLfloat(destRect.LowerRightCorner.Y));
glColor4ub(useColor[1].getRed(), useColor[1].getGreen(), useColor[1].getBlue(), useColor[1].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
glVertex2f(GLfloat(destRect.UpperLeftCorner.X), GLfloat(destRect.LowerRightCorner.Y));
glEnd();
if (clipRect)
glDisable(GL_SCISSOR_TEST);
}
//! draws a set of 2d images, using a color and the alpha channel of the
//! texture if desired. The images are drawn beginning at pos and concatenated
//! in one line. All drawings are clipped against clipRect (if != 0).
......@@ -835,8 +903,6 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
if (!texture)
return;
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
if (!setTexture(0, texture))
......@@ -849,6 +915,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
return;
glEnable(GL_SCISSOR_TEST);
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height-clipRect->LowerRightCorner.Y,
clipRect->getWidth(),clipRect->getHeight());
}
......@@ -872,7 +939,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
tcoords.LowerRightCorner.X = sourceRects[currentIndex].LowerRightCorner.X / static_cast<f32>(ss.Width);
tcoords.LowerRightCorner.Y = sourceRects[currentIndex].LowerRightCorner.Y / static_cast<f32>(ss.Height);
core::rect<s32> poss(targetPos, sourceSize);
const core::rect<s32> poss(targetPos, sourceSize);
glBegin(GL_QUADS);
......@@ -897,72 +964,6 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
video::SColor* colors, bool useAlphaChannelOfTexture)
{
if (!texture)
return;
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
const core::dimension2d<s32>& ss = texture->getOriginalSize();
core::rect<f32> tcoords;
tcoords.UpperLeftCorner.X = sourceRect.UpperLeftCorner.X / static_cast<f32>(ss.Width);
tcoords.UpperLeftCorner.Y = sourceRect.UpperLeftCorner.Y / static_cast<f32>(ss.Height);
tcoords.LowerRightCorner.X = sourceRect.LowerRightCorner.X / static_cast<f32>(ss.Width);
tcoords.LowerRightCorner.Y = sourceRect.LowerRightCorner.Y / static_cast<f32>(ss.Height);
video::SColor temp[4] =
{
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF
};
video::SColor* useColor = colors ? colors : temp;
setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 || useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255, true, useAlphaChannelOfTexture);
disableTextures(1);
setTexture(0, texture);
if (clipRect)
{
if (!clipRect->isValid())
return;
glEnable(GL_SCISSOR_TEST);
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height-clipRect->LowerRightCorner.Y,
clipRect->getWidth(), clipRect->getHeight());
}
glBegin(GL_QUADS);
glColor4ub(useColor[0].getRed(), useColor[0].getGreen(), useColor[0].getBlue(), useColor[0].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
glVertex2f(GLfloat(destRect.UpperLeftCorner.X), GLfloat(destRect.UpperLeftCorner.Y));
glColor4ub(useColor[3].getRed(), useColor[3].getGreen(), useColor[3].getBlue(), useColor[3].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
glVertex2f(GLfloat(destRect.LowerRightCorner.X), GLfloat(destRect.UpperLeftCorner.Y));
glColor4ub(useColor[2].getRed(), useColor[2].getGreen(), useColor[2].getBlue(), useColor[2].getAlpha());
glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
glVertex2f(GLfloat(destRect.LowerRightCorner.X), GLfloat(destRect.LowerRightCorner.Y));
glColor4ub(useColor[1].getRed(), useColor[1].getGreen(), useColor[1].getBlue(), useColor[1].getAlpha());
glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
glVertex2f(GLfloat(destRect.UpperLeftCorner.X), GLfloat(destRect.LowerRightCorner.Y));
glEnd();
if (clipRect)
glDisable(GL_SCISSOR_TEST);
}
//! draw a 2d rectangle
void COpenGLDriver::draw2DRectangle(SColor color, const core::rect<s32>& position,
const core::rect<s32>* clip)
......@@ -1499,10 +1500,8 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
glMatrixMode(GL_PROJECTION);
const core::dimension2d<s32>& renderTargetSize = getCurrentRenderTargetSize();
const core::vector3df translation(-1,1,0);
m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-renderTargetSize.Height), -1.0, 1.0);
m.setTranslation(translation);
m.setTranslation(core::vector3df(-1,1,0));
createGLMatrix(glmat, m);
glLoadMatrixf(glmat);
......
......@@ -18,6 +18,7 @@ namespace irr
namespace io
{
class IXMLWriter;
class IFileSystem;
}
namespace scene
{
......
......@@ -84,9 +84,9 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
++ShadowVolumesUsed;
}
s32 faceCount = (int)(IndexCount / 3);
const s32 faceCount = (s32)(IndexCount / 3);
if (faceCount * 6 > EdgeCount || !Edges)
if (!Edges || faceCount * 6 > EdgeCount)
{
delete [] Edges;
EdgeCount = faceCount * 6;
......@@ -94,7 +94,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
}
s32 numEdges = 0;
core::vector3df ls = light * Infinity; // light scaled
const core::vector3df ls = light * Infinity; // light scaled
//if (UseZFailMethod)
// createZFailVolume(faceCount, numEdges, light, svp);
......@@ -132,16 +132,15 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges,
const core::vector3df& light,
SShadowVolume* svp)
{
u16 wFace0, wFace1, wFace2;
s32 i;
core::vector3df ls = light * Infinity;
const core::vector3df ls = light * Infinity;
// Check every face if it is front or back facing the light.
for (i=0; i<faceCount; ++i)
{
wFace0 = Indices[3*i+0];
wFace1 = Indices[3*i+1];
wFace2 = Indices[3*i+2];
const u16 wFace0 = Indices[3*i+0];
const u16 wFace1 = Indices[3*i+1];
const u16 wFace2 = Indices[3*i+2];
const core::vector3df v0 = Vertices[wFace0];
const core::vector3df v1 = Vertices[wFace1];
......@@ -168,18 +167,17 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges,
FaceData[i] = true; // it's a front facing face
}
for(i=0; i<faceCount; ++i)
{
if (FaceData[i] == true)
{
wFace0 = Indices[3*i+0];
wFace1 = Indices[3*i+1];
wFace2 = Indices[3*i+2];
const u16 wFace0 = Indices[3*i+0];
const u16 wFace1 = Indices[3*i+1];
const u16 wFace2 = Indices[3*i+2];
u16 adj0 = Adjacency[3*i+0];
u16 adj1 = Adjacency[3*i+1];
u16 adj2 = Adjacency[3*i+2];
const u16 adj0 = Adjacency[3*i+0];
const u16 adj1 = Adjacency[3*i+1];
const u16 adj2 = Adjacency[3*i+2];
if (adj0 != (u16)-1 && FaceData[adj0] == false)
{
......@@ -217,13 +215,11 @@ void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
if (light == core::vector3df(0,0,0))
light = core::vector3df(0.0001f,0.0001f,0.0001f);
u16 wFace0, wFace1, wFace2;
for (s32 i=0; i<faceCount; ++i)
{
wFace0 = Indices[3*i+0];
wFace1 = Indices[3*i+1];
wFace2 = Indices[3*i+2];
const u16 wFace0 = Indices[3*i+0];
const u16 wFace1 = Indices[3*i+1];
const u16 wFace2 = Indices[3*i+2];
if (core::triangle3df(Vertices[wFace0],Vertices[wFace1],Vertices[wFace2]).isFrontFacing(light))
{
......@@ -353,7 +349,7 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(const IMesh* mesh)
}
}
// recalculate adjacency if neccessarry
// recalculate adjacency if necessary
if (oldVertexCount != VertexCount &&
oldIndexCount != IndexCount && UseZFailMethod)
calculateAdjacency();
......@@ -451,11 +447,11 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
for (s32 e=0; e<3; ++e)
{
t = v1.getDistanceFromSQ(Vertices[Indices[of+e]]);
if (t <= epsilon && t >= -epsilon)
if (core::iszero(t))
++cnt1;
t = v2.getDistanceFromSQ(Vertices[Indices[of+e]]);
if (t <= epsilon && t >= -epsilon)
if (core::iszero(t))
++cnt2;
}
......@@ -474,3 +470,4 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
} // end namespace scene
} // end namespace irr
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment