Beispiel #1
0
void CBoidObject::UpdateDisplay(SBoidContext &bc)
{
	if(bc.animationMaxDistanceSq ==0)
		return;

	Vec3 cameraPos(gEnv->pRenderer->GetCamera().GetPosition());
	Vec3 cameraDir(gEnv->pRenderer->GetCamera().GetMatrix().GetColumn1());

	float  dot = (m_pos - cameraPos).Dot(cameraDir);

	float distSq = Distance::Point_PointSq(cameraPos,m_pos);

	if(m_displayChr)
	{
		if(dot < 0 || distSq > bc.animationMaxDistanceSq)
		{
			DisplayCharacter(false);
		}
	}
	else
	{
		if(dot > 0 && distSq <= bc.animationMaxDistanceSq)
		{
			// show animated character
			DisplayCharacter(true);
		}
	}

}
/* ----------------------------------------------------------------------
 * Author: Julian
 * Date: 25 March 2014
 * Description: Renders the light manager
 * ----------------------------------------------------------------------
 */
void LightManager::render(const sf::View& camera)
{
	// Set the view of the camera
	sf::Vector2f cameraPos(camera.getCenter() - sf::Vector2f(context.window->getSize() / 2u));
	context.window->setView(camera);

	// Clear the window to see light only
	//context.window->clear(sf::Color::White);

	// Clear the light texture
	lightTexture.clear();

	// Render all the lights
	for(auto&& light : lightList)
		light.render(camera, lightTexture);

	// Render the dusk color over the light texture
	sf::RectangleShape shape(sf::Vector2f(context.window->getSize()));
	shape.setFillColor(duskColor);
	lightTexture.draw(shape);

	// Render the light texture on the rest of the window with BlendMultiply!
	lightTexture.display();
	sf::Sprite sprite(lightTexture.getTexture());
	sprite.setPosition(cameraPos);
	context.window->draw(sprite, sf::BlendMultiply);
}
void TerrainTilesPanel::ScrollToTop()
{
	//Reset zoom to identity
	//float zoom = m_cameraZoom;
	//SetCameraZoom(1.0f);

	//Scroll to top
	float halfCanvas = (m_canvasSize.y * 4.0f);
	float maxY = halfCanvas - ((float)m_panelSize.y / m_cameraZoom);
	ion::Vector3 cameraPos(-(m_panelSize.x / 2.0f / m_cameraZoom), maxY, 0.0f);

	//Re-apply zoom
	//SetCameraZoom(zoom);
}
void TerrainTilesPanel::ResetZoomPan()
{
	const int tileWidth = m_project.GetPlatformConfig().tileWidth;
	const int tileHeight = m_project.GetPlatformConfig().tileHeight;

	m_cameraZoom = (float)m_panelSize.x / (m_canvasSize.x * tileWidth);

	//Scroll to top
	float halfCanvas = (m_canvasSize.y * ((float)tileHeight / 2.0f));
	float maxY = halfCanvas - ((float)m_panelSize.y / m_cameraZoom);
	ion::Vector3 cameraPos(-(m_panelSize.x / 2.0f / m_cameraZoom), maxY, 0.0f);

	m_camera.SetZoom(ion::Vector3(m_cameraZoom, m_cameraZoom, 1.0f));
	m_camera.SetPosition(cameraPos);
}
Beispiel #5
0
void Camera::apply( glm::mat4x4 modelMatrix )
{
	glm::vec3 cameraPos( mPosition.x, mPosition.y, mPosition.z );
	glm::vec4 centerPos( 0.0f, 0.0f, 1.0f, 0.0f );

	glm::mat4 identityMtx( 1.0f );
	centerPos = glm::rotate( identityMtx, mRotation.x, GLM_X_AXIS ) * centerPos;
	centerPos = glm::rotate( identityMtx, mRotation.y, GLM_Y_AXIS ) * centerPos;

	glm::vec3 upVec( 0.0f, 1.0f, 0.0f );

	glm::mat4 viewMtx = glm::lookAt( cameraPos, glm::vec3( centerPos ) + cameraPos, upVec );
	
	applyModelView( modelMatrix, viewMtx );
}
Beispiel #6
0
void LOD::Render(const matrix4x4f &trans, const RenderData *rd)
{
	PROFILE_SCOPED()
	//figure out approximate pixel size of object's bounding radius
	//on screen and pick a child to render
	const vector3f cameraPos(-trans[12], -trans[13], -trans[14]);
	//fov is vertical, so using screen height
	const float pixrad = Graphics::GetScreenHeight() * rd->boundingRadius / (cameraPos.Length() * Graphics::GetFovFactor());
	if (m_pixelSizes.empty()) return;
	unsigned int lod = m_children.size() - 1;
	for (unsigned int i=m_pixelSizes.size(); i > 0; i--) {
		if (pixrad < m_pixelSizes[i-1]) lod = i-1;
	}
	m_children[lod]->Render(trans, rd);
}
Beispiel #7
0
void Camera::applyOrbital( glm::mat4x4 modelMatrix )
{
	glm::vec4 cameraPos( 0.0f, 0.0f, mDistance, 0.0f );

	glm::mat4 identityMtx( 1.0f );
	cameraPos = glm::rotate( identityMtx, mRotation.x, GLM_X_AXIS ) * cameraPos;
	cameraPos = glm::rotate( identityMtx, mRotation.y, GLM_Y_AXIS ) * cameraPos;

	glm::vec3 upVec( 0.0f, 1.0f, 0.0f );
	glm::vec3 center( mPosition.x, mPosition.y, mPosition.z );

	glm::mat4 viewMtx = glm::lookAt( glm::vec3( cameraPos ) + center, center, upVec );

	applyModelView( modelMatrix, viewMtx );
}
Beispiel #8
0
	void Model::beginRender()
	{
		mt::mat4f projection;
		mt::make_projection_fov_m4( projection, m_cameraFOV, m_cameraWidth / m_cameraHeight, 1.f, 1000.f );

		DXCALL m_pDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX *)projection.buff() );

		const Model3DFrame & frame = this->getCurrentFrame();

		mt::mat4f lookAt;

		mt::vec3f cameraPos( frame.cameraPos.x, frame.cameraPos.y, frame.cameraPos.z );
		mt::vec3f cameraDir( -frame.cameraDir.x, -frame.cameraDir.z, -frame.cameraDir.y );
		mt::vec3f cameraUp( -frame.cameraRight.x, -frame.cameraRight.z, -frame.cameraRight.y );

		mt::make_lookat_m4( lookAt, cameraPos, cameraDir, cameraUp, -1.f );

		DXCALL m_pDevice->SetTransform( D3DTS_VIEW, (D3DMATRIX *)lookAt.buff() );

		DXCALL m_pDevice->SetTexture( 0, m_pTexture );

		DXCALL m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	}
