예제 #1
0
mlVector3D	mlVector3D::Normalised() const
{
	mlVector3D normalisedVector(x,y,z);
	
	mlFloat maxValue = 0.0f;
	
	if(mlFabs(normalisedVector.x) > maxValue) maxValue = mlFabs(normalisedVector.x);
	if(mlFabs(normalisedVector.y) > maxValue) maxValue = mlFabs(normalisedVector.y);
	if(mlFabs(normalisedVector.z) > maxValue) maxValue = mlFabs(normalisedVector.z);
	
	if(maxValue == 0.0f)
		return mlVector3D(x,y,z);
		
	normalisedVector.x = normalisedVector.x / maxValue;
	normalisedVector.y = normalisedVector.y / maxValue;
	normalisedVector.z = normalisedVector.z / maxValue;
	
	mlFloat mag = normalisedVector.Magnitude();
	
	if(mag == 0.0f)
		return mlVector3D(x,y,z);
	
	mlFloat invMag = 1.0f / mag;
	normalisedVector.x *= invMag;
	normalisedVector.y *= invMag;
	normalisedVector.z *= invMag;
	
	return normalisedVector;
}
예제 #2
0
파일: VectorSet.cpp 프로젝트: ptierney/inc
mlVector3D VectorSet::GetVector(int i)
{
	if(i < 0) return mlVector3D();
	if(i >= m_pVectors.size()) return mlVector3D();

	return m_pVectors[i];
}
예제 #3
0
void mlMatrix3x4::SetIdentity()
{
	I = mlVector3D(1.0f, 0.0f, 0.0f);
	J = mlVector3D(0.0f, 1.0f, 0.0f);
	K = mlVector3D(0.0f, 0.0f, 1.0f);
	
	T.SetZero();
}
예제 #4
0
void 	mlMatrixTranspose(mlMatrix3x3 & result, const mlMatrix3x3 & source)
{
	result = mlMatrix3x3(
		mlVector3D(source.I.x, source.J.x, source.K.x),
		mlVector3D(source.I.y, source.J.y, source.K.y),
		mlVector3D(source.I.z, source.J.z, source.K.z)
		);
}
예제 #5
0
mlTransform::
mlTransform()
:	m_rotation(1.0f, 0.0f, 0.0f, 0.0f),
	m_translation(0.0f, 0.0f, 0.0f),
	m_matrix(	mlVector3D(1.0f, 0.0f, 0.0f),
				mlVector3D(0.0f, 1.0f, 0.0f),
				mlVector3D(0.0f, 0.0f, 1.0f),
				mlVector3D(0.0f, 0.0f, 0.0f)	),
	m_scale(1.0f),
	m_matrix_valid(true)
{
}
예제 #6
0
mlVector3D mlVectorScale(const mlVector3D &a, const mlVector3D &b)
{
	return mlVector3D(
		a.x * b.x,
		a.y * b.y,
		a.z * b.z);
}
예제 #7
0
mlVector3D mlMatrix3x4::TransformVector(const mlVector3D &v) const
{
	return mlVector3D(
				I.x * v.x + J.x * v.y + K.x * v.z,
				I.y * v.x + J.y * v.y + K.y * v.z,
				I.z * v.x + J.z * v.y + K.z * v.z
			);
}
예제 #8
0
mlVector3D	mlVectorCross(const mlVector3D &a, const mlVector3D &b)
{
	return mlVector3D(
				a.y * b.z - a.z * b.y,
				a.z * b.x - a.x * b.z,
				a.x * b.y - a.y * b.x
			);
}
예제 #9
0
mlVector3D mlMatrix3x4::TransformVectorByTranspose(const mlVector3D &v) const
{
	return mlVector3D(
				I.x * v.x + I.y * v.y + I.z * v.z,
				J.x * v.x + J.y * v.y + J.z * v.z,
				K.x * v.x + K.y * v.y + K.z * v.z
			);
}
예제 #10
0
mlVector3D mlMatrix3x4::TransformPoint(const mlVector3D &v) const
{
	return mlVector3D(
				I.x * v.x + J.x * v.y + K.x * v.z + T.x,
				I.y * v.x + J.y * v.y + K.y * v.z + T.y,
				I.z * v.x + J.z * v.y + K.z * v.z + T.z
			);
}
예제 #11
0
mlVector3D mlMatrix3x4::TransformPointByTranspose(const mlVector3D &v) const
{
	mlVector3D temp = v - T;
	return mlVector3D(
				I.x * temp.x + I.y * temp.y + I.z * temp.z,
				J.x * temp.x + J.y * temp.y + J.z * temp.z,
				K.x * temp.x + K.y * temp.y + K.z * temp.z
			);
}
예제 #12
0
void World::UpdateMousePos(int nX, int nY)
{
    // Viewport already set in Reshape()
    int nViewportHeight = viewport[3];

    mlVector3D vOldPosition = m_vMouse2DPosition;
    mlVector3D vNewPosition = mlVector3D(nX, nViewportHeight - nY);

    m_vMouse2DPosition = vNewPosition;
    m_vMouse2DPositionDelta = vNewPosition - vOldPosition;
}
예제 #13
0
파일: Solid.cpp 프로젝트: ptierney/inc
/**
 * Loads a coordinates file, setting vertices and indices 
 * 
 * @param solidFile file used to create the solid
 * @param color solid color
 */
