Beispiel #1
0
void CCamera::Think()
{
	bool bFreeMode = cam_free.GetBool();
	if (bFreeMode != m_bFreeMode)
	{
		m_vecFreeCamera = GetCameraPosition();
		m_angFreeCamera = VectorAngles((GetCameraTarget() - GetCameraPosition()).Normalized());
		m_bFreeMode = bFreeMode;
		CApplication::Get()->SetMouseCursorEnabled(!m_bFreeMode);
	}

	if (m_bFreeMode)
	{
		Vector vecForward, vecRight;
		AngleVectors(m_angFreeCamera, &vecForward, &vecRight, NULL);

		m_vecFreeCamera += vecForward * m_vecFreeVelocity.x * GameServer()->GetFrameTime() * 20;
		m_vecFreeCamera -= vecRight * m_vecFreeVelocity.z * GameServer()->GetFrameTime() * 20;
	}
	else
	{
		if (shrink_frustum.GetBool())
			GameServer()->GetRenderer()->FrustumOverride(GetCameraPosition(), GetCameraTarget(), GetCameraFOV()-1, GetCameraNear()+1, GetCameraFar()-1);
	}
}
Beispiel #2
0
void CCamera::KeyDown(int c)
{
	if (CVar::GetCVarBool("cheats") && c == 'Z')
	{
		cam_free.SetValue(m_bFreeMode?_T("off"):_T("on"));

		if (lock_freemode_frustum.GetBool())
		{
			if (m_bFreeMode)
				GameServer()->GetRenderer()->FrustumOverride(GetCameraPosition(), GetCameraTarget(), GetCameraFOV(), GetCameraNear(), GetCameraFar());
			else
				GameServer()->GetRenderer()->CancelFrustumOverride();
		}
	}

	if (m_bFreeMode)
	{
		if (c == 'W')
			m_vecFreeVelocity.x = 10.0f;
		if (c == 'S')
			m_vecFreeVelocity.x = -10.0f;
		if (c == 'D')
			m_vecFreeVelocity.z = 10.0f;
		if (c == 'A')
			m_vecFreeVelocity.z = -10.0f;
	}
}
Beispiel #3
0
void DisplaySky(GObject *sky, Camera *cam) {

	ShaderProgram *prev_shader;
	RenderState *rs;
	GLboolean prev_cull;
	float x,y,z; // camera position
	static trfm3D localT;

	rs = RenderStateScene();

	glGetBooleanv(GL_CULL_FACE, &prev_cull);

	prev_shader = GetShaderProgramRS(rs);
	SetShaderProgramRS(rs, FindShaderScene("sky"));
	glDisable(GL_CULL_FACE);

	// move skybox to camera origin
	GetCameraPosition(cam, &x, &y, &z);
	SetTransTrfm3D(&localT, x, y, z);
	PushRS(rs, MG_MODELVIEW);
	MultTrfmRS(rs, MG_MODELVIEW, &localT);
	DrawGObject(sky);
	PopRS(rs, MG_MODELVIEW);
	// restore shader
	SetShaderProgramRS(rs, prev_shader);
	if (prev_cull == GL_TRUE)
		glEnable(GL_CULL_FACE);

}
Beispiel #4
0
Avatar *CreateAvatar( char *name, Camera *theCamera, float radius) {

	Avatar  *newAvatar;
	BSphere *newBSphere;
	float x, y, z;

	newAvatar = malloc( sizeof(*newAvatar) * 1 );
	newAvatar->name = strdup(name);
	GetCameraPosition(theCamera, &x, &y, &z);
	newBSphere = CreateBSphere( x, y, z, radius);

	newAvatar->cam          = theCamera;
	newAvatar->bsph         = newBSphere;
	newAvatar->walk         = 0;

	return newAvatar;
}
float *VsSimulationWindow::GetDataPointer(const std::string &strDataType)
{
	float *lpData=NULL;
	std::string strType = Std_CheckString(strDataType);

	GetCameraPosition();

	if(strType == "CAMERAPOSITIONX")
		lpData = &m_fltCameraPosX;
	else if(strType == "CAMERAPOSITIONY")
		lpData = &m_fltCameraPosY;
	else if(strType == "CAMERAPOSITIONZ")
		lpData = &m_fltCameraPosZ;
	else
		THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "StimulusName: " + STR(m_strName) + "  DataType: " + strDataType);

	return lpData;
} 
Beispiel #6
0
Scene :: Scene( Game* const apNewGame, QWidget* apPwgt ) : QGLWidget( apPwgt )
{
    QGLFormat fmt;

    mpGame = apNewGame;
    setMouseTracking( false  );
    for ( int i = 0; i < 4; i++	    )
    {
	mAmbientLight[ i ] = 0.0f;
        mDiffuseLight[ i ] = 0.0f;
	mSpecularLight[ i ] = 0.0f;
    }

    mWidth  = STANDART_SCENE_WIDTH;
    mHeight = STANDART_SCENE_HEIGHT;

    mCameraPosition = SphericalCoor( Geometry :: pi / 4, Geometry :: pi / 8 );
    GetCameraPosition();
    SetViewVectors();

    mRatio              = HEIGHT_RATIO / ( float )WIDTH_RATIO;
    mFrustumAperture    = 45.0f / 180.0f * Geometry :: pi;
    mFrustumNearPlane	= 60;
    mFrustumFarPlane	= 1000;
    mFrustumHalfWidth   = mFrustumNearPlane * tan( mFrustumAperture );
    mFrustumFocalLength = (mFrustumFarPlane + mFrustumNearPlane) * 0.8f;
    mFrustumEyeSep      = mFrustumFocalLength / 30.0f;
    mShowHelp           = true;
    mIsStereo           = false;

    fmt.setStereo( true );
    setFormat( fmt );

    for ( int i = 0; i < RENDER_MESSAGES_CNT; i++ )
        mRenderMessages[ i ] = Game :: EMPTY;

}
void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )
{
	/* FIXME:
	blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
	MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.

	Program received signal SIGABRT, Aborted.
	[Switching to Thread 16384 (LWP 1519)]
	0x40477571 in kill () from /lib/libc.so.6
	(gdb) bt
	#7  0x08334368 in MT_Vector3::normalized() const ()
	#8  0x0833e6ec in RAS_OpenGLRasterizer::applyTransform(RAS_IRasterizer*, double*, int) ()
	*/

	if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
		objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
	{
		// rotate the billboard/halo
		//page 360/361 3D Game Engine Design, David Eberly for a discussion
		// on screen aligned and axis aligned billboards
		// assumed is that the preprocessor transformed all billboard polygons
		// so that their normal points into the positive x direction (1.0, 0.0, 0.0)
		// when new parenting for objects is done, this rotation
		// will be moved into the object

		MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
		MT_Point3 campos = GetCameraPosition();
		MT_Vector3 dir = (campos - objpos).safe_normalized();
		MT_Vector3 up(0,0,1.0);

		KX_GameObject* gameobj = (KX_GameObject*)m_clientobject;
		// get scaling of halo object
		MT_Vector3  size = gameobj->GetSGNode()->GetWorldScaling();

		bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
		if (screenaligned)
		{
			up = (up - up.dot(dir) * dir).safe_normalized();
		} else
		{
			dir = (dir - up.dot(dir)*up).safe_normalized();
		}

		MT_Vector3 left = dir.normalized();
		dir = (up.cross(left)).normalized();

		// we have calculated the row vectors, now we keep
		// local scaling into account:

		left *= size[0];
		dir  *= size[1];
		up   *= size[2];

		double maat[16] = {left[0], left[1], left[2], 0,
		                   dir[0],  dir[1],  dir[2],  0,
		                   up[0],   up[1],   up[2],   0,
		                   0,       0,       0,       1};

		glTranslated(objpos[0],objpos[1],objpos[2]);
		glMultMatrixd(maat);

	}
	else {
		if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
		{
			// shadow must be cast to the ground, physics system needed here!
			MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
			KX_GameObject *gameobj = (KX_GameObject*)m_clientobject;
			MT_Vector3 direction = MT_Vector3(0,0,-1);

			direction.normalize();
			direction *= 100000;

			MT_Point3 topoint = frompoint + direction;

			KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
			PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
			PHY_IPhysicsController* physics_controller = gameobj->GetPhysicsController();

			KX_GameObject *parent = gameobj->GetParent();
			if (!physics_controller && parent)
				physics_controller = parent->GetPhysicsController();
			if (parent)
				parent->Release();

			KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
			if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
			{
				// couldn't find something to cast the shadow on...
				glMultMatrixd(oglmatrix);
			}
			else
			{ // we found the "ground", but the cast matrix doesn't take
			  // scaling in consideration, so we must apply the object scale
				MT_Vector3  size = gameobj->GetSGNode()->GetLocalScale();
				glScalef(size[0], size[1], size[2]);
			}
		} else
		{

			// 'normal' object
			glMultMatrixd(oglmatrix);
		}
	}
}
Beispiel #8
0
void Scene :: paintGL()
{
    Point3Df camera_positon;
    Point3Df camera_directon;
    Point3Df right_vec_to_dir;

    camera_positon     = GetCameraPosition();
    camera_directon    = Geometry :: Normalize( -1.0f * camera_positon );
    camera_positon     = camera_positon + mCameraShift;
    right_vec_to_dir   = Geometry :: VectorMul( camera_directon, Point3Df( 0.0f, 1.0f, 0.0f ) );

    glViewport( 0, 0, mWidth, mHeight );

    if ( mIsStereo )
    {
	right_vec_to_dir    = ( mFrustumEyeSep / 2.0f ) * right_vec_to_dir;


        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();

        mFrustumLeft  = -mRatio * mFrustumHalfWidth - 0.5 * mFrustumEyeSep * mFrustumNearPlane / mFrustumFocalLength;
        mFrustumRight =  mRatio * mFrustumHalfWidth - 0.5 * mFrustumEyeSep * mFrustumNearPlane / mFrustumFocalLength;

        glFrustum(  mFrustumLeft, mFrustumRight,
                   -mFrustumHalfWidth * mRatio, mFrustumHalfWidth * mRatio,
                    mFrustumNearPlane, mFrustumFarPlane );

        glMatrixMode( GL_MODELVIEW );
        glDrawBuffer( GL_BACK_RIGHT );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glLoadIdentity();
        gluLookAt( camera_positon.mX + right_vec_to_dir.mX,
                   camera_positon.mY + right_vec_to_dir.mY,
                   camera_positon.mZ + right_vec_to_dir.mZ,
                   camera_positon.mX + right_vec_to_dir.mX + camera_directon.mX,
                   camera_positon.mY + right_vec_to_dir.mY + camera_directon.mY,
                   camera_positon.mZ + right_vec_to_dir.mZ + camera_directon.mZ,
                   0, 1, 0 );
        mpGame -> DrawWorld();
        glLightfv( GL_LIGHT0, GL_POSITION, mpGame -> GetLightPosition() );


	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	mFrustumLeft  = -mRatio * mFrustumHalfWidth + 0.5 * mFrustumEyeSep * mFrustumNearPlane / mFrustumFocalLength;
	mFrustumRight =  mRatio * mFrustumHalfWidth + 0.5 * mFrustumEyeSep * mFrustumNearPlane / mFrustumFocalLength;

	glFrustum(  mFrustumLeft, mFrustumRight,
                   -mFrustumHalfWidth * mRatio, mFrustumHalfWidth * mRatio,
                    mFrustumNearPlane, mFrustumFarPlane );

	glMatrixMode( GL_MODELVIEW );
	glDrawBuffer( GL_BACK_LEFT );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
	gluLookAt( camera_positon.mX - right_vec_to_dir.mX,
		   camera_positon.mY - right_vec_to_dir.mY,
		   camera_positon.mZ - right_vec_to_dir.mZ,
		   camera_positon.mX - right_vec_to_dir.mX + camera_directon.mX,
		   camera_positon.mY - right_vec_to_dir.mY + camera_directon.mY,
		   camera_positon.mZ - right_vec_to_dir.mZ + camera_directon.mZ,
		   0, 1, 0 );
	mpGame -> DrawWorld();
	glLightfv( GL_LIGHT0, GL_POSITION, mpGame -> GetLightPosition() );
    }
    else
    {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
        glOrtho( -mWidth / 2, mWidth / 2, -mHeight / 2, mHeight / 2, 0, 1000 );
	glMatrixMode( GL_MODELVIEW );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
        gluLookAt( camera_positon.mX, camera_positon.mY, camera_positon.mZ,
		   mCameraShift.mX,   mCameraShift.mY,   mCameraShift.mZ,
		   0, 1, 0 );
	mpGame -> DrawWorld();
	glLightfv( GL_LIGHT0, GL_POSITION, mpGame -> GetLightPosition() );
    }

    DrawTextInformation();

    swapBuffers();
}