Beispiel #9
0
void Window::mvpSetup()
{
	//Setting up MVP matrix
	mat4 model = mat4(1.0f);
	//model = glm::scale(model, vec3(0.5, 0.5f, 0.5f));
	//model = glm::translate(model, vec3(-1.0f, -1.0f, 0.0f));

	mat4 view;
	vec3 cameraPos(0.0f, 0.0f, 1.0f);
	vec3 cameraTarget(0.0f, 0.0f, 0.0f);
	vec3 up(0.0f, 1.0f, 0.0f);
	view = glm::lookAt(cameraPos, cameraTarget, up);

	mat4 projection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
	//mat4 projection = glm::perspective(45.0f, 1.0f, 0.1f, 10.0f);

	mvp = projection * view * model;

	if (hapticsEnabled) {
		haptic.setModelviewMatrix(view * model);
		haptic.setProjectionMatrix(projection);
	}
}
Beispiel #10
0
void WindPointer::onEvent(Actor* initiator, unsigned int eventId, void* eventData)
{
    if( eventId == EVENT_CAMERA_IS_ACTUAL )
    {
        // current wind
        NxVec3 wind = _scene->getWindAtPoint( NxVec3( 0,0,0 ) );

        // make signature worldspace position
        Matrix4f cameraPose = _scene->getCamera()->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        Vector3f pos( wind.x, wind.y, wind.z );
        pos.normalize();
        pos *= 10000.0f;
        pos += cameraPos;

        // update signature window
        Vector3f screenPos = Gameplay::iEngine->getDefaultCamera()->projectPosition( pos );
        if( screenPos[2] > 1 )
        {
            _signature->getPanel()->setVisible( false );
            return;
        }
        else
        {
            _signature->getPanel()->setVisible( true );
            gui::Rect oldRect = _signature->getPanel()->getRect();
            gui::Rect newRect(
                int( screenPos[0] ), int( screenPos[1] ),
                int( screenPos[0] ) + oldRect.getWidth(),
                int( screenPos[1] ) + oldRect.getHeight()
            );
            _signature->getPanel()->setRect( newRect );
            _windSpeed->getStaticText()->setText( wstrformat( Gameplay::iLanguage->getUnicodeString(295), wind.magnitude() ).c_str() );
        }        
    }
}
Beispiel #11
0
bool CameraMan::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
	// update accelerations
	Ogre::Vector3 accel = calculateAccelerations();

	// if accelerating, try to reach top speed in a certain time
	Ogre::Real topSpeed = mFastMove ? mTopSpeed * 2 : mTopSpeed;
	double y_tmp = mVelocity.y;
	if (accel.squaredLength() != 0)
	{
		accel.normalise();
		mVelocity += accel * topSpeed * evt.timeSinceLastFrame * 10;
	}
	// if not accelerating, try to stop in a certain time
	else 
	{
		mVelocity -= mVelocity * evt.timeSinceLastFrame * 10;
	}
	mVelocity.y = y_tmp;

	// vertical movement
	if (mJump) mVelocity.y = jumpSpeed;
	mJump = false;
	mVelocity.y -= gravityAccel * evt.timeSinceLastFrame;

	Ogre::Real tooSmall = std::numeric_limits<Ogre::Real>::epsilon();

	y_tmp = mVelocity.y;
	mVelocity.y = 0;
	// keep camera velocity below top speed and above epsilon
	if (mVelocity.squaredLength() > topSpeed * topSpeed)
	{
		mVelocity.normalise();
		mVelocity *= topSpeed;
	}
	else if (mVelocity.squaredLength() < tooSmall * tooSmall)
	{
		mVelocity = Ogre::Vector3::ZERO;
	}
	mVelocity.y = y_tmp;

	// terrain handling, raycast each unit direction
	PolyVox::RaycastResult resultXH;
	PolyVox::RaycastResult resultXL;
	PolyVox::RaycastResult resultY;
	PolyVox::RaycastResult resultZH;
	PolyVox::RaycastResult resultZL;

	double width = 0.5;
	PolyVox::Vector3DFloat cameraPos( mCamera->getPosition().x, mCamera->getPosition().y,						mCamera->getPosition().z );
	PolyVox::Vector3DFloat cameraPosH( mCamera->getPosition().x, mCamera->getPosition().y + width,				mCamera->getPosition().z );
	PolyVox::Vector3DFloat cameraPosL( mCamera->getPosition().x, mCamera->getPosition().y - charHeight + width,	mCamera->getPosition().z );

	if( mVelocity.x > 0 )
	{
		mTerrain->raycast( cameraPosH, PolyVox::Vector3DFloat( width, 0, 0), resultXH);
		mTerrain->raycast( cameraPosL, PolyVox::Vector3DFloat( width, 0, 0), resultXL);
	}
	else if( mVelocity.x < 0 )
	{
		mTerrain->raycast( cameraPosH, PolyVox::Vector3DFloat(-width, 0, 0), resultXH);
		mTerrain->raycast( cameraPosL, PolyVox::Vector3DFloat(-width, 0, 0), resultXL);
	}
	else
	{
		resultXH.foundIntersection = false;
		resultXL.foundIntersection = false;
	}

	if( mVelocity.y > 0 )
	{
		mTerrain->raycast( cameraPosH, PolyVox::Vector3DFloat( 0, width, 0), resultY);
	}
	else if( mVelocity.y < 0 )
	{
		mTerrain->raycast( cameraPosL, PolyVox::Vector3DFloat( 0,-width, 0), resultY);
	}
	else
	{
		resultY.foundIntersection = false;
	}

	if( mVelocity.z > 0 )
	{
		mTerrain->raycast( cameraPosH, PolyVox::Vector3DFloat( 0, 0, width), resultZH);
		mTerrain->raycast( cameraPosL, PolyVox::Vector3DFloat( 0, 0, width), resultZL);
	}
	else if( mVelocity.z < 0 )
	{
		mTerrain->raycast( cameraPosH, PolyVox::Vector3DFloat( 0, 0,-width), resultZH);
		mTerrain->raycast( cameraPosL, PolyVox::Vector3DFloat( 0, 0,-width), resultZL);
	}
	else
	{
		resultZH.foundIntersection = false;
		resultZL.foundIntersection = false;
	}

	Ogre::Vector3 camPos( mCamera->getPosition() );
	// handle horizontal movement
	if( resultXH.foundIntersection || resultXL.foundIntersection )
	{
		mVelocity.x = 0;
		
		if( resultXH.foundIntersection )
		{
			camPos.x = resultXH.previousVoxel.getX();
		}
		else
		{
			camPos.x = resultXL.previousVoxel.getX();
		}
	}
	if( resultZH.foundIntersection || resultZL.foundIntersection )
	{
		mVelocity.z = 0;

		if( resultZH.foundIntersection )
		{
			camPos.z = resultZH.previousVoxel.getZ();
		}
		else
		{
			camPos.z = resultZL.previousVoxel.getZ();
		}
	}

	// handle ground/ceiling
	if( resultY.foundIntersection )
	{
		camPos.y = resultY.previousVoxel.getY();
		if( mVelocity.y < 0 )
		{
			camPos.y += charHeight - 1.0;
		}

		mVelocity.y = 0;
	}
	else
	{
		if( mVelocity.y < -fallSpeedMax )
		{
			mVelocity.y = -fallSpeedMax;
		}
	}

	// set new position, not in a voxel
	mCamera->setPosition( camPos );

	if (mVelocity != Ogre::Vector3::ZERO) mCamera->move(mVelocity * evt.timeSinceLastFrame);

	return true;
}
void Spectator::onUpdateActivity(float dt)
{
    // spectator can become inactive when he is relaxing
    if( _active && _wish == wishRelax && _scene->getCamera() )
    {
        Matrix4f cameraPose = _scene->getCamera()->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        float distance = ( cameraPos - _clump->getFrame()->getPos() ).length();
        if( distance > activeRadius && _action->getActionTime() > _action->getBlendTime() )
        {
            _active = false;
        }
    }
    if( !_active && _scene->getCamera() )
    {
        Matrix4f cameraPose = _scene->getCamera()->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        float distance = ( cameraPos - _clump->getFrame()->getPos() ).length();
        if( distance < activeRadius ) _active = true;
    }

    if( !_active ) return;

    // fulfill wish
    switch( _wish )
    {
    case wishRelax: {
        // setup corresponding action
        if( !actionIs(Idle) || 
            _clump->getAnimationController()->getTrackAnimation(0) != &idleSequence )
        {
            delete _action;
            _action = new Character::Idle( _clump, &idleSequence, 0.2f, 1.0f );
        }
        // decrease relax time
        _relaxTime -= dt;
        if( _relaxTime < 0 ) _endOfWish = true;
        } break;
    case wishGoto: {
        // obtain distance vector to desired position
        Vector3f distance = _gotoPos - _clump->getFrame()->getPos();
        if( distance.length() > _gotoError )
        {
            // if i am did not moves yet
            if( !actionIs(Move) )
            {
                // obtain angle to desired pos
                Vector3f direction = distance;
                direction[1] = 0.0f;
                direction.normalize();
                float angle = calcAngle( direction, _clump->getFrame()->getAt(), Vector3f( 0,1,0 ) );
                // if angle too large, i will turns
                if( fabs( angle ) > 5.0f )
                {
                    if( !actionIs(Turn) )
                    {
                        delete _action;
                        _action = new Turn( _clump, direction );
                    }
                }
                // else i will move
                else if( !actionIs(Move) )
                {
                    delete _action;
                    _action = new Move( _clump, _enclosure, _gotoPos, false );
                }
            }
            // if wish is undesirable, reject it
            else if( _action->isEndOfAction() )
            {
                _endOfWish = true;
            }
        }
        else
        {
            _endOfWish = true;
        }
        } break;
    case wishWatch: {
        // simulate delay due to character orientation
        _watchDelay -= dt;
        if( _watchDelay > 0 ) break;
        // obtain distance vector to desired position
        Vector3f distance = _watchPos - _clump->getFrame()->getPos();
        // obtain angle to desired pos
        Vector3f direction = distance;
        direction[1] = 0.0f;
        direction.normalize();
        float angle = calcAngle( direction, _clump->getFrame()->getAt(), Vector3f( 0,1,0 ) );
        // if angle too large, i will turns
        if( fabs( angle ) > 5.0f )
        {
            if( !actionIs(Turn) )
            {
                delete _action;
                _action = new Turn( _clump, direction );
            }
        }
        else
        {
            if( !actionIs(Idle) ||
                _clump->getAnimationController()->getTrackAnimation( 0 ) != &watchSequence )
            {
                delete _action;
                _action = new Character::Idle( _clump, &watchSequence, 0.2f, 1.0f );
            }
        }
        // decrease watch time
        _watchTime -= dt;
        if( _watchTime <= 0 ) _endOfWish = true;
        } break;
    }

    // end of wish?
    if( _endOfWish )
    {
        // complete previous wish
        if( _wish == wishGoto )
        {
            Crowd* crowd = dynamic_cast<Crowd*>( _parent ); assert( crowd );
            crowd->endWalk();
        }

        // choose new wish
        if( _wish != wishRelax )
        {
            _wish = wishRelax;
            _relaxTime = getCore()->getRandToolkit()->getUniform( wishRelaxTimeMin ,wishRelaxTimeMax );
        }
        else
        {
            // request for a walk
            Crowd* crowd = dynamic_cast<Crowd*>( _parent ); assert( crowd );
            if( crowd->beginWalk() )
            {
                _wish = wishGoto;
                _gotoPos = _enclosure->place();
                _gotoError = 100.0f;
            }
            else
            {
                _wish = wishRelax;
                _relaxTime = getCore()->getRandToolkit()->getUniform( wishRelaxTimeMin ,wishRelaxTimeMax );
            }
        }
        _endOfWish = false;
    }

    // inherited behaviour
    Character::onUpdateActivity( dt );
}
Beispiel #13
0
	bool Run()
	{
		int result = ::DxLib::SetGraphMode(
			static_cast<int>(m_width),
			static_cast<int>(m_height),
			32);

		::DxLib::ChangeWindowMode(TRUE);	// ウインドウモードに変更
		if (::DxLib::DxLib_Init() == -1)
		{
			MessageBox(nullptr, "Initializing error", "Error!", MB_ICONERROR | MB_TASKMODAL | MB_TOPMOST);
			return false;
		}


		// 描画先画面を裏画面にセット
		SetDrawScreen(DX_SCREEN_BACK);


		float nearZ = 1.f, farZ = 100.f;

		SetCameraNearFar(nearZ, farZ);

		VECTOR3 cameraPos(0.f, 0.5f, -10.f);
		VECTOR3 targetPos(0.f, 0.f, 0.f);

		DxLib::SetCameraPositionAndTarget_UpVecY(cameraPos, targetPos);

		Cube cube(1.f);
		int keys[] = { KEY_INPUT_UP, KEY_INPUT_DOWN, KEY_INPUT_LEFT, KEY_INPUT_RIGHT };
		float val[] = { +0.1f, -0.1f, -0.1f, +0.1f };
		float* pos[][2] = { 
			{ &cameraPos.y, &targetPos.y },
			{ &cameraPos.y, &targetPos.y },
			{ &cameraPos.x, &targetPos.x },
			{ &cameraPos.x, &targetPos.x },
		};
		while (_LoopProc() && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
		{
			const std::vector<Face>& faces = cube.GetFaces();
			for (const Face& face : faces)
			{
				int vertexNum = static_cast<int>(face.GetVertexNum());
				
				for (int i = 0; i < vertexNum - 1; ++i)
				{
					int j = (i + 1) % vertexNum;

					// 頂点の取得
					VECTOR4 from(face.GetVertexAt(i));
					VECTOR4 to(face.GetVertexAt(j));

					VECTOR3 from3d(from);
					VECTOR3 to3d(to);


					//------------------------------
					// 座標変換
					//------------------------------
					float dist = targetPos.z - cameraPos.z;
										
					MATRIX matT;
					CreateTranslationMatrix(matT, from.x, from.y, from.z);

					MATRIX matP;
					CreatePerspectiveLH(matP, m_width, m_height, nearZ, farZ);

					MATRIX mat;
					MultiplyMatrix(mat, matT, matP);
					
					Vector4Transform(from, from, mat);
					
					CreateTranslationMatrix(matT, to.x, to.y, to.z);
					MultiplyMatrix(mat, matT, matP);

					Vector4Transform(to, to, mat);

					/*
					D3DXMATRIX * D3DXMatrixPerspectiveLH(
						D3DXMATRIX * pOut,
						FLOAT w,	近くのビュー プレーンでのビュー ボリュームの幅
						FLOAT h,	近くのビュー プレーンでのビュー ボリュームの高さ
						FLOAT zn,	近くのビュー プレーンの z 値
						FLOAT zf	遠くのビュー プレーンの z 値
					);

					 2*zn/w  0       0              0 
					 0       2*zn/h  0              0 
					 0       0       zf/(zf-zn)     1 
					 0       0       zn*zf/(zn-zf)  0


					 D3DXMATRIX * D3DXMatrixPerspectiveRH(
						 D3DXMATRIX * pOut,
						 FLOAT w,	 FLOAT h,
						 FLOAT zn,	 FLOAT zf);
					 2*zn/w  0       0              0
					 0       2*zn/h  0              0
					 0       0       zf/(zn-zf)    -1
					 0       0       zn*zf/(zn-zf)  0
					*/
					
					
					/*
					D3DXMATRIX* D3DXMatrixPerspectiveFovLH(
						D3DXMATRIX * pOut,
						FLOAT fovy,		y 方向の視野角 (ラジアン単位)
						FLOAT Aspect,	アスペクト比 (ビュー空間の幅を高さで除算して定義(width/height))
						FLOAT zn,		近くのビュー プレーンの z 値
						FLOAT zf		遠くのビュー プレーンの z 値
					);
					where: 
					yScale = cot(fovY/2)
					xScale = yScale / aspect ratio

					xScale     0          0               0
					0        yScale       0               0
					0          0       zf/(zf-zn)         1
					0          0       -zn*zf/(zf-zn)     0
					
					D3DXMATRIX * D3DXMatrixPerspectiveFovRH(
						  D3DXMATRIX * pOut,
						  FLOAT fovy, FLOAT Aspect,
						  FLOAT zn,	  FLOAT zf);
					xScale     0          0              0
					0        yScale       0              0
					0        0        zf/(zn-zf)        -1
					0        0        zn*zf/(zn-zf)      0
					
					*/

					/*
					D3DXMATRIX * D3DXMatrixLookAtLH(
						D3DXMATRIX * pOut,			処理の結果を表す D3DXMATRIX 構造体へのポインター
						CONST D3DXVECTOR3 * pEye,	視点を定義する D3DXVECTOR3 構造体へのポインターです。この値は変換に使用されます。
						CONST D3DXVECTOR3 * pAt,	カメラの注視対象を定義する D3DXVECTOR3 構造体へのポインターです。
						CONST D3DXVECTOR3 * pUp		現在のワールド座標における上方向を定義する D3DXVECTOR3 構造体へのポインター。この構造体の値は通常 [0, 1, 0] です。
					);

					zaxis = normal(At - Eye)
					xaxis = normal(cross(Up, zaxis))
					yaxis = cross(zaxis, xaxis)
					xaxis.x           yaxis.x           zaxis.x          0
					xaxis.y           yaxis.y           zaxis.y          0
					xaxis.z           yaxis.z           zaxis.z          0
					-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  l

					D3DXMATRIX * D3DXMatrixLookAtRH(
						D3DXMATRIX * pOut,
						CONST D3DXVECTOR3 * pEye,
						CONST D3DXVECTOR3 * pAt,
						CONST D3DXVECTOR3 * pUp
					);
					zaxis = normal(Eye - At)
					xaxis = normal(cross(Up, zaxis))
					yaxis = cross(zaxis, xaxis)
					xaxis.x           yaxis.x           zaxis.x          0
					xaxis.y           yaxis.y           zaxis.y          0
					xaxis.z           yaxis.z           zaxis.z          0
					-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  l

					*/


					
					
					//------------------------------
					// 描画
					DxLib::DrawLine(from.x, from.y,
									to.x, to.y,
									GetColor(250, 0, 0));

					printf("from(%.1f, %.1f, %.1f) ", from.x, from.y, from.z);
					printf("to(%.1f, %.1f, %.1f)\n", to.x, to.y, to.z);

					DxLib::DrawLine3D(from3d, to3d, -1);
				}

			}

			{
				int i = 0;
				for (int key : keys)
				{
					if (CheckHitKey(key) != 0)
					{
						*pos[i][0] += val[i];
						*pos[i][1] += val[i];
					}
					++i;
				}
				DxLib::SetCameraPositionAndTarget_UpVecY(cameraPos, targetPos);
				DrawExtendFormatString(0, 0, 0.75, 0.75, -1, "camera(%.1f, %.1f, %.1f) target(%.1f, %.1f, %.1f)", cameraPos.x, cameraPos.y, cameraPos.z, targetPos.x, targetPos.y, targetPos.z);
			}
		}


		return true;
	}
void ParticleRenderSystem::processEntities( const vector<Entity*>& p_entities )
{
    ClientStateSystem* stateSystem = static_cast<ClientStateSystem*>(m_world->getSystem(SystemType::ClientStateSystem));

    /*
    if (stateSystem->getCurrentState() == GameStates::INGAME)
    {
    	timeInGame += m_world->getDelta();
    	if (timeInGame < 2.0f)
    		return;
    }
    */

    clearRenderQues();
    drawnPS = 0;
    calcCameraPlanes();

    // get camera pos, for sorting
    AglVector3 cameraPos( 0.0f, 0.0f, 0.0f );
    auto entitymanager = m_world->getEntityManager();
    Entity* cam = entitymanager->getFirstEntityByComponentType(ComponentType::TAG_MainCamera);
    if (cam)
    {
        Transform* camTransform = static_cast<Transform*>(
                                      cam->getComponent( ComponentType::Transform ) );
        if (camTransform) cameraPos = camTransform->getTranslation();
    }


    // all particle systems
    for( unsigned int i = 0; i<p_entities.size(); i++ )
    {
        Transform* transform = static_cast<Transform*>(
                                   p_entities[i]->getComponent( ComponentType::Transform ) );

        MeshOffsetTransform* offset = static_cast<MeshOffsetTransform*>(
                                          p_entities[i]->getComponent( ComponentType::MeshOffsetTransform ) );

        ParticleSystemsComponent* particlesComp = static_cast<ParticleSystemsComponent*>(
                    p_entities[i]->getComponent( ComponentType::ParticleSystemsComponent ) );



        if( particlesComp->getParticleSystemCnt() > 0 )
        {
            for( unsigned int i=0; i<particlesComp->getParticleSystemsPtr()->size(); i++ )
            {
                ParticleSystemAndTexture* psAndTex = particlesComp->getParticleSystemAndTexturePtr(i);
                if( psAndTex != NULL )
                {
                    if (shouldRender(psAndTex))
                    {
                        drawnPS++;
                        AglParticleSystemHeader header = psAndTex->particleSystem.getHeader();

                        AglMatrix transMat = transform->getMatrix();

                        Transform* newTrans = new Transform(transform->getMatrix());


                        // Offset Agl-loaded meshes by their offset matrix
                        if( offset != NULL ) {
                            transMat = offset->offset.inverse() * transMat;
                        }
                        newTrans->setMatrix(transMat);

                        if( header.spawnSpace == AglParticleSystemHeader::AglSpace_LOCAL &&
                                header.particleSpace == AglParticleSystemHeader::AglSpace_GLOBAL)
                        {
                            particlesComp->setSpawn( transMat, i );
                        }

                        PsRenderInfo info( psAndTex, newTrans->getInstanceVertex());
                        insertToRenderQue( info );
                        delete newTrans;
                    }
                }
            }
        }
        particlesComp->updateParticleSystems( m_world->getDelta(), cameraPos);

    }
    if (drawnPS > maxDrawnPS)
        maxDrawnPS = drawnPS;
}
Beispiel #15
0
void Mission::FollowCamera::onUpdateActivity(float dt)
{
        assert( _scene );
        _cameraFOV = 80.0f;

        _positionModeTimeout -= dt;
        _positionModeTimeout = _positionModeTimeout < 0 ? 0 : _positionModeTimeout;

        // retrieve action channels
        ActionChannel* headLeft  = Gameplay::iGameplay->getActionChannel( iaHeadLeft );
        ActionChannel* headRight = Gameplay::iGameplay->getActionChannel( iaHeadRight );
        ActionChannel* headUp    = Gameplay::iGameplay->getActionChannel( iaHeadUp );
        ActionChannel* headDown  = Gameplay::iGameplay->getActionChannel( iaHeadDown );
        ActionChannel* zoomIn    = Gameplay::iGameplay->getActionChannel( iaZoomIn );
        ActionChannel* zoomOut   = Gameplay::iGameplay->getActionChannel( iaZoomOut );    

        switch (_mode) {
        case FeetLeft: 
                {
                        // target position
                        Matrix4f targetPose( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 );
                        if( _target ) targetPose = _target->getPose();

                        Vector3f targetPos( targetPose[3][0], targetPose[3][1], targetPose[3][2] );
                        Vector3f targetUp( targetPose[1][0], targetPose[1][1], targetPose[1][2] );
                        Vector3f targetRight( targetPose[0][0], targetPose[0][1], targetPose[0][2] );
                        Vector3f targetFront( targetPose[2][0], targetPose[2][1], targetPose[2][2] );
                        targetUp.normalize();
                        targetRight.normalize();
                        targetFront.normalize();

                        Vector3f cameraPos(targetPos);

                        if( dynamic_cast<Jumper*>( _target ) )
                        {
                                Jumper* j = dynamic_cast<Jumper*>( _target );
                                j->getClump()->getFrame()->getLTM();
                                engine::IFrame* backBone = Jumper::getBackBone( j->getClump() );
                                targetPos = backBone->getPos();

                                engine::IFrame* legBone = Jumper::getLeftSmokeJetAnchor(j->getClump());
                                cameraPos = legBone->getPos();
                                cameraPos += legBone->getAt() * 0.0f; // right
                                cameraPos += legBone->getUp() * -10.0f; // up
                                cameraPos += legBone->getRight() * -20.0f; // forward
                                targetPos = cameraPos;
                                targetPos += legBone->getAt() * -25.0f; // right
                                targetPos += legBone->getRight() * 40.0f; // forward
                                targetPos += legBone->getUp() * -25.0f; // up
                                targetUp = legBone->getUp() * -8.0f + legBone->getAt() * -2.0f;
                                targetUp.normalize();
                        }

                        //cameraPos += targetUp * 45.0f - targetRight * 40.0f - targetFront * 100.0f;

                        // camera direction
                        Vector3f cameraAt = cameraPos - targetPos/* + targetFront * 50.0f*/;
                        cameraAt.normalize();        

                        // camera right
                        Vector3f cameraRight; 
                        cameraRight.cross( targetUp, cameraAt );
                        cameraRight.normalize();

                        // camera up
                        Vector3f cameraUp;
                        cameraUp.cross( cameraAt, cameraRight );
                        cameraUp.normalize();

                        // camera matrix
                        _cameraMatrix.set( 
                                cameraRight[0], cameraRight[1], cameraRight[2], 0.0f,
                                cameraUp[0], cameraUp[1], cameraUp[2], 0.0f,
                                cameraAt[0], cameraAt[1], cameraAt[2], 0.0f,
                                cameraPos[0], cameraPos[1], cameraPos[2], 1.0f
                                );

                        break;
                }
        case FeetRight:
                {
                        // target position
                        Matrix4f targetPose( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 );
                        if( _target ) targetPose = _target->getPose();

                        Vector3f targetPos( targetPose[3][0], targetPose[3][1], targetPose[3][2] );
                        Vector3f targetUp( targetPose[1][0], targetPose[1][1], targetPose[1][2] );
                        Vector3f targetRight( targetPose[0][0], targetPose[0][1], targetPose[0][2] );
                        Vector3f targetFront( targetPose[2][0], targetPose[2][1], targetPose[2][2] );
                        targetUp.normalize();
                        targetRight.normalize();
                        targetFront.normalize();

                        Vector3f cameraPos(targetPos);

                        if( dynamic_cast<Jumper*>( _target ) )
                        {
                                Jumper* j = dynamic_cast<Jumper*>( _target );
                                j->getClump()->getFrame()->getLTM();
                                engine::IFrame* backBone = Jumper::getBackBone( j->getClump() );
                                targetPos = backBone->getPos();

                                engine::IFrame* legBone = Jumper::getRightSmokeJetAnchor(j->getClump());
                                cameraPos = legBone->getPos();
                                cameraPos += legBone->getAt() * 0.0f; // right
                                cameraPos += legBone->getUp() * -12.0f; // up
                                cameraPos += legBone->getRight() * -20.0f; // forward
                                targetPos = cameraPos;
                                targetPos += legBone->getAt() * -25.0f; // right
                                targetPos += legBone->getRight() * 40.0f; // forward
                                targetPos += legBone->getUp() * -25.0f; // up
                                targetUp = legBone->getUp() * -8.0f + legBone->getAt() * -2.0f;
                                targetUp.normalize();
                        }

                        //cameraPos += targetUp * 45.0f - targetRight * 40.0f - targetFront * 100.0f;

                        // camera direction
                        Vector3f cameraAt = cameraPos - targetPos/* + targetFront * 50.0f*/;
                        cameraAt.normalize();        

                        // camera right
                        Vector3f cameraRight; 
                        cameraRight.cross( targetUp, cameraAt );
                        cameraRight.normalize();

                        // camera up
                        Vector3f cameraUp;
                        cameraUp.cross( cameraAt, cameraRight );
                        cameraUp.normalize();

                        // camera matrix
                        _cameraMatrix.set( 
                                cameraRight[0], cameraRight[1], cameraRight[2], 0.0f,
                                cameraUp[0], cameraUp[1], cameraUp[2], 0.0f,
                                cameraAt[0], cameraAt[1], cameraAt[2], 0.0f,
                                cameraPos[0], cameraPos[1], cameraPos[2], 1.0f
                                );

                        break;
                }
        case Back:
                {
                        // target position
                        Matrix4f targetPose( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 );
                        if( _target ) targetPose = _target->getPose();

                        Vector3f targetPos( targetPose[3][0], targetPose[3][1], targetPose[3][2] );
                        Vector3f targetUp( targetPose[1][0], targetPose[1][1], targetPose[1][2] );
                        Vector3f targetRight( targetPose[0][0], targetPose[0][1], targetPose[0][2] );
                        Vector3f targetFront( targetPose[2][0], targetPose[2][1], targetPose[2][2] );
                        targetUp.normalize();
                        targetRight.normalize();
                        targetFront.normalize();

                        Vector3f cameraPos(targetPos);

                        if( dynamic_cast<Jumper*>( _target ) )
                        {
                                Jumper* j = dynamic_cast<Jumper*>( _target );
                                j->getClump()->getFrame()->getLTM();
                                engine::IFrame* backBone = Jumper::getBackBone( j->getClump() );
                                targetPos = backBone->getPos();

                                engine::IFrame* head = Jumper::getHelmetEquipAnchor(j->getClump());
                                cameraPos = head->getPos();
                                cameraPos += head->getAt() * -28.0f; // down
                                cameraPos += head->getRight() * 0.0f; // left
                                cameraPos += head->getUp() * -1.0f; // forward
                                targetPos = cameraPos;
                                targetPos += head->getAt() * -10.0f; // down
                                targetPos += head->getRight() * 0.0f; // left
                                targetPos += head->getUp() * -10.0f; // forward
                                targetUp = head->getAt() * -1.0f;
                                targetUp.normalize();
                        }

                        //cameraPos += targetUp * 45.0f - targetRight * 40.0f - targetFront * 100.0f;

                        // camera direction
                        Vector3f cameraAt = cameraPos - targetPos/* + targetFront * 50.0f*/;
                        cameraAt.normalize();        

                        // camera right
                        Vector3f cameraRight; 
                        cameraRight.cross( targetUp, cameraAt );
                        cameraRight.normalize();

                        // camera up
                        Vector3f cameraUp;
                        cameraUp.cross( cameraAt, cameraRight );
                        cameraUp.normalize();

                        // camera matrix
                        _cameraMatrix.set( 
                                cameraRight[0], cameraRight[1], cameraRight[2], 0.0f,
                                cameraUp[0], cameraUp[1], cameraUp[2], 0.0f,
                                cameraAt[0], cameraAt[1], cameraAt[2], 0.0f,
                                cameraPos[0], cameraPos[1], cameraPos[2], 1.0f
                                );

                        break;
                }
        }

        // camera is actual now
        Gameplay::iEngine->getDefaultCamera()->setFOV( _cameraFOV );
        Gameplay::iEngine->getDefaultCamera()->getFrame()->setMatrix( _cameraMatrix );
        _scene->getScenery()->happen( this, EVENT_CAMERA_IS_ACTUAL );
        if( _scene->getTopMode() ) _scene->getTopMode()->happen( this, EVENT_CAMERA_IS_ACTUAL );

        // RT-RS pass
        bool flares = ( _scene->getLocation()->getWeather() == ::wtSunny ) || ( _scene->getLocation()->getWeather() == ::wtVariable );
        Gameplay::iGameplay->getRenderTarget()->render( _scene, _cameraMatrix, _cameraFOV, flares, false );
        // GUI
        Gameplay::iEngine->getDefaultCamera()->beginScene( 0, Vector4f( 0,0,0,0 ) );    
        if( _scene->isHUDEnabled() ) Gameplay::iGui->render();
        Gameplay::iEngine->getDefaultCamera()->endScene();
        // present result
        Gameplay::iEngine->present();

}
Beispiel #16
0
/*
	Since this demo can load many different sizes and shapes of 3d model setting the initial
	camera position so the model can be seen is a tricky task. This function uses the model's bounding sphere
	to come up with an initial position for the camera.
*/
D3DXVECTOR3 CXFileEntity::GetInitialCameraPosition() const
{
	D3DXVECTOR3 cameraPos(0.0f,m_sphereCentre.y,-(m_sphereRadius*3));
	return cameraPos;
}
Beispiel #17
0
void Scene::updateActivity(float dt)
{
    if( !_isLoaded )
    {
        load();
        _isLoaded = true;
        return;
    }

    // tune scene reverberation
#ifdef GAMEPLAY_DEVELOPER_EDITION
    if( _reverberation )
    {
        bool _isChanged = false;
        // F4 = decrease inGain
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x3E] & 0x80 )
        {
            _reverberation->inGain -= 0.01f;
            _isChanged = true;
        }
        // F5 = increate inGain
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x3F] & 0x80 )
        {
            _reverberation->inGain += 0.01f;
            _isChanged = true;
        }
        // F6 = decrease reverbMixDB
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x40] & 0x80 )
        {
            _reverberation->reverbMixDB -= 0.001f;
            _isChanged = true;
        }
        // F7 = increate reverbMixDB
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x41] & 0x80 )
        {
            _reverberation->reverbMixDB += 0.001f;
            _isChanged = true;
        }
        // F8 = decrease reverbTime
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x42] & 0x80 )
        {
            _reverberation->reverbTime -= 0.01f;
            _isChanged = true;
        }
        // F9 = increase reverbTime
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x43] & 0x80 )
        {
            _reverberation->reverbTime += 0.01f;
            _isChanged = true;
        }
        // F10 = decrease hfTimeRatio
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x44] & 0x80 )
        {
            _reverberation->hfTimeRatio -= 0.001f;
            _isChanged = true;
        }
        // F11 = increase hfTimeRatio
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x57] & 0x80 )
        {
            _reverberation->hfTimeRatio += 0.001f;
            _isChanged = true;
        }
        if( _isChanged )
        {
            getScenery()->happen( getScenery(), EVENT_SCENE_REVERBERATION_IS_CHANGED, NULL );
            if( _modes.size() ) getTopMode()->happen( getTopMode(), EVENT_SCENE_REVERBERATION_IS_CHANGED, NULL );
            getCore()->logMessage(
                "Reverb = { %3.3f, %3.3f, %3.3f, %3.3f }",
                _reverberation->inGain,
                _reverberation->reverbMixDB,
                _reverberation->reverbTime,
                _reverberation->hfTimeRatio
            );
        }
    }
