// Update frame-based values.
void D3D12Multithreading::OnUpdate()
{
	m_timer.Tick(NULL);

	PIXSetMarker(m_commandQueue.Get(), 0, L"Getting last completed fence.");

	// Get current GPU progress against submitted workload. Resources still scheduled 
	// for GPU execution cannot be modified or else undefined behavior will result.
	const UINT64 lastCompletedFence = m_fence->GetCompletedValue();

	// Move to the next frame resource.
	m_currentFrameResourceIndex = (m_currentFrameResourceIndex + 1) % FrameCount;
	m_pCurrentFrameResource = m_frameResources[m_currentFrameResourceIndex];

	// Make sure that this frame resource isn't still in use by the GPU.
	// If it is, wait for it to complete.
	if (m_pCurrentFrameResource->m_fenceValue > lastCompletedFence)
	{
		HANDLE eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
		if (eventHandle == nullptr)
		{
			ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
		}
		ThrowIfFailed(m_fence->SetEventOnCompletion(m_pCurrentFrameResource->m_fenceValue, eventHandle));
		WaitForSingleObject(eventHandle, INFINITE);
		CloseHandle(eventHandle);
	}

	m_cpuTimer.Tick(NULL);
	float frameTime = static_cast<float>(m_timer.GetElapsedSeconds());
	float frameChange = 2.0f * frameTime;

	if (m_keyboardInput.leftArrowPressed)
		m_camera.RotateYaw(-frameChange);
	if (m_keyboardInput.rightArrowPressed)
		m_camera.RotateYaw(frameChange);
	if (m_keyboardInput.upArrowPressed)
		m_camera.RotatePitch(frameChange);
	if (m_keyboardInput.downArrowPressed)
		m_camera.RotatePitch(-frameChange);

	if (m_keyboardInput.animate)
	{
		for (int i = 0; i < NumLights; i++)
		{
			float direction = frameChange * pow(-1.0f, i);
			XMStoreFloat4(&m_lights[i].position, XMVector4Transform(XMLoadFloat4(&m_lights[i].position), XMMatrixRotationY(direction)));

			XMVECTOR eye = XMLoadFloat4(&m_lights[i].position);
			XMVECTOR at = { 0.0f, 8.0f, 0.0f };
			XMStoreFloat4(&m_lights[i].direction, XMVector3Normalize(XMVectorSubtract(at, eye)));
			XMVECTOR up = { 0.0f, 1.0f, 0.0f };
			m_lightCameras[i].Set(eye, at, up);

			m_lightCameras[i].Get3DViewProjMatrices(&m_lights[i].view, &m_lights[i].projection, 90.0f, static_cast<float>(m_width), static_cast<float>(m_height));
		}
	}

	m_pCurrentFrameResource->WriteConstantBuffers(&m_viewport, &m_camera, m_lightCameras, m_lights);
}
Example #2
0
void TestTriangleStripsDX::Update()
{
	if (processInput)
	{
		float rotAmount = 0.0f;
		XMMATRIX rotMatrix = XMMatrixIdentity();
		if (input.right || input.left)
		{
			if (input.right)
				rotAmount = rotDelta;
			if (input.left)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&up), XMConvertToRadians(rotAmount));
		}
		else if (input.up || input.down)
		{
			if (input.up)
				rotAmount = rotDelta;
			if (input.down)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&right), XMConvertToRadians(rotAmount));
		}

		XMStoreFloat4(&eye, XMVector3Transform(XMLoadFloat4(&eye), rotMatrix));
		XMStoreFloat4(&right, XMVector3Normalize(XMVector3Cross(XMLoadFloat4(&up), (XMLoadFloat4(&center) - XMLoadFloat4(&eye)))));

		XMMATRIX viewMatrix = XMMatrixLookAtRH(XMLoadFloat4(&eye), XMLoadFloat4(&center), XMLoadFloat4(&up));
		mDeviceContext->UpdateSubresource(viewMatrixBuffer, 0, NULL, &viewMatrix, 0, 0);
	}
}
Example #3
0
// static
void ff::QuaternionKey::InitTangents(QuaternionKey *pKeys, size_t nKeys, float tension)
{
	for (size_t i = 0; i < nKeys; i++)
	{
		QuaternionKey &keyCur       = pKeys[i];
		QuaternionKey &keyBefore    = pKeys[i ? i - 1 : nKeys - 1];
		QuaternionKey &keyNext      = pKeys[(i + 1) % nKeys];
		QuaternionKey &keyAfterNext = pKeys[(i + 2) % nKeys];

		XMVECTOR keyCurTangent;
		XMVECTOR keyNextTangent;
		XMVECTOR keyNextValue;

		XMQuaternionSquadSetup(
			&keyCurTangent,                       // A
			&keyNextTangent,                      // B
			&keyNextValue,                        // C
			XMLoadFloat4(&keyBefore._value),     // Q0
			XMLoadFloat4(&keyCur._value),        // Q1
			XMLoadFloat4(&keyNext._value),       // Q2
			XMLoadFloat4(&keyAfterNext._value)); // Q3

		XMStoreFloat4(&keyCur._tangent,  keyCurTangent);
		XMStoreFloat4(&keyNext._tangent, keyNextTangent);
		XMStoreFloat4(&keyNext._value,   keyNextValue);
	}
}
Example #4
0
void AasRenderer::RecalcNormals(int vertexCount, const XMFLOAT4* pos, XMFLOAT4* normals, int primCount, const uint16_t* indices) {
	static XMFLOAT4 recalcNormalsBuffer[0x8000];
	memset(recalcNormalsBuffer, 0, vertexCount * sizeof(XMFLOAT4));

	// Process every TRI we have
	auto curIdx = indices;
	for (auto tri = 0; tri < primCount; ++tri) {
		// Indices of the three vertices making up this triangle
		auto idx1 = *curIdx++;
		auto idx2 = *curIdx++;
		auto idx3 = *curIdx++;

		auto pos1 = XMLoadFloat4(&pos[idx1]);
		auto pos2 = XMLoadFloat4(&pos[idx2]);
		auto pos3 = XMLoadFloat4(&pos[idx3]);

		auto v1to2(pos2 - pos1);
		auto v1to3(pos3 - pos1);

		// Calculate the surface normal of the surface defined 
		// by the two directional vectors
		auto surfNormal(XMVector3Cross(v1to2, v1to3) * -1);

		// The surface normal contributes to all three vertex normals
		XMStoreFloat4(&normals[idx1], surfNormal);
		XMStoreFloat4(&normals[idx2], surfNormal);
		XMStoreFloat4(&normals[idx3], surfNormal);
	}

	// Re-Normalize the normals we calculated
	for (auto i = 0; i < vertexCount; ++i) {
		auto normal(XMVector3Normalize(XMLoadFloat4(&normals[i])));
		XMStoreFloat4(&normals[i], normal);
	}
}
Example #5
0
void Camera::rotateX(float amount)
{
	XMMATRIX mRotate = XMMatrixRotationAxis(XMLoadFloat4(&v_Right), amount);
	
	XMVECTOR new_y = XMVector4Transform(XMLoadFloat4(&v_Up), mRotate);
	XMVECTOR new_z = XMVector4Transform(XMLoadFloat4(&v_Look), mRotate);
	
	XMStoreFloat4(&v_Up, new_y);
	XMStoreFloat4(&v_Look, new_z);

	update();
}
Example #6
0
void Camera::rotateZ(float amount)
{
	XMMATRIX mRotate = XMMatrixRotationZ(amount);
	
	XMVECTOR new_x = XMVector4Transform(XMLoadFloat4(&v_Right), mRotate);
	XMVECTOR new_z = XMVector4Transform(XMLoadFloat4(&v_Look), mRotate);
	
	XMStoreFloat4(&v_Right, new_x);
	XMStoreFloat4(&v_Look, new_z);

	update();
}
Example #7
0
void World::moveEntity( WorldEntity* entity, XMVECTOR moveVec, float dist )
{
    //Try to move the entity in the world along the moveVec
    XMVECTOR pos = XMLoadFloat4( &entity->getPosition() );
    XMVECTOR wall = XMVectorZero();
    XMVECTOR vel = XMVectorScale( moveVec, dist );
    XMVECTOR desiredPos;
    XMFLOAT4 check;
    XMFLOAT4 negativeCheck;

    int checks = 0;
    int maxChecks = 10;
    float saveDist = dist;
    float distInterval = dist / static_cast<float>(maxChecks);

    XMStoreFloat4( &check, XMVector3Length(moveVec) );

    //Don't bother doing anything if there is no movement direction
    if( check.x <= 0.0f ){
        return;
    }

    //Check collision at where we plan to be
    if( checkEntityCollision( entity, pos, &wall ) ){
        XMStoreFloat4( &check, wall );
        XMStoreFloat4( &negativeCheck, vel );

        //Check the negative bit of the x and z values and see if they are equal, if they are, then stop movement
        bool negativeXWall = *(int*)(&check.x) < 0;
        bool negativeZWall = *(int*)(&check.z) < 0;

        bool negativeXVel = *(int*)(&negativeCheck.x) < 0;
        bool negativeZVel = *(int*)(&negativeCheck.z) < 0;

        //If we are not in a corner, collide with the wall, otherwise stop movement
        if(check.w <= 1.5f ||
           ( negativeXWall != negativeXVel || 
             negativeZWall != negativeZVel ) ){
            XMVECTOR invWall = XMVectorNegate( wall );
            wall = wall * XMVector3Length( moveVec * invWall );
            vel = (moveVec - wall) * dist;
        }else{
            vel = XMVectorZero();
        }
    }

    desiredPos = pos + vel;
    
    XMStoreFloat4( &entity->getPosition(), desiredPos );
}
Example #8
0
void Canister::Update(float DeltaTime, Terrain* terrain)
{
	XMFLOAT3	newPos	=	GetFloat3Value( Position );

	if ( !gPointLight )
	{
		gPointLight	=	new PointLight();
		gPointLight->GetGPULight()->Color		=	XMFLOAT4( 0.0f, 0.0f, 1.0f, 0.0f );
		gPointLight->GetGPULight()->Position	=	newPos;
		gPointLight->GetGPULight()->Range		=	33.333f * 0.40f;
		gPointLight->GetGPULight()->HasShadow	=	false;

		AddLight( gPointLight );
	}

	gTimeSpan	+=	DeltaTime;

	XMVECTOR QuatV = XMQuaternionRotationRollPitchYaw(0, DeltaTime, 0);
	XMFLOAT4 Quat;

	XMStoreFloat4(&Quat, QuatV);
	AddRotation( Quat );
	newPos.y	=	gOffset.y + ( gOffset.y - 2 ) * sin( 8 * gTimeSpan );
	MoveTo( newPos );
	newPos.y	-=	1.0f;
	if ( gPointLight )
		gPointLight->GetGPULight()->Position	=	newPos;

	Item::Update( DeltaTime, terrain );
}
Example #9
0
 f32 Vector::dot(const Vector& vec) const
 {
     XMVECTOR vecDot = XMVector3Dot(m_vector, vec.getXMVector());
     XMFLOAT4 fDot;
     XMStoreFloat4(&fDot, vecDot);
     return fDot.x;
 }
