Пример #1
0
METHODPREFIX
void
GLFrustum<ScalarParam>::setFromGL(
	void)
	{
	typedef Geometry::ProjectiveTransformation<double,3> PTransform;
	
	/* Read projection and modelview matrices from OpenGL: */
	PTransform pmv=glGetProjectionMatrix<double>();
	pmv*=glGetModelviewMatrix<double>();
	pmv.doInvert();
	
	/* Calculate the eight frustum vertices: */
	frustumVertices[0]=Point(pmv.transform(Geometry::Point<double,3>(-1,-1,-1)));
	frustumVertices[1]=Point(pmv.transform(Geometry::Point<double,3>( 1,-1,-1)));
	frustumVertices[2]=Point(pmv.transform(Geometry::Point<double,3>(-1, 1,-1)));
	frustumVertices[3]=Point(pmv.transform(Geometry::Point<double,3>( 1, 1,-1)));
	frustumVertices[4]=Point(pmv.transform(Geometry::Point<double,3>(-1,-1, 1)));
	frustumVertices[5]=Point(pmv.transform(Geometry::Point<double,3>( 1,-1, 1)));
	frustumVertices[6]=Point(pmv.transform(Geometry::Point<double,3>(-1, 1, 1)));
	frustumVertices[7]=Point(pmv.transform(Geometry::Point<double,3>( 1, 1, 1)));
	
	/* Calculate the six frustum face planes: */
	Vector fv10=frustumVertices[1]-frustumVertices[0];
	Vector fv20=frustumVertices[2]-frustumVertices[0];
	Vector fv40=frustumVertices[4]-frustumVertices[0];
	Vector fv67=frustumVertices[6]-frustumVertices[7];
	Vector fv57=frustumVertices[5]-frustumVertices[7];
	Vector fv37=frustumVertices[3]-frustumVertices[7];
	frustumPlanes[0]=Plane(Geometry::cross(fv40,fv20),frustumVertices[0]);
	frustumPlanes[1]=Plane(Geometry::cross(fv57,fv37),frustumVertices[7]);
	frustumPlanes[2]=Plane(Geometry::cross(fv10,fv40),frustumVertices[0]);
	frustumPlanes[3]=Plane(Geometry::cross(fv37,fv67),frustumVertices[7]);
	frustumPlanes[4]=Plane(Geometry::cross(fv20,fv10),frustumVertices[0]);
	Scalar screenArea=Geometry::mag(frustumPlanes[4].getNormal());
	frustumPlanes[5]=Plane(Geometry::cross(fv67,fv57),frustumVertices[7]);
	for(int i=0;i<6;++i)
		frustumPlanes[i].normalize();
	
	/* Use the frustum near plane as the screen plane: */
	screenPlane=frustumPlanes[4];
	
	/* Calculate the eye point: */
	eye=HVector(pmv.transform(Geometry::HVector<double,3>(0,0,1,0)));
	
	/* Calculate the inverse eye-screen distance: */
	eyeScreenDist=eye[3]/(screenPlane.getNormal()[0]*eye[0]+screenPlane.getNormal()[1]*eye[1]+screenPlane.getNormal()[2]*eye[2]-screenPlane.getOffset()*eye[3]);
	
	/* Get viewport size from OpenGL: */
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT,viewport);
	
	/* Calculate the inverse pixel size: */
	pixelSize=Math::sqrt((Scalar(viewport[2])*Scalar(viewport[3]))/screenArea);
	}
Пример #2
0
    void Render(Context* pcontext)
    {
        MeshIndex* pindex = (MeshIndex*)&(m_vindex[0]);

        m_pnode->Render(
            pindex, 
            HVector(
                pcontext->TransformEyeToLocal(Vector(0, 0, 0))
            )
        );
        pcontext->SetBlendMode(BlendModeSourceAlpha);
        pcontext->SetCullMode(CullModeNone);
        pcontext->DrawTriangles(m_vvertex, m_vindex);
    }
HVector Matrix::Transform(const HVector& vec) const
{
    float x = vec.X();
    float y = vec.Y();
    float z = vec.Z();
    float w = vec.W();

    return
        HVector(
            m_m[0][0] * x + m_m[0][1] * y + m_m[0][2] * z + m_m[0][3] * w,
            m_m[1][0] * x + m_m[1][1] * y + m_m[1][2] * z + m_m[1][3] * w,
            m_m[2][0] * x + m_m[2][1] * y + m_m[2][2] * z + m_m[2][3] * w,
            m_m[3][0] * x + m_m[3][1] * y + m_m[3][2] * z + m_m[3][3] * w
        );
}
void Matrix::Transform(const TVector<HVector>& vSource, TVector<HVector>& vDest) const
{
    int count = vSource.GetCount();
    vDest.SetCount(count);

    for (int index = 0; index < count; index++) {
        float x = vSource[index].X();
        float y = vSource[index].Y();
        float z = vSource[index].Z();

        vDest.Set(
            index,
            HVector(
                m_m[0][0] * x + m_m[0][1] * y + m_m[0][2] * z + m_m[0][3],
                m_m[1][0] * x + m_m[1][1] * y + m_m[1][2] * z + m_m[1][3],
                m_m[2][0] * x + m_m[2][1] * y + m_m[2][2] * z + m_m[2][3]
            )
        );
    }
}
Пример #5
0
// HVector.cpp: implementation of the HVector class.
//
//////////////////////////////////////////////////////////////////////

#include "HVector.h"
#include <assert.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

const HVector HVector::Zero=HVector(0,0,0);
/*
static HVector & HVector::NULL()
{
	m[0]=m[1]=m[2]=0;
}
*/

HVector::HVector(double a, double b, double c)
{
	m[0]=a;
	m[1]=b;
	m[2]=c;
}

HVector::HVector(const AN8XVECTOR3 & an8)
{
  m[0]=an8.x;
  m[1]=an8.y;
  m[2]=an8.z;