void Solid::loadCoordinateFile(const std::string & sFileName, const gxColor & colBase, int dRed, int dGreen, int dBlue)
{
	std::ifstream modelFile;

	modelFile.open(sFileName.c_str());

	int nNumVertices = 0;
	modelFile >> nNumVertices;

	for(int i = 0; i < nNumVertices; i++)
	{
		// Read in a vector.
		int nVertexID = 0;

		mlVector3D vPosition;

		modelFile >> nVertexID;

		modelFile >> vPosition.x;
		modelFile >> vPosition.y;
		modelFile >> vPosition.z;

		vPosition = mlVectorScale(vPosition, mlVector3D(0.5f, 0.5f, 0.5f));

		vertices.AddVector(vPosition);
	}

	// Now load up the indices.

	int nNumTriangles = 0;
	modelFile >> nNumTriangles;

	for(int i = 0; i < nNumTriangles; i++)
	{
		int nTriangleID = 0;

		int nTriIndex1 = 0;
		int nTriIndex2 = 0;
		int nTriIndex3 = 0;

		modelFile >> nTriangleID;

		modelFile >> nTriIndex1;
		modelFile >> nTriIndex2;
		modelFile >> nTriIndex3;

		indices.AddInt(nTriIndex1);
		indices.AddInt(nTriIndex2);
		indices.AddInt(nTriIndex3);
	}

	modelFile.close();

	for(int i = 0; i < nNumVertices; i++)
	{
		gxColor col = colBase;

		if(dRed < 0) col.red -= rand() % (-1*dRed); else if(dRed > 0) col.red += rand() % dRed;
		if(dGreen < 0) col.green -= rand() % (-1*dGreen); else if(dGreen > 0) col.green += rand() % dGreen;
		if(dBlue < 0) col.blue -= rand() % (-1*dBlue); else if(dBlue > 0) col.blue += rand() % dBlue;

		colors.AddColor(col);
	}
}
예제 #14
0
mlVector3D	operator * (mlFloat s, const mlVector3D &v)			{ return mlVector3D(v.x * s, v.y * s, v.z * s); }
예제 #15
0
mlVector3D	mlVector3D::operator -	() const			{ return mlVector3D(-x, -y, -z);}
예제 #16
0
mlVector3D	mlVector3D::operator -  (const mlVector3D &v) const	{ return mlVector3D(x - v.x, y - v.y, z - v.z); }
예제 #17
0
mlVector3D	mlVector3D::operator +  (const mlVector3D &v) const	{ return mlVector3D(x + v.x, y + v.y, z + v.z); }
예제 #18
0
void gxPick(const mlVector3D & rayPoint, const mlVector3D & rayVector, const gxModel & model, gxIntersectionResultSet & intersectionResultSet)
{
	intersectionResultSet.intersectionResults.clear();
	
	for(unsigned int i = 0; i < model.m_triangles.size(); i++)
	{
		utIntersectionResult currentIntersectionResult = utIntersectionPosition(rayPoint, rayVector, model.m_triangles[i]);
		if(currentIntersectionResult.lineLengthener > 0.0f && model.m_triangles[i].IsInTriangle(currentIntersectionResult.intersectionPosition))
		{
			gxIntersectionResult resultToStore(currentIntersectionResult, model.m_triangles[i]);
			intersectionResultSet.intersectionResults.push_back(resultToStore);
		}
	}

	mlLine lnRay(rayPoint, rayPoint + rayVector);

	for(unsigned int i = 0; i < model.m_lines.size(); i++)
	{
		const mlLine & line = model.m_lines[i];

		mlLine lnJoiningLine = lnRay.ShortestLineToLine(line);
		
		GLdouble modelMatrix[16];
		GLdouble projMatrix[16];
		GLint viewport[4];

		glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
		glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
		glGetIntegerv(GL_VIEWPORT, viewport);

		GLdouble win1x;
		GLdouble win1y;
		GLdouble win1z;

		GLdouble win2x;
		GLdouble win2y;
		GLdouble win2z;

		GLdouble obj1x = lnJoiningLine.a.x;
		GLdouble obj1y = lnJoiningLine.a.y;
		GLdouble obj1z = lnJoiningLine.a.z;

		GLdouble obj2x = lnJoiningLine.b.x;
		GLdouble obj2y = lnJoiningLine.b.y;
		GLdouble obj2z = lnJoiningLine.b.z;

		gluProject(obj1x, obj1y, obj1z, modelMatrix, projMatrix, viewport, &win1x, &win1y, &win1z);
		gluProject(obj2x, obj2y, obj2z, modelMatrix, projMatrix, viewport, &win2x, &win2y, &win2z);

		mlVector3D vScreenTween = mlVector3D(win1x,win1y,win1z) - mlVector3D(win2x,win2y,win2z);
		mlFloat fPixels = vScreenTween.Magnitude();

		mlFloat fMaxLinePixels = 5.0f;

		//mlFloat fMaxLinePixels = 10.0f; // Even this is a bit much...
		//mlFloat fMaxLinePixels = 20.0f;

		//if(lnJoiningLine.Length() < 0.1f && line.IsOnLine(lnJoiningLine.b))
		//if(lnJoiningLine.Length() < 0.5f && line.IsOnLine(lnJoiningLine.b))
		if(fPixels < fMaxLinePixels && line.ProjectionIsOnLine(lnJoiningLine.b))
		{
			intersectionResultSet.intersectionResults.push_back(gxIntersectionResult(utIntersectionResult(0.0f, lnJoiningLine.b)));
		}
	}
}
예제 #19
0
// Author: Greg Santucci, 2008 and 2009
// Email: [email protected]
// Web: http://createuniverses.blogspot.com/