#endif

    // switch HUD
    _switchHUDTimeout -= dt;
    if( Gameplay::iGameplay->getActionChannel( ::iaSwitchHUDMode )->getTrigger() &&
            _switchHUDTimeout < 0 )
    {
        _isHUDEnabled = !_isHUDEnabled;
        _switchHUDTimeout = 0.25f;
    }

    // update playing time
    getCareer()->getVirtues()->statistics.playingTime += dt;

    // time speed effect
    dt *= _timeSpeed * _timeSpeedMultiplier;

    // wind time
    _windTime += dt * getCore()->getRandToolkit()->getUniform( 0.0f, 0.25f ) *
                 getCore()->getRandToolkit()->getUniform( 0.0f, 0.25f );

    // update scenery
    _scenery->updateActivity( dt );

    // remove complete modes
    if( _modes.size() )
    {
        if( _modes.top()->endOfMode() )
        {
            _modes.top()->onSuspend();
            delete _modes.top();
            _modes.pop();
            if( _modes.size() ) _modes.top()->onResume();
        }
    }
    // add mode queries
    if( _modeQuery )
    {
        if( _modes.size() ) _modes.top()->onSuspend();
        _modes.push( _modeQuery );
        _modes.top()->onResume();
        _modeQuery = NULL;
    }

    // update current mode
    //network->stopSending();
    if( _modes.size() )
    {
        _modes.top()->updateActivity( dt );
    }
    //if (!network->arePacketsLocked() && !network->arePacketsSendingLocked()) {
    //	network->beginSending();
    //}

    // update rain
    if( _rain )
    {
        Matrix4f cameraPose = _camera->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        _rain->setProperty( "Center", cameraPos );
        Vector3f vel = Vector3f( 0,-1000,0 ) - wrap( getWindAtPoint( PxVec3( 0,0,0 ) ) );
        _rain->setProperty( "Velocity", vel );
        _rain->setProperty( "NBias", 3.0f );
        _rain->setProperty( "TimeSpeed", _timeSpeed * _timeSpeedMultiplier );
    }

    // update camera
    if( _camera )
    {
        _camera->updateActivity( dt );

        Matrix4f cameraPose = _camera->getPose();
        Vector3f cameraOffset = Vector3f( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] ) -
                                Vector3f( _lastCameraPose[3][0], _lastCameraPose[3][1], _lastCameraPose[3][2] );
        Vector3f cameraVel = cameraOffset;
        float velMagnitude = cameraVel.length();
        velMagnitude = velMagnitude / ( dt > 0 ? dt : 0.001f );
        if( velMagnitude > 5000.0f ) velMagnitude = 5000.0f;
        cameraVel.normalize();
        cameraVel *= velMagnitude;
        Gameplay::iAudio->setListener( cameraPose, cameraVel );
        _lastCameraPose = cameraPose;
    }

    // check player health
    if( _career->getVirtues()->evolution.health < 0.75f && !Gameplay::iGameplay->_freeModeIsEnabled )
    {
#ifdef GAMEPLAY_DEMOVERSION
        // check top mode is not mission and not interrupt mode
        if( dynamic_cast<Mission*>( _modes.top() ) == NULL &&
                dynamic_cast<Interrupt*>( _modes.top() ) == NULL )
        {
            if( _career->getVirtues()->evolution.health > 0 )
            {
                _career->getVirtues()->evolution.health = 1.0f;
            }
            else
            {
                _endOfActivity = true;
            }
        }
#else
        // check top mode is not mission and not interrupt mode
        if( dynamic_cast<Mission*>( _modes.top() ) == NULL &&
                dynamic_cast<Interrupt*>( _modes.top() ) == NULL )
        {
            // force exit to career course
            _endOfActivity = true;
        }
#endif
    }
}
Beispiel #18
0
void MovieRenderer::Imp::prepareForStart()
{
	struct locals {
		static void eraseUncompatibleExistingLevel(const TFilePath &fp, const TDimension &imageSize) // nothrow
		{
			assert(!fp.isEmpty());

			if (TSystem::doesExistFileOrLevel(fp)) {
				bool remove = false;

				// In case the raster specifics are different from those of a currently
				// existing movie, erase it
				try {
					TLevelReaderP lr(fp);
					lr->loadInfo();

					const TImageInfo *info = lr->getImageInfo();
					if (!info || info->m_lx != imageSize.lx || info->m_ly != imageSize.ly)
						TSystem::removeFileOrLevel(fp); // nothrow
				} catch (...) {
					// Same if the level could not be read/opened
					TSystem::removeFileOrLevel(fp); // nothrow
				}

				// NOTE: The level removal procedure could still fail.
				// In this case, no signaling takes place. The level readers will throw
				// when the time to write on the file comes, leading to a render failure.
			}
		}
	};

	TOutputProperties *oprop = m_scene->getProperties()->getOutputProperties();
	double frameRate = (double)oprop->getFrameRate();

	/*-- Frame rate の stretch --*/
	double stretchFactor = oprop->getRenderSettings().m_timeStretchTo / oprop->getRenderSettings().m_timeStretchFrom;
	frameRate *= stretchFactor;

	// Get the shrink
	int shrinkX = m_renderSettings.m_shrinkX, shrinkY = m_renderSettings.m_shrinkY;

	//Build the render area
	TPointD cameraPos(-0.5 * m_frameSize.lx, -0.5 * m_frameSize.ly);
	TDimensionD cameraRes(double(m_frameSize.lx) / shrinkX, double(m_frameSize.ly) / shrinkY);
	TDimension cameraResI(cameraRes.lx, cameraRes.ly);

	TRectD renderArea(cameraPos.x, cameraPos.y, cameraPos.x + cameraRes.lx, cameraPos.y + cameraRes.ly);
	setRenderArea(renderArea);

	if (!m_fp.isEmpty()) {
		try // Construction of a LevelUpdater may throw (well, almost ANY operation on a LevelUpdater
		{   // could throw). But due to backward compatibility this function is assumed to be non-throwing.
			if (!m_renderSettings.m_stereoscopic) {
				locals::eraseUncompatibleExistingLevel(m_fp, cameraResI);

				m_levelUpdaterA.reset(new LevelUpdater(m_fp, oprop->getFileFormatProperties(m_fp.getType())));
				m_levelUpdaterA->getLevelWriter()->setFrameRate(frameRate);
			} else {
				TFilePath leftFp = m_fp.withName(m_fp.getName() + "_l");
				TFilePath rightFp = m_fp.withName(m_fp.getName() + "_r");

				locals::eraseUncompatibleExistingLevel(leftFp, cameraResI);
				locals::eraseUncompatibleExistingLevel(rightFp, cameraResI);

				m_levelUpdaterA.reset(new LevelUpdater(leftFp, oprop->getFileFormatProperties(leftFp.getType())));
				m_levelUpdaterA->getLevelWriter()->setFrameRate(frameRate);

				m_levelUpdaterB.reset(new LevelUpdater(rightFp, oprop->getFileFormatProperties(rightFp.getType())));
				m_levelUpdaterB->getLevelWriter()->setFrameRate(frameRate);
			}
		} catch (...) {
			// If we get here, it's because one of the LevelUpdaters could not be created. So, let's say
			// that if one could not be created, then ALL OF THEM couldn't (ie saving is not possible at all).
			m_levelUpdaterA.reset();
			m_levelUpdaterB.reset();
		}
	}
}
Beispiel #19
0
glm::vec3 TPCamera::checkCollisionWithSquares(glm::vec3 & eye, std::vector<glm::vec2> locations, float halfSideLength)
{
	SquareSides side = none;
	//glm::vec2 cameraPos(eye.x,eye.z);
	//glm::vec2 charaPos(look.x, look.z);
	//glm::vec2 delta(cameraPos - charaPos);
	//glm::vec2 halfCameraPos = charaPos + glm::vec2(delta.x / 2, delta.y / 2);
	//glm::vec2 delta2(halfCameraPos - charaPos);
	//glm::vec2 quarterCameraPos = charaPos + glm::vec2(delta2.x / 2, delta2.y / 2);
	//loop through the locations
	for (std::vector<glm::vec2>::iterator it = locations.begin(); it < locations.end(); it++)
	{
		side = none;
		glm::vec2 cameraPos(eye.x, eye.z);
		glm::vec2 charaPos(look.x, look.z);
		glm::vec2 delta(cameraPos - charaPos);
		glm::vec2 threeQuarterCameraPos = charaPos + glm::vec2(delta.x*3.0 / 4, delta.y*3.0 / 4);
		glm::vec2 halfCameraPos = charaPos + glm::vec2(delta.x / 2, delta.y / 2);
		glm::vec2 quarterCameraPos = charaPos + glm::vec2(delta.x / 4, delta.y / 4);
		//check if camera and square collide
		if (SquareCollisions::intersectPointWithSquare(quarterCameraPos, *it, halfSideLength))
		{
			//find side that camera collides with
			side = SquareCollisions::intersectLineWithSquare(*it, halfSideLength, quarterCameraPos, charaPos);
		}
		else if (SquareCollisions::intersectPointWithSquare(halfCameraPos, *it, halfSideLength))
		{
			//find side that camera collides with
			side = SquareCollisions::intersectLineWithSquare(*it, halfSideLength, halfCameraPos, charaPos);
		}
		else if (SquareCollisions::intersectPointWithSquare(threeQuarterCameraPos, *it, halfSideLength))
		{
			//find side that camera collides with
			side = SquareCollisions::intersectLineWithSquare(*it, halfSideLength, threeQuarterCameraPos, charaPos);
		}
		else if (SquareCollisions::intersectPointWithSquare(cameraPos, *it, halfSideLength))
		{
			//find side that camera collides with
			side = SquareCollisions::intersectLineWithSquare(*it, halfSideLength, cameraPos, charaPos);
		}
		switch (side)
		{
		case top:
			eye.z = it->y + halfSideLength;
			eye.x = solveLineEquation(cameraPos.y, cameraPos.x, charaPos.y, charaPos.x, eye.z);
			break;
		case right:
			eye.x = it->x - halfSideLength;
			eye.z = solveLineEquation(cameraPos.x, cameraPos.y, charaPos.x, charaPos.y, eye.x);
			break;
		case left:
			eye.x = it->x + halfSideLength;
			eye.z = solveLineEquation(cameraPos.x, cameraPos.y, charaPos.x, charaPos.y, eye.x);
			break;
		case bottom:
			eye.z = it->y - halfSideLength;
			eye.x = solveLineEquation(cameraPos.y, cameraPos.x, charaPos.y, charaPos.x, eye.z);
			break;
		}
	}
	return eye;
}