Example #10
0
void LevelParts::setWorld(XMFLOAT4X4 tempLevelPartsWorld)
{


	mLevelPartsWorld = tempLevelPartsWorld;


	XMMATRIX tempWorld = XMLoadFloat4x4(&mLevelPartsWorld);


	XMVECTOR Scale;
	XMVECTOR Position;
	XMVECTOR Rotation;


	XMMatrixDecompose(&Scale, &Rotation, &Position, tempWorld);

	XMStoreFloat3(&mLevelPartsPosition, Position);

	XMStoreFloat3(&mLevelPartsScale, Scale);

	XMStoreFloat4(&mLevelPartsRotation, Rotation);





	XMVECTOR S = XMLoadFloat3(&mLevelPartsScale);
	XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition);
	XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation);

	XMStoreFloat4x4(&mLevelPartsStartingWorld, XMMatrixAffineTransformation(S, rot, Q, P));

}
Example #11
0
void Direct3D::update(float dt)
{
	static float rotDT = 0.f;
	rotDT = dt;
	XMMATRIX rot = XMMatrixRotationAxis(XMVectorSet(0.f, 0.f, 1.f, 0.f), rotDT);
	for(int i = 0; i < NROFLIGHTS; i++)
	{
		XMVECTOR vLightPos = XMLoadFloat4(&m_lightList[i].pos);
		vLightPos = XMVector4Transform(vLightPos, rot);
		XMStoreFloat4(&m_lightList[i].pos, vLightPos);
	}
	m_pCamera->update();
	//m_fps = 1/dt;
	m_time += dt;
	static int frameCnt = 0;
    static float t_base = 0.f;
	frameCnt++;
	
	if(m_time - t_base >= 1.f)
	{
		frameCnt /= 1;
		m_fps = (float)frameCnt;
		frameCnt = 0;
		t_base += 1.f;
	}

	updateConstantBuffers();
}
Example #12
0
XMFLOAT4 quat_from_axis_angle(XMFLOAT3 axis, float angle)
{
    auto qr = XMQuaternionRotationAxis(XMLoadFloat3(&axis), XMConvertToRadians(angle));
    XMFLOAT4 quat;
    XMStoreFloat4(&quat, qr);
    return quat;
}
Example #13
0
        void d3d_display::update_camera() {
            XMVECTOR DefaultForward, DefaultRight, camPosition;
            
            DefaultForward = XMLoadFloat4(&_camera.DefaultForward);
            DefaultRight = XMLoadFloat4(&_camera.DefaultRight);
            camPosition = XMLoadFloat4(&_camera.camPosition);

            XMMATRIX camRotationMatrix = XMMatrixRotationRollPitchYaw(_camera.camPitch, _camera.camYaw, 0);
            XMVECTOR camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix);
            camTarget = XMVector3Normalize(camTarget);

            XMVECTOR camRight = XMVector3TransformCoord(DefaultRight, camRotationMatrix);
            XMVECTOR camForward = XMVector3TransformCoord(DefaultForward, camRotationMatrix);
            XMVECTOR camUp = XMVector3Cross(camForward, camRight);
           
            camPosition += _camera.moveLeftRight * camRight;
            camPosition += _camera.moveBackForward * camForward;
            XMStoreFloat4(&_camera.camPosition, camPosition);

            _camera.moveLeftRight = 0.0f;
            _camera.moveBackForward = 0.0f;

            camTarget = camPosition + camTarget;

            XMStoreFloat4x4(&_View, XMMatrixLookAtLH(camPosition, camTarget, camUp));
        }