#include "ML_Matrix.h"

#include "ML_Maths.h"
#include "ML_Quaternion.h"

extern const mlMatrix3x3	mlMatrix3x3Identity
(
	mlVector3D(1.0f, 0.0f, 0.0f),
	mlVector3D(0.0f, 1.0f, 0.0f),
	mlVector3D(0.0f, 0.0f, 1.0f)
);

extern const mlMatrix3x4	mlMatrix3x4Identity
(
	mlVector3D(1.0f, 0.0f, 0.0f),
	mlVector3D(0.0f, 1.0f, 0.0f),
	mlVector3D(0.0f, 0.0f, 1.0f),
	mlVector3D(0.0f, 0.0f, 0.0f)
);

extern const mlMatrix4x4	mlMatrix4x4Identity
(
	mlVector4D(1.0f, 0.0f, 0.0f, 0.0f),
	mlVector4D(0.0f, 1.0f, 0.0f, 0.0f),
	mlVector4D(0.0f, 0.0f, 1.0f, 0.0f),
	mlVector4D(0.0f, 0.0f, 0.0f, 1.0f)
예제 #20
0
World::World()
{
    m_nRenderCount = 0;
    m_nUpdateCount = 0;

    //m_fFieldOfView = 45.0f;
    m_fFieldOfView = 90.0f;

    // m_trnCamera.SetTranslation(mlVector3D(162,66,35));
    // LookAt(mlVector3D(144,60,45));
    m_trnCamera.SetTranslation(mlVector3D(0,10,0));
    LookAt(mlVector3D(0,0,100));

    m_vMouse2DPosition = mlVector3D(300, 300);
    m_vMouse2DPositionDelta = mlVector3D();
    m_vMousePickPosition = mlVector3D();
    m_fMousePickDepth = 0.5f;
    m_vMouseFloorPickPosition = mlVector3D();
    m_fMouseFloorPickDepth = 0.5f;

    m_bLeftMouseDown = false;
    m_bLeftMouseWentDown = false;
    m_bRightMouseDown = false;
    m_bRightMouseWentDown = false;

    m_bMouseMovesCamera = true;
    m_bUsePositionPreservingOrbitCamera = true;
    //m_bUsePositionPreservingOrbitCamera = false;

    m_bUpdatePickPosition = true;
    m_bRenderMousePickSphere = true;
	m_bRenderFloorGrid = true;
    m_bRenderFloorPlane = true;
    m_bRenderProbesHUD = false;

    m_bDoubleClick = false;

    for(int i = 0; i < 4;  i++) viewport[i]    = 0;
    for(int i = 0; i < 16; i++) projMatrix[i]  = 0.0;
    for(int i = 0; i < 16; i++) modelMatrix[i] = 0.0;

    m_nCurrentBuffer = -1;

    //NewEditor();

    m_bRenderOutput = true;
    m_bRenderError = true;
    m_bRenderEditor = true;

    m_bRenderFPS = true;
    m_nFloorGridRed = 255;
    m_nFloorGridGreen = 0;
    m_nFloorGridBlue = 255;

    m_nClearColorRed   = 0;
    m_nClearColorGreen = 0;
    m_nClearColorBlue  = 0;

    m_bRunning = true;

    // MIDI
#ifdef __PRAXIS_LINUX__
    m_midiout = new RtMidiOutAlsa("praxis");
    m_midiin  = new RtMidiInAlsa("praxis");
#endif
#ifdef __PRAXIS_WINDOWS__
    m_midiout = new RtMidiOutWinMM("praxis");
    m_midiin  = 0;
#endif
}
예제 #21
0
void World::Render()
{
    UseMainWindowContext();

    glGetIntegerv(GL_VIEWPORT, viewport);
    int fHeight = viewport[3];
    int fWidth = viewport[2];

    if(m_bRunning)
    {
        if(!luaCall("prerender()", "onerrorgl"))
        {
            m_bRunning = false;
        }

        //ioCall("render()");
    }

    glViewport(0,0,fWidth, fHeight);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // glEnable(GL_CULL_FACE);
    glDisable(GL_CULL_FACE);

    // Turned this off for the Vivo Smart Tab
    // Turn it back on again if needed.
    //glEnable(GL_POLYGON_OFFSET_FILL);
    //glPolygonOffset (1., 1.);

    glClearColor(Int2FloatCol(m_nClearColorRed),
                 Int2FloatCol(m_nClearColorGreen),
                 Int2FloatCol(m_nClearColorBlue),
                 1.0f);
    //glClearColor(0.0f, (float)(rand()%1000) * 0.001f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();

    BuildGLMatrices();

    RenderFloorPlane();
    if(m_bUpdatePickPosition && !m_bDoubleClick)
        RefreshFloorPickPosition();

    glClearColor(Int2FloatCol(m_nClearColorRed),
                 Int2FloatCol(m_nClearColorGreen),
                 Int2FloatCol(m_nClearColorBlue),
                 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // turned off the lighting code for now
    // too much to tune
    // 3d ck didn't have lighting
    // just a simple scheme for coloring the different faces
    // of the object primitives so that they were distinct

    //glEnable(GL_LIGHTING);
    //glEnable(GL_LIGHT0);
    //glEnable(GL_LIGHT1);
    //glEnable(GL_MULTISAMPLE);
    glEnable(GL_COLOR_MATERIAL);

    if(m_bRenderFloorGrid)
        RenderFloorGrid();

    //static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
    //static GLfloat lightPosition1[4] = {  30, 10,  30, 1.0 };
    //static GLfloat lightPosition2[4] = {   0, 20, 400, 1.0 };
    //glLightfv(GL_LIGHT0, GL_POSITION, lightPosition2);
    //glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2);
    // x = 400, y = -300 + i * 60, z = 20
    //glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    glColor4ub(255,255,255,255);

    if(m_bRunning)
    {
        if(!luaCall("render()", "onerrorgl"))
        {
            m_bRunning = false;
        }

        //ioCall("render()");
    }

    // Restore a sane render state in case render left it in a bad condition
    glDisable(GL_STENCIL_TEST);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glColorMask(1,1,1,1);

    // If there is an error, then stop the automatic lua calls.

    UseMainWindowContext();

    glColor4ub(0,255,0,255); // green

    //if(m_bRenderOutput)
    //    DrawText3DStroked(mlVector3D(-50,0,0  ), SelectEndLines(luaGetOutput(),100));

    //if(m_bRenderError)
    //    DrawText3DStroked(mlVector3D(-50,0,200), SelectEndLines(luaGetError(),100));

    if(m_bRenderFloorPlane)
        RenderFloorPlane();

    if(m_bUpdatePickPosition && !m_bDoubleClick)
		RefreshPickPosition();

    if(m_bRenderMousePickSphere)
        RenderMousePickSphere();


    if(m_bRenderProbesHUD)
        RenderProbes();

    if(m_bRunning)
    {
        if(!luaCall("postrender()", "onerrorgl"))
        {
            m_bRunning = false;
        }
    }

    // Restore a sane render state in case postrender left it in a bad condition
    glDisable(GL_STENCIL_TEST);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glColorMask(1,1,1,1);

    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
    glDisable(GL_LIGHT1);
    glDisable(GL_MULTISAMPLE);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    if(m_bRenderEditor)
    {
        // Get rid of this completely.
        qt_save_gl_state();
        GetEditor()->Render();
        qt_restore_gl_state();

        DrawText2D(mlVector3D(5,2), std::string("Buffer: ") + GetEditor()->GetName());
    }

    if(m_bRenderFPS)
    {
#ifdef __PRAXIS_WINDOWS__
        int nCurrentTime = ::timeGetTime();
#endif
#ifdef __PRAXIS_LINUX__
        int nCurrentTime = glutGet(GLUT_ELAPSED_TIME);
#endif
        if(m_nRenderCount % 10 == 0)
        {
            int nTimeDelta = nCurrentTime - g_nLastFrameTime;
            g_nLastFrameTime = nCurrentTime;
            g_fFPS = 1000.0f / (float)nTimeDelta;
            g_fFPS *= 10.0f;
        }

        //qt_save_gl_state();
        //GetEditor()->Render();
        //qt_restore_gl_state();

        // Render a graph
        // A widget
        // A camera aligned widget
        // A widget for the 2D world
        // Just a camera aligned widget will do.

        stringstream ss; ss << std::setprecision(0) << std::fixed << g_fFPS << "fps";
        DrawText2D(mlVector3D(90,95), ss.str());
    }


    // Also, FPS
    // Get current time
    // Compare with previous time
    // Calculate and display FPS
    // ????
    // PROFIT

    if(m_bRenderOutput)
        DrawText2D(mlVector3D(10 + GLEditor::m_nDesiredTextureSize + 10, 35 + GLEditor::m_nDesiredTextureSize - 13),  SelectEndLines(PraxisLog::trace,20), fWidth, fHeight);

    if(m_bRenderError)
        DrawText2D(mlVector3D(10 + GLEditor::m_nDesiredTextureSize + 10, 35 + (GLEditor::m_nDesiredTextureSize / 4)),  SelectEndLines(PraxisLog::error,20), fWidth, fHeight);

    m_nRenderCount++;
}