Ejemplo n.º 1
0
    //-----------------------------------------------------------------------
    void Polygon::updateNormal( void ) const
    {
        OgreAssertDbg( getVertexCount() >= 3, "Insufficient vertex count!" );

        if (mIsNormalSet)
            return;

        // vertex order is ccw
        const Vector3& a = getVertex( 0 );
        const Vector3& b = getVertex( 1 );
        const Vector3& c = getVertex( 2 );

        // used method: Newell
        mNormal.x = 0.5f * ( (a.y - b.y) * (a.z + b.z) +
                               (b.y - c.y) * (b.z + c.z) + 
                               (c.y - a.y) * (c.z + a.z));

        mNormal.y = 0.5f * ( (a.z - b.z) * (a.x + b.x) +
                               (b.z - c.z) * (b.x + c.x) + 
                               (c.z - a.z) * (c.x + a.x));

        mNormal.z = 0.5f * ( (a.x - b.x) * (a.y + b.y) +
                               (b.x - c.x) * (b.y + c.y) + 
                               (c.x - a.x) * (c.y + a.y));

        mNormal.normalise();

        mIsNormalSet = true;

    }
Ejemplo n.º 2
0
    //-----------------------------------------------------------------------
    void Polygon::setVertex(const Vector3& vdata, size_t vertex )
    {
        // TODO: optional: check planarity
        OgreAssertDbg(vertex < getVertexCount(), "Search position out of range" );

        // set new vertex
        mVertexList[ vertex ] = vdata;
    }
Ejemplo n.º 3
0
    //-----------------------------------------------------------------------
    void Polygon::deleteVertex( size_t vertex )
    {
        OgreAssertDbg( vertex < getVertexCount(), "Search position out of range" );

        VertexList::iterator it = mVertexList.begin();
        std::advance(it, vertex);

        mVertexList.erase( it );
    }
Ejemplo n.º 4
0
    //-----------------------------------------------------------------------
    void Polygon::insertVertex(const Vector3& vdata, size_t vertex )
    {
        // TODO: optional: check planarity
        OgreAssertDbg(vertex <= getVertexCount(), "Insert position out of range" );

        VertexList::iterator it = mVertexList.begin();

        std::advance(it, vertex);
        mVertexList.insert(it, vdata);

    }
Ejemplo n.º 5
0
 GLenum GL3PlusPixelUtil::getGLOriginFormat(PixelFormat pf)
 {
     OgreAssertDbg(sizeof(_pixelFormats)/sizeof(GLPixelFormatDescription) == PF_COUNT, "Did you add a new format?");
     return _pixelFormats[pf].format;
 }
Ejemplo n.º 6
0
    //---------------------------------------------------------------------
    Real AnimationTrack::getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
        unsigned short* firstKeyIndex) const
    {
        // Parametric time
        // t1 = time of previous keyframe
        // t2 = time of next keyframe
        Real t1, t2;

        Real timePos = timeIndex.getTimePos();

        // Find first keyframe after or on current time
        KeyFrameList::const_iterator i;
        if (timeIndex.hasKeyIndex())
        {
            // Global keyframe index available, map to local keyframe index directly.
            assert(timeIndex.getKeyIndex() < mKeyFrameIndexMap.size());
            i = mKeyFrames.begin() + mKeyFrameIndexMap[timeIndex.getKeyIndex()];
#if OGRE_DEBUG_MODE
            KeyFrame timeKey(0, timePos);
            if (i != std::lower_bound(mKeyFrames.begin(), mKeyFrames.end(), &timeKey, KeyFrameTimeLess()))
            {
                OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                    "Optimised key frame search failed",
                    "AnimationTrack::getKeyFramesAtTime");
            }
#endif
        }
        else
        {
            // Wrap time
            Real totalAnimationLength = mParent->getLength();
            OgreAssertDbg(totalAnimationLength > 0.0f, "Invalid animation length!");

            if( timePos > totalAnimationLength && totalAnimationLength > 0.0f )
                timePos = std::fmod( timePos, totalAnimationLength );

            // No global keyframe index, need to search with local keyframes.
            KeyFrame timeKey(0, timePos);
            i = std::lower_bound(mKeyFrames.begin(), mKeyFrames.end(), &timeKey, KeyFrameTimeLess());
        }

        if (i == mKeyFrames.end())
        {
            // There is no keyframe after this time, wrap back to first
            *keyFrame2 = mKeyFrames.front();
            t2 = mParent->getLength() + (*keyFrame2)->getTime();

            // Use last keyframe as previous keyframe
            --i;
        }
        else
        {
            *keyFrame2 = *i;
            t2 = (*keyFrame2)->getTime();

            // Find last keyframe before or on current time
            if (i != mKeyFrames.begin() && timePos < (*i)->getTime())
            {
                --i;
            }
        }

        // Fill index of the first key
        if (firstKeyIndex)
        {
            *firstKeyIndex = static_cast<unsigned short>(std::distance(mKeyFrames.begin(), i));
        }

        *keyFrame1 = *i;

        t1 = (*keyFrame1)->getTime();

        if (t1 == t2)
        {
            // Same KeyFrame (only one)
            return 0.0;
        }
        else
        {
            return (timePos - t1) / (t2 - t1);
        }
    }
Ejemplo n.º 7
0
    //-----------------------------------------------------------------------
    const Vector3& Polygon::getVertex( size_t vertex ) const
    {
        OgreAssertDbg(vertex < getVertexCount(), "Search position out of range");

        return mVertexList[vertex];
    }