Example #14
0
	//---------------------------------------------------------------------
	void SceneResource::processNodeTrack(const Util::XmlNode * trackNode, SceneNodePtr & parentSceneNode) const
	{
		NodeTrack & nodeTrack = parentSceneNode->getNodeTrack();

		Util::String trackModeStr(mXmlReader->getAttribute(trackNode, "track_mode"));
		if (boost::algorithm::equals("as_world", trackModeStr))
			nodeTrack.TrackMode = NTM_AS_WORLD;
		else if (boost::algorithm::equals("as_parent", trackModeStr))
			nodeTrack.TrackMode = NTM_AS_PARENT;

		nodeTrack.MoveSpeed = boost::lexical_cast<Util::real>(mXmlReader->getAttribute(trackNode, "move_speed"));
		nodeTrack.RotateSpeed = boost::lexical_cast<Util::real>(mXmlReader->getAttribute(trackNode, "rotate_speed"));

		const Util::XmlNode * controllPointNode = mXmlReader->getFirstNode(trackNode, "controll_point");
		while (controllPointNode)
		{
			NodeControllPoint controllPoint;
			XMStoreFloat3(&controllPoint.Position, Util::StringToVector(mXmlReader->getAttribute(controllPointNode, "position"), 3));
			XMStoreFloat4(&controllPoint.Orientation, Util::StringToVector(mXmlReader->getAttribute(controllPointNode, "orientation"), 4));

			parentSceneNode->addTrackPoint(controllPoint);

			controllPointNode = mXmlReader->getNextSiblingNode(controllPointNode);
		}
	}
