Newer
Older
Import / research / 3d-octrees / jNormal.h
/*
 * =====================================================================================
 *
 *       Filename:  jNormal.h
 *
 *    Description:  A special case of jVector3f which caches if it is normalized or not
 *
 *        Version:  1.0
 *        Created:  31/05/2011 22:06:55
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  John Ryland (jryland), jryland@xiaofrog.com
 *        Company:  InvertedLogic
 *
 * =====================================================================================
 */

#ifndef __J_NORMAL_H__
#define __J_NORMAL_H__


#include <jVector.h>


class jNormal
{
public:
    jNormal();
    jNormal(jNormal& a_normal);
    jNormal(jVector3f& a_vector);

    void setNormal(jNormal& a_normal);
    void setVector(const jVector3f& a_vector, bool a_normalized = false);
    jVector3f getVector();

    void normalize();

private:
    enum jNormalFlags {
        NORMALIZED = 1,
        DIRTY = 2
    };
    jInt8 m_flags;

    // Need to consider if floats are best, when normalized all values between -1 to 1
    // And as one value approaches 1, the others diminish, so the sum is in another range
    // Really can be represented more simply as 2 angles, but limits use in dot products etc.
    jVector3f m_vec;
};


class jNormalIterator
{
public:
    jNormalIterator(jNormal& a_startNormal, jNormal& a_endNormal, int a_steps);
    jNormal step(int a_times = 1);
    
    jNormalIterator(jNormal& a_startNormal, jNormal& a_endNormal, jNormal& a_dotProductWith, int a_steps);
    jInt8 stepDotInfinityI();
    jFloat32 stepDotInfinityF();

    jNormalIterator(jNormal& a_startNormal, jNormal& a_endNormal, jVector3f& a_start, jVector3f& a_end, jVector3f& a_dotProductWith, int a_steps);
    //jNormalIterator(jNormal& a_startNormal, jNormal& a_endNormal, jVector3f& a_dotProductWith, int a_steps);
    jInt8 stepDotPointI();
    jFloat32 stepDotPointF();

private:
    jVector3f m_current;
    jVector3f m_delta;
    jFloat32 m_distSqr;
    jFloat32 m_distSqrForwardDiff;
    jFloat32 m_unNormalizedDotForwardDiff;
    jFloat32 m_currentDot;
    jVector3f m_surfacePoint;
    jVector3f m_surfacePointDelta;
};


#endif // __J_NORMAL_H__