Example #15
0
 f32 Vector::lengthSqr() const
 {
     XMVECTOR vecLen = XMVector3LengthSq(m_vector);
     XMFLOAT4 fLen;
     XMStoreFloat4(&fLen, vecLen);
     return fLen.x;
 }
Example #16
0
XMFLOAT4 Weapon::GetWeaponOffsetRotation()
{
	XMVECTOR quat = XMQuaternionIdentity();

	XMFLOAT3 direction = GetFloat3Value( Direction );

	XMFLOAT3 aimPos;
	XMFLOAT3 pipePos;

	if (GetJointPosition("PipeAim", aimPos) && GetJointPosition("Pipe", pipePos))
	{
		//handPos.y = pipePos.y;
		XMVECTOR directionV	= XMLoadFloat3(&direction);
		XMVECTOR handPosV	= XMLoadFloat3(&aimPos);
		XMVECTOR pipePosV	= XMLoadFloat3(&pipePos);

		XMVECTOR offsetDirectionV = pipePosV - handPosV;

		XMVECTOR angleV = XMVector3AngleBetweenVectors(directionV, offsetDirectionV);
		float angle;
		XMStoreFloat(&angle, angleV);

		if (angle != 0)
		{
			XMVECTOR axis = XMVector3Cross(directionV, offsetDirectionV);
			quat = XMQuaternionRotationAxis(axis, angle);
		}
	}

	XMFLOAT4 result;
	XMStoreFloat4(&result, quat);

	return result;
}
Example #17
0
    bool Vector::operator==(const Vector& rhs) const
    {
        XMVECTOR equVec = XMVectorEqual(m_vector, rhs.getXMVector());
        XMFLOAT4 fEqu;
        XMStoreFloat4(&fEqu, equVec);

        return fEqu.x && fEqu.y && fEqu.z && fEqu.w;
    }
Example #18
0
XMFLOAT3 EliteEnemyShip::getPosition()
{
	XMFLOAT4 pos;
	XMFLOAT4 orig = XMFLOAT4(0,0,0,1);
	XMFLOAT4X4 mat = *(body->getWorldMatrix());
	XMStoreFloat4(&pos, XMVector4Transform(XMLoadFloat4(&orig), XMLoadFloat4x4(&mat)));
	return (XMFLOAT3(pos.x, pos.y, pos.z));
}
Example #19
0
void GameEntity::init()
{
	_scale = XMFLOAT4(1.0f, 1.0f, 1.0f, 0.0f);
	XMStoreFloat4(&_rotation, XMQuaternionIdentity());
	_position = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
	_layer = 1;
	_color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
}
Example #20
0
	void RayTraceDataGenerator::GenerateRaytraceResult(int width, int height,float scale, XMFLOAT4 loc, int neardistance, int maxdepth, XMFLOAT4 n, XMFLOAT4 up, void(*CallbackFunc)(int x, int y, const int& TexType, const XMFLOAT4& loc, const XMFLOAT4& n,const float& depth, void* arg), void* arg)
	{
		XMVECTOR v_ori = XMLoadFloat4(&loc);
		XMVECTOR v_center=XMLoadFloat4(&loc);
		XMVECTOR v_n = XMLoadFloat4(&n);
		XMVECTOR v_up = XMVector3Normalize(XMLoadFloat4(&up));
		v_center = XMVectorAdd(v_center, XMVectorScale(v_n, neardistance));
		XMVECTOR v_dir_x = XMVector3Cross(v_n, v_up);
		XMVECTOR v_dir_y = XMVector3Cross(v_n, v_dir_x);
		XMVECTOR v_current = XMVectorAdd(v_center, XMVectorScale(v_dir_x, -scale*width*0.5));
		XMVECTOR v_ret_n;
		XMVECTOR v_ret_loc;
		//XMFLOAT4 v_unpacked;
		XMFLOAT4 v_ret_unpack_n;
		XMFLOAT4 v_ret_unpack_loc;
		XMVECTOR v_corner1;
		XMVECTOR v_corner2;
		bool result;
		float f_ret_depth;
		v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_y, -scale*height*0.5));
		v_corner1 = v_current;
		v_corner2 = XMVectorAdd(v_current, XMVectorScale(v_dir_y, +scale*height*1.0));
		v_corner2 = XMVectorAdd(v_corner2, XMVectorScale(v_dir_x, +scale*width*1.0));
		for (int i = 0; i < width; i++)
		{
			for (int j = 0; j < height; j++)
			{//XMVector3Normalize(XMVectorSubtract(v_current, v_ori))
				result = CalcIntersect(v_current, v_n, &v_ret_n, &v_ret_loc, &f_ret_depth);
				if (result)
				{
					XMStoreFloat4(&v_ret_unpack_loc,v_ret_loc);
					XMStoreFloat4(&v_ret_unpack_n, v_ret_n);
					CallbackFunc(i, j, GetLocInfo((int)v_ret_unpack_loc.x, (int)v_ret_unpack_loc.y, (int)v_ret_unpack_loc.z), v_ret_unpack_loc, v_ret_unpack_n, f_ret_depth, arg);
				}
				else
				{
					v_ret_unpack_n.x = v_ret_unpack_n.y = v_ret_unpack_n.z = -1;
					v_ret_unpack_loc.x = v_ret_unpack_loc.y = v_ret_unpack_loc.z = -1;
					f_ret_depth = -1;
					CallbackFunc(i, j, -1, v_ret_unpack_loc, v_ret_unpack_n, f_ret_depth, arg);
				}
				v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_y, scale));
			}
			v_current = XMVectorAdd(v_current, XMVectorScale(v_dir_x, scale));
		}
	}
Example #21
0
Quaternion& Quaternion::operator*=(const Quaternion& other)
{
    XMVECTOR q = ToSIMD();
    q = XMQuaternionMultiply(q, other.ToSIMD());
    XMStoreFloat4(reinterpret_cast<XMFLOAT4*>(this), q);

    return *this;
}
Example #22
0
bool MyListener::frameStarted(float timeSinceLastFrame)
{
	
	mKeyboard->capture();
	mMouse->capture();
	cameraMan->update(timeSinceLastFrame);
	debugWindow->updateFPS(timeSinceLastFrame);

	elapsedTime+=timeSinceLastFrame*0.3f;
	Light* l = mSceneMgr->mShadingMgr->directionalLight;

	
	//XMStoreFloat3(&baseDir,XMVector2Normalize(XMLoadFloat3(&baseDir)));

	//l->direction = baseDir;//XMFLOAT3(baseDir.x*cos(elapsedTime)-baseDir.z*sin(elapsedTime),baseDir.y,baseDir.x*cos(elapsedTime)+baseDir.z*sin(elapsedTime));
	//XMStoreFloat3(&l->direction,XMVector2Normalize(XMLoadFloat3(&l->direction)));
	XMStoreFloat3(&l->direction,XMVector3Rotate(XMLoadFloat3(&baseDir),XMLoadFloat4(&lightQuat)));

	mSceneMgr->getGuiManager()->update(timeSinceLastFrame/1000.0f);

	mPhysicsMgr->fetchResults(true);
	mPhysicsMgr->synchronizeEntities();
	mPhysicsMgr->startSimulating(timeSinceLastFrame);

	mShadowMapping->renderShadowMaps();

	//if(count%2==0)
	voxelScene->voxelizeScene(XMFLOAT3(30,30,30),XMFLOAT3(0,0,0));

	mShadowMapping->renderCaustics();

	voxelScene->endFrame(XMFLOAT3(30,30,30),XMFLOAT3(0,0,0));

	count++;

	//voxelScene->unifyVoxels();
	mSceneMgr->setCurrentCamera(mSceneMgr->getCamera("main"));
	mSceneMgr->mShadingMgr->updatePerFrameConstants(timeSinceLastFrame,mSceneMgr->getCamera(),mSceneMgr->getCamera("sun"));
	
	mRS->setBackbufferAsRenderTarget();
	mRS->clearViews();
	//mSceneMgr->renderSceneWithMaterial(mSceneMgr->getMaterial("depthWrite"));
	//mSceneMgr->renderScene();

	pp->render();


	mSceneMgr->getGuiManager()->render();

	mRS->swapChain_->Present(0,0);

	if(xp) xr+=timeSinceLastFrame; else if(xm) xr-=timeSinceLastFrame;
	if(zp) zr+=timeSinceLastFrame; else if(zm) zr-=timeSinceLastFrame;

	XMStoreFloat4(&lightQuat,XMQuaternionRotationRollPitchYaw(xr,0,zr));

	return continue_rendering;
}
Example #23
0
XMFLOAT4 BlendMap::GetBlendData(float x, float z)
{
	if (x < 0 || z < 0 ) 
		return XMFLOAT4(0,0,0,0);

	int maxWidth  = (m_Width  - 1);
	int maxHeight = (m_Height - 1);

	float X = x * maxWidth;
	float Z = z * maxHeight;

	if ( X > maxWidth || Z > maxHeight )
		return XMFLOAT4(0,0,0,0);

	if ( X == maxWidth || Z == maxHeight )
		return m_Map[(int)Z][(int)X];

	//hämtar blenddata för hörnen i den rektangel man står i
	XMVECTOR a = XMLoadFloat4(&m_Map[(int)Z+1][(int)X]);
	XMVECTOR b = XMLoadFloat4(&m_Map[(int)Z+1][(int)X+1]);
	XMVECTOR c = XMLoadFloat4(&m_Map[(int)Z][(int)X]);
	XMVECTOR d = XMLoadFloat4(&m_Map[(int)Z][(int)X+1]);

	float s = X - (int)X;
	float t = 1 - (Z - (int)Z);

	XMFLOAT4 result;

	//kollar vilken triangel man står i och räknar ut blenddata därefter.
	if (s + t <= 1)					//abc-triangel
	{
		XMVECTOR uy = b - a;
		XMVECTOR vy = c - a;
		XMStoreFloat4(&result, a + s * uy + t * vy);
	}

	else							//bcd-triangel
	{
		XMVECTOR uy = c - d;
		XMVECTOR vy = b - d;
		XMStoreFloat4(&result, d + (1.0f - s) * uy + (1.0f - t) * vy);
	}

	return result;
}
XMFLOAT4 SphereWalker::getBehind(float dist)
{
	XMVECTOR xperp	  = XMVectorSet(-cosf(angle), sinf(angle), 0,0);
	XMVECTOR incrementalRotation;
	incrementalRotation = XMQuaternionRotationAxis( xperp, -dist);
	XMFLOAT4 ret;
	XMStoreFloat4(&ret, XMQuaternionMultiply(incrementalRotation , XMLoadFloat4(&qPos)));
	return ret;
}
Example #25
0
void ExtractFrustumPlanes(XMFLOAT4 planes[6], CXMMATRIX M)
{
    //
    // Left
    //
    planes[0].x = M.r[0].m128_f32[3] + M.r[0].m128_f32[0];
    planes[0].y = M.r[1].m128_f32[3] + M.r[1].m128_f32[0];
    planes[0].z = M.r[2].m128_f32[3] + M.r[2].m128_f32[0];
    planes[0].w = M.r[3].m128_f32[3] + M.r[3].m128_f32[0];

    //
    // Right
    //
    planes[1].x = M.r[0].m128_f32[3] - M.r[0].m128_f32[0];
    planes[1].y = M.r[1].m128_f32[3] - M.r[1].m128_f32[0];
    planes[1].z = M.r[2].m128_f32[3] - M.r[2].m128_f32[0];
    planes[1].w = M.r[3].m128_f32[3] - M.r[3].m128_f32[0];

    //
    // Bottom
    //
    planes[2].x = M.r[0].m128_f32[3] + M.r[0].m128_f32[1];
    planes[2].y = M.r[1].m128_f32[3] + M.r[1].m128_f32[1];
    planes[2].z = M.r[2].m128_f32[3] + M.r[2].m128_f32[1];
    planes[2].w = M.r[3].m128_f32[3] + M.r[3].m128_f32[1];

    //
    // Top
    //
    planes[3].x = M.r[0].m128_f32[3] - M.r[0].m128_f32[1];
    planes[3].y = M.r[1].m128_f32[3] - M.r[1].m128_f32[1];
    planes[3].z = M.r[2].m128_f32[3] - M.r[2].m128_f32[1];
    planes[3].w = M.r[3].m128_f32[3] - M.r[3].m128_f32[1];

    //
    // Near
    //
    planes[4].x = M.r[0].m128_f32[2];
    planes[4].y = M.r[1].m128_f32[2];
    planes[4].z = M.r[2].m128_f32[2];
    planes[4].w = M.r[3].m128_f32[2];

    //
    // Far
    //
    planes[5].x = M.r[0].m128_f32[3] - M.r[0].m128_f32[2];
    planes[5].y = M.r[1].m128_f32[3] - M.r[1].m128_f32[2];
    planes[5].z = M.r[2].m128_f32[3] - M.r[2].m128_f32[2];
    planes[5].w = M.r[3].m128_f32[3] - M.r[3].m128_f32[2];

    // Normalize the plane equations.
    for (int i = 0; i < 6; ++i)
    {
        XMVECTOR v = XMPlaneNormalize(XMLoadFloat4(&planes[i]));
        XMStoreFloat4(&planes[i], v);
    }
}
void ExtractFrustumPlanes(XMFLOAT4 planes[6], CXMMATRIX M)
{
	//
	// Left
	//
	planes[0].x = M(0,3) + M(0,0);
	planes[0].y = M(1,3) + M(1,0);
	planes[0].z = M(2,3) + M(2,0);
	planes[0].w = M(3,3) + M(3,0);

	//
	// Right
	//
	planes[1].x = M(0,3) - M(0,0);
	planes[1].y = M(1,3) - M(1,0);
	planes[1].z = M(2,3) - M(2,0);
	planes[1].w = M(3,3) - M(3,0);

	//
	// Bottom
	//
	planes[2].x = M(0,3) + M(0,1);
	planes[2].y = M(1,3) + M(1,1);
	planes[2].z = M(2,3) + M(2,1);
	planes[2].w = M(3,3) + M(3,1);

	//
	// Top
	//
	planes[3].x = M(0,3) - M(0,1);
	planes[3].y = M(1,3) - M(1,1);
	planes[3].z = M(2,3) - M(2,1);
	planes[3].w = M(3,3) - M(3,1);

	//
	// Near
	//
	planes[4].x = M(0,2);
	planes[4].y = M(1,2);
	planes[4].z = M(2,2);
	planes[4].w = M(3,2);

	//
	// Far
	//
	planes[5].x = M(0,3) - M(0,2);
	planes[5].y = M(1,3) - M(1,2);
	planes[5].z = M(2,3) - M(2,2);
	planes[5].w = M(3,3) - M(3,2);

	// Normalize the plane equations.
	for(int i = 0; i < 6; ++i)
	{
		XMVECTOR v = XMPlaneNormalize(XMLoadFloat4(&planes[i]));
		XMStoreFloat4(&planes[i], v);
	}
}
Example #27
0
void Camera::updateView(float pitch, float yaw, float offset) {
	XMMATRIX rotate = XMMatrixRotationRollPitchYaw(pitch, yaw, 0);
	XMVECTOR pos = XMLoadFloat4(&position);
	XMVECTOR direction = XMLoadFloat4(&target) - pos;
	XMVECTOR realTarget = XMVector3Normalize(XMVector3TransformCoord(direction, rotate)) + pos;

	XMVECTOR realUp = XMVector3TransformCoord(XMLoadFloat4(&up), rotate);
	realUp = XMVector3Normalize(realUp);

	direction = XMVector3Normalize(realTarget - pos) * offset;
	pos += direction;
	realTarget += direction;
	XMStoreFloat4(&position, pos);
	XMStoreFloat4(&target, realTarget);
	XMStoreFloat4(&up, realUp);

	XMMATRIX view = XMMatrixLookAtLH(pos, realTarget, realUp);
	XMStoreFloat4x4(&viewMatrix, view);
}
Example #28
0
Quat Json2Quat(const Json::Value& value)
{
	Quat ret;
	Vector3 v3;
	v3.x = (float)value[(size_t)0].asDouble();
	v3.y = (float)value[1].asDouble();
	v3.z = (float)value[2].asDouble();
	XMVECTOR q = XMQuaternionRotationRollPitchYaw(v3.x * Angle2Radian, v3.y * Angle2Radian, v3.z * Angle2Radian);
	XMStoreFloat4((XMFLOAT4*)&ret, q);
	return ret;
}
Example #29
0
// static
void ff::VectorKey::Interpolate(const VectorKey &lhs, const VectorKey &rhs, float time, bool bSpline, XMFLOAT4 &output)
{
	if (bSpline)
	{
		XMStoreFloat4(&output,
			XMVectorHermite(
				XMLoadFloat4(&lhs._value),
				XMLoadFloat4(&lhs._tangent),
				XMLoadFloat4(&rhs._value),
				XMLoadFloat4(&rhs._tangent),
				time));
	}
	else
	{
		XMStoreFloat4(&output,
			XMVectorLerp(
				XMLoadFloat4(&lhs._value),
				XMLoadFloat4(&rhs._value),
				time));
	}
}
Example #30
0
// static
void ff::QuaternionKey::Interpolate(const QuaternionKey &lhs, const QuaternionKey &rhs, float time, bool bSpline, XMFLOAT4 &output)
{
	if (bSpline)
	{
		XMStoreFloat4(&output,
			XMQuaternionSquad(
				XMLoadFloat4(&lhs._value),
				XMLoadFloat4(&lhs._tangent),
				XMLoadFloat4(&rhs._tangent),
				XMLoadFloat4(&rhs._value),
				time));
	}
	else
	{
		XMStoreFloat4(&output,
			XMQuaternionSlerp(
				XMLoadFloat4(&lhs._value),
				XMLoadFloat4(&rhs._value),
				time));
	}
}