예제 #1
0
파일: BoidManager.cpp 프로젝트: hxshly/FYP
XMVECTOR BoidManager::vMult(XMVECTOR a, XMVECTOR b)
{
	
	float x, y, z;
	
	if (XMVectorGetX(b) == -1.0f)
		{
			x = (XMVectorGetX(a) * XMVectorGetX(b));
		}
		else {
				x = XMVectorGetX(a);
			 }


	if (XMVectorGetY(b) == -1.0f)
		{
			y = (XMVectorGetY(a) * XMVectorGetY(b));
		}
		else {
				y = XMVectorGetY(a);
			 }


	if (XMVectorGetZ(b) == -1.0f)
		{
			z = (XMVectorGetZ(a) * XMVectorGetZ(b));
		}
		else {
				z = XMVectorGetZ(a);
			 }

	XMVECTOR mult = XMVectorSet(x, y, z, 0.0f);

	return mult;
}
예제 #2
0
void AimingEnemyController::update(UpdatePackage * package)
{
	//find the player
	PlayerController * playerController = package->state->getComponentOfType<PlayerController>();
	// if there is a player
	if (playerController != NULL)
	{
		// get information on the player and the enemy
		Entity * player = package->state->getContainerEntity(playerController);
		ShipController * ship = package->entity->getComponentOfType<ShipController>();
		Transform * transform = package->entity->getComponentOfType<Transform>();
		Physics * physics = package->entity->getComponentOfType<Physics>();
		Transform * playerTransform = player->getComponentOfType<Transform>();
		//find the vector between them
		XMVECTOR difference = transform->getPosition() - playerTransform->getPosition();
		//get the length of the distance
		float distance = XMVectorGetX(XMVector3Length(difference));
		//get the cross product of the unit vector between the player and the enemy and the forward vector of the enemy 
		difference = XMVector3Normalize(difference);
		XMVECTOR cross = XMVector3Cross(transform->getUp(), difference);
		// turn the ship based on the z component of the cross product
		ship->turn(-XMVectorGetZ(cross) * 2);
		//if the vectors are moslty aligned then fire
		if (abs(XMVectorGetZ(cross)) < 0.1f)
		{
			ship->fire();
		}
		//if the ship is mostly facing the player and is too far away then thrust
		if (distance > 300 && abs(abs(XMVectorGetZ(cross)) < 0.5f))
		{
			ship->thrust();
		}
	}
}
예제 #3
0
void GetBoundCornersFromPoints(const XMFLOAT3* points, uint32 numPoints, uint32 stride, 
	XMVECTOR &minx, XMVECTOR &maxx, XMVECTOR &miny, XMVECTOR &maxy, XMVECTOR &minz, XMVECTOR &maxz)
{
	Assert_(numPoints > 0);
	Assert_(points);

	minx = maxx = miny = maxy = minz = maxz = XMLoadFloat3(points);

	for (uint32 i = 1; i < numPoints; i++)
	{
		XMVECTOR Point = XMLoadFloat3((XMFLOAT3*)((BYTE*)points + i * stride));

		float px = XMVectorGetX(Point);
		float py = XMVectorGetY(Point);
		float pz = XMVectorGetZ(Point);

		if (px < XMVectorGetX(minx))
			minx = Point;

		if (px > XMVectorGetX(maxx))
			maxx = Point;

		if (py < XMVectorGetY(miny))
			miny = Point;

		if (py > XMVectorGetY(maxy))
			maxy = Point;

		if (pz < XMVectorGetZ(minz))
			minz = Point;

		if (pz > XMVectorGetZ(maxz))
			maxz = Point;
	}
}
예제 #4
0
void BoneModel::createBone(){

	auto& bones = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneBuffer;
	auto& boneName = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneName;

	DWORD mBoneNum = bones.size();
	mBone.clear();
	mIk.clear();
	mBone.resize(mBoneNum);

	DWORD ikCount = 0;
	for (DWORD i = 0; i < mBoneNum; i++){
		auto& bone = bones[i];


		mBone[i].mStrName = boneName[i];
		mBone[i].mHierarchy.mIdxSelf = i;
		mBone[i].mHierarchy.mIdxParent = bone.parent_bidx;
		if (bone.parent_bidx >= (int)mBoneNum) mBone[i].mHierarchy.mIdxParent = UINT(-1);


		XMVECTOR head_pos = XMVectorSet(bone.bone_head_pos[0], bone.bone_head_pos[1], bone.bone_head_pos[2], 0.0f);
		XMVECTOR parent_pos = { 0, 0, 0, 1 };
		if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){
			UINT p = mBone[i].mHierarchy.mIdxParent;
			parent_pos = XMVectorSet(bones[p].bone_head_pos[0], bones[p].bone_head_pos[1], bones[p].bone_head_pos[2], 0.0f);
		}

		XMVECTOR local_pos = XMVectorSubtract(head_pos, parent_pos);

		mBone[i].mPos = XMFLOAT3(XMVectorGetX(local_pos), XMVectorGetY(local_pos), XMVectorGetZ(local_pos));
		mBone[i].mScale = XMFLOAT3(1.0f, 1.0f, 1.0f);
		XMVECTOR q = XMQuaternionIdentity();
		mBone[i].mRot = XMFLOAT4(XMVectorGetX(q), XMVectorGetY(q), XMVectorGetZ(q), XMVectorGetW(q));

		//ワールド行列計算
		XMVECTOR scale = { 1, 1, 1, 1 };
		mBone[i].mMtxPose = SRTMatrix(scale, q, local_pos);
		if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){
			mBone[i].mMtxPose = XMMatrixMultiply(mBone[i].mMtxPose, mBone[mBone[i].mHierarchy.mIdxParent].mMtxPose);
		}
		if (bone.bone_flag & pmx::t_bone::BIT_IK){
			mBone[i].mIkBoneIdx = (WORD)bone.t_ik_data_idx;

			createIk(ikCount, i);
			ikCount++;
		}
		else{
			mBone[i].mIkBoneIdx = 0;
		}


		mBone[i].mMtxPoseInit = mBone[i].mMtxPose;

	}
}
예제 #5
0
inline BOOL checkCamInOctree(const Engine::Octree *octree, const Engine::PerspCamera *cam)
{
	const XMVECTOR p = cam->getCameraPosition();

	if (XMVectorGetX(p) >= octree->vertex[0].x && XMVectorGetX(p) < octree->vertex[7].x &&
		XMVectorGetY(p) >= octree->vertex[0].y && XMVectorGetY(p) < octree->vertex[7].y &&
		XMVectorGetZ(p) >= octree->vertex[0].z && XMVectorGetZ(p) < octree->vertex[7].z)
		return TRUE;
	return FALSE;
}
예제 #6
0
bool SceneNode::check_collision(SceneNode* compare_tree, SceneNode* object_tree_root)
{
	// check to see if root of tree being compared is same as root node of object tree being checked
	// i.e. stop object node and children being checked against each other
	if (object_tree_root == compare_tree) return false;

	// only check for collisions if both nodes contain a model
	if (m_p_model && compare_tree->m_p_model)
	{
		XMVECTOR v1 = get_world_centre_position();
		XMVECTOR v2 = compare_tree->get_world_centre_position();
		XMVECTOR vdiff = v1 - v2;

		//XMVECTOR a = XMVector3Length(vdiff);
		float x1 = XMVectorGetX(v1);
		float x2 = XMVectorGetX(v2);
		float y1 = XMVectorGetY(v1);
		float y2 = XMVectorGetY(v2);
		float z1 = XMVectorGetZ(v1);
		float z2 = XMVectorGetZ(v2);

		float dx = x1 - x2;
		float dy = y1 - y2;
		float dz = z1 - z2;

		// check bounding sphere collision
		if (sqrt(dx*dx + dy*dy + dz*dz) <
			(compare_tree->m_p_model->GetBoundingSphereRadius() * compare_tree->m_world_scale) +
			(this->m_p_model->GetBoundingSphereRadius() * m_world_scale))
		{
			return true;
		}
	}

	// iterate through compared tree child nodes
	for (int i = 0; i< compare_tree->m_children.size(); i++)
	{
		// check for collsion against all compared tree child nodes 
		if (check_collision(compare_tree->m_children[i], object_tree_root) == true) return true;
	}

	// iterate through composite object child nodes
	for (int i = 0; i< m_children.size(); i++)
	{
		// check all the child nodes of the composite object against compared tree
		if (m_children[i]->check_collision(compare_tree, object_tree_root) == true) return true;
	}

	return false;

}
예제 #7
0
void Engine::PerspCamera::setTargetPosition(const FLOAT &atheta, const FLOAT &aphi) const
{
	FLOAT tmp = cosf(aphi);
	*_vforward = XMVectorSet(tmp * sinf(atheta), sinf(aphi), tmp * cosf(atheta), 0.0f);
	*_vleft = XMVector3Normalize(XMVectorSet(XMVectorGetZ(*_vforward), 0.0f, -XMVectorGetX(*_vforward), 0.0f));
	*_vup = XMVector3Cross(*_vforward, *_vleft);
}
예제 #8
0
void rainDrop::update(CameraClass *camera)
{
    if (!alive)
    {
        triggerTick += 15;
    
        if (triggerTick > triggerDelay)
        {
            alive = true;
            triggerTick = 0;
        }
    }

    else
    {    
        y -= 0.45;

        if (y < -5)
        {
           y = 10;
           x = initial_x + XMVectorGetX(camera -> getPos());
           z = initial_z + XMVectorGetZ(camera -> getPos());
           alive = false;
        }
    }
}
예제 #9
0
    void MainLoop()
    {
	    Layer[0] = new VRLayer(HMD);

	    while (HandleMessages())
	    {
            // We turn off yaw to keep the case simple
		    ActionFromInput(1, false);
		    Layer[0]->GetEyePoses();

            // Find perturbation of position from point 1m in front of camera
            XMVECTOR eye0 = ConvertToXM(Layer[0]->EyeRenderPose[0].Position);
            XMVECTOR eye1 = ConvertToXM(Layer[0]->EyeRenderPose[1].Position);
            XMVECTOR perturb = XMVectorScale(XMVectorAdd(eye0, eye1), 0.5f);

            // Calculate velocity from this
            const float sensitivity = 0.2f;
		    XMVECTOR vel = XMVectorScale(XMVectorSet(-XMVectorGetX(perturb), 0, -XMVectorGetZ(perturb), 0), sensitivity);

              // Add velocity to camera
            MainCam->Pos = XMVectorAdd(MainCam->Pos, vel);

            for (int eye = 0; eye < 2; ++eye)
		    {
			    Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye);
		    }

		    Layer[0]->PrepareLayerHeader();
		    DistortAndPresent(1);
	    }
    }
예제 #10
0
파일: main.cpp 프로젝트: GainLee/OculusSDK
    void MainLoop()
    {
	    Layer[0] = new VRLayer(Session);

	    while (HandleMessages())
	    {
			//Need to check we're visible, before proceeding with velocity changes, 
			//otherwise it does this a lot of times, and we
			//end up miles away from our start point from the sheer number of iterations.
			ovrSessionStatus sessionStatus;
			ovr_GetSessionStatus(Session, &sessionStatus);
			if (sessionStatus.IsVisible)
			{
				// Take out manual yaw rotation (leaving button move for now)
				ActionFromInput(1, false);
				ovrTrackingState trackingState = Layer[0]->GetEyePoses();

				// Set various control methods into camera
				MainCam->Pos = XMVectorAdd(MainCam->Pos, FindVelocityFromTilt(this, Layer[0], &trackingState));

				MainCam->Pos = XMVectorSet(XMVectorGetX(MainCam->Pos),
					GetAccelJumpPosY(this, &trackingState),
					XMVectorGetZ(MainCam->Pos), 0);

				MainCam->Rot = GetAutoYawRotation(Layer[0]);

				// If tap side of Rift, then fire a bullet
				bool singleTap = WasItTapped(trackingState.HeadPose.LinearAcceleration);

				static XMVECTOR bulletPos = XMVectorZero();
				static XMVECTOR bulletVel = XMVectorZero();
				if (singleTap)
				{
					XMVECTOR eye0 = ConvertToXM(Layer[0]->EyeRenderPose[0].Position);
					XMVECTOR eye1 = ConvertToXM(Layer[0]->EyeRenderPose[1].Position);
					XMVECTOR midEyePos = XMVectorScale(XMVectorAdd(eye0, eye1), 0.5f);

					XMVECTOR totalRot = XMQuaternionMultiply(ConvertToXM(Layer[0]->EyeRenderPose[0].Orientation), MainCam->Rot);
					XMVECTOR posOfOrigin = XMVectorAdd(MainCam->Pos, XMVector3Rotate(midEyePos, MainCam->Rot));

					XMVECTOR unitDirOfMainCamera = XMVector3Rotate(XMVectorSet(0, 0, -1, 0), totalRot);

					bulletPos = XMVectorAdd(posOfOrigin, XMVectorScale(unitDirOfMainCamera, 2.0f));
					bulletVel = XMVectorScale(unitDirOfMainCamera, 0.3f);
				}

				// Move missile on, and set its position
				bulletPos = XMVectorAdd(bulletPos, bulletVel);
				XMStoreFloat3(&RoomScene->Models[1]->Pos, bulletPos);

				for (int eye = 0; eye < 2; ++eye)
				{
					Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye);
				}

				Layer[0]->PrepareLayerHeader();
				DistortAndPresent(1);
			}
	    }
    }
예제 #11
0
void Camera::moveCam()
{
	XMVECTOR tempRight = XMLoadFloat3(&mRight);
	XMVECTOR tempUp = XMLoadFloat3(&mUp);
	XMVECTOR tempPosition = XMLoadFloat3(&mPosition);
	XMVECTOR tempForward = XMLoadFloat3(&mLook);
	



	//set the camera to look at the character
	camTarget = playerPosition;






	XMVECTOR tempTarget = XMLoadFloat3(&camTarget);

	tempTarget = XMVectorSetY(tempTarget,10);


	
	//rotate camera around the character
	camRotationMatrix = XMMatrixRotationRollPitchYaw(-camPitch, camYaw, 0);
	tempPosition = XMVector3TransformNormal(PlayerForward, camRotationMatrix);
	tempPosition = XMVector3Normalize(tempPosition);


	tempPosition = (tempPosition * -50) + tempTarget;
		
	tempPosition = XMVectorSetY(tempPosition, 30.0f);

	tempForward = XMVector3Normalize(tempTarget - tempPosition);	// Get forward vector based on target
	tempForward = XMVectorSetY(tempForward, 0.0f);	// set forwards y component to 0 so it lays only on

	tempForward= XMVector3Normalize(tempForward);

	tempRight = XMVectorSet(XMVectorGetZ(-tempForward), 0.0f, XMVectorGetX(tempForward), 0.0f);

	tempUp = XMVector3Normalize(XMVector3Cross(XMVector3Normalize(tempPosition - tempTarget), tempRight));



	XMStoreFloat3(&mRight, tempRight);
	XMStoreFloat3(&mUp, tempUp);
	XMStoreFloat3(&mPosition, tempPosition);
	XMStoreFloat3(&mLook, tempForward);

	XMMATRIX tempView = XMLoadFloat4x4(&mView);


	tempView = XMMatrixLookAtLH(tempPosition, tempTarget, tempUp);

	XMStoreFloat4x4(&mView, tempView);

	///////////mising some code maybe
}
예제 #12
0
	//---------------------------------------------------------------------
	Frustum::LocateSide Frustum::testContainState(FXMVECTOR plane, const Util::AABBPtr & aabb)
	{
		Util::real dist = XMVectorGetX(XMPlaneDotCoord(plane, aabb->getCenterPoint()));

		XMVECTOR halfSize = aabb->getHalfSize();
		Util::real maxAbsDist = abs(XMVectorGetX(plane) * XMVectorGetX(halfSize)) + 
			abs(XMVectorGetY(plane) * XMVectorGetY(halfSize)) +
			abs(XMVectorGetZ(plane) * XMVectorGetZ(halfSize));

		if (dist < -maxAbsDist)
			return LS_NEGATIVE;

		if (dist > + maxAbsDist)
			return LS_POSITIVE;

		return LS_INTERSECT;
	}
예제 #13
0
void		CFVec4::SetXYZ( CFVec3Arg fv3Source )
{
	const XMVECTOR& v3V = *reinterpret_cast<const XMVECTOR*>( &fv3Source );
	XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>(this);

	v4V = XMVectorSetX( v4V, XMVectorGetX( v3V ) );
	v4V = XMVectorSetY( v4V, XMVectorGetY( v3V ) );
	v4V = XMVectorSetZ( v4V, XMVectorGetZ( v3V ) );
}
예제 #14
0
파일: DEMO.cpp 프로젝트: locpk/Mockingbird
float ObjectToCamera(XMFLOAT4X4* _objMatrix, XMFLOAT3 _cameraPos)
{
	XMVECTOR obj = XMVectorZero();
	obj = XMVector3Transform(obj, XMLoadFloat4x4(_objMatrix));
	float ObjtoCameraX = XMVectorGetX(obj) - _cameraPos.x;
	float ObjtoCameraY = XMVectorGetY(obj) - _cameraPos.y;
	float ObjtoCameraZ = XMVectorGetZ(obj) - _cameraPos.z;
	return ObjtoCameraX*ObjtoCameraX + ObjtoCameraY*ObjtoCameraY + ObjtoCameraZ*ObjtoCameraZ;
}
예제 #15
0
//ALEX OWEN - 26/01/15 - set the position with a vector
void GameObject::setPositionVec(FXMVECTOR _position)
{
	position.x = XMVectorGetX(_position);
	position.y = XMVectorGetY(_position);
	position.z = XMVectorGetZ(_position);
	updated = true;
	transformed = true;

}
예제 #16
0
//ALEX OWEN - 26/01/15 - set the position with a vector
void GameObject::setRotationVec(FXMVECTOR _rotation)
{
	rotation.x = XMVectorGetX(_rotation);
	rotation.y = XMVectorGetY(_rotation);
	rotation.z = XMVectorGetZ(_rotation);
	updated = true;
	transformed = true;

}
예제 #17
0
XMVECTOR GetAngle(XMVECTOR quat)
{
	XMMATRIX mtx = XMMatrixRotationQuaternion(quat);

	//ZYX Y=-90〜90°Y軸=ねじり方向
	float rx = -atan2f(XMVectorGetY(mtx.r[2]), XMVectorGetZ(mtx.r[2]));
	float ry = asinf(XMVectorGetX(mtx.r[2]));
	float rz = -atan2f(XMVectorGetX(mtx.r[1]), XMVectorGetX(mtx.r[0]));
	return XMVectorSet(rx, ry, rz, 0);
}
void D3DCamera::RebuildView()
{
    // Keep camera's axes orthogonal to each other and of unit length.
    m_LookAt = XMVector3Normalize(m_LookAt);

    m_Up = XMVector3Cross(m_LookAt, m_Right);
    m_Up = XMVector3Normalize(m_Up);

    m_Right = XMVector3Cross(m_Up, m_LookAt);
    m_Right = XMVector3Normalize(m_Right);

    // Fill in the view matrix entries.
    float x = -XMVectorGetX(XMVector3Dot(m_Position, m_Right));
    float y = -XMVectorGetX(XMVector3Dot(m_Position, m_Up));
    float z = -XMVectorGetX(XMVector3Dot(m_Position, m_LookAt));

    XMFLOAT4X4 tempView;

    tempView(0, 0) = XMVectorGetX(m_Right);
    tempView(1, 0) = XMVectorGetY(m_Right);
    tempView(2, 0) = XMVectorGetZ(m_Right);
    tempView(3, 0) = x;

    tempView(0, 1) = XMVectorGetX(m_Up);
    tempView(1, 1) = XMVectorGetY(m_Up);
    tempView(2, 1) = XMVectorGetZ(m_Up);
    tempView(3, 1) = y;

    tempView(0, 2) = XMVectorGetX(m_LookAt);
    tempView(1, 2) = XMVectorGetX(m_LookAt);
    tempView(2, 2) = XMVectorGetX(m_LookAt);
    tempView(3, 2) = z;

    tempView(0, 3) = 0.0f;
    tempView(1, 3) = 0.0f;
    tempView(2, 3) = 0.0f;
    tempView(3, 3) = 1.0f;

    m_ViewMatrix = XMLoadFloat4x4(&tempView);

    // Reconstuct the viewing frustum.
    //m_Frustum->ConstructFrustrum( m_zFar, m_ProjMatrix, m_ViewMatrix );
}
예제 #19
0
	void LightPoint::update_radius() {
		XMVECTOR v = colorv();
		float r = XMVectorGetX(v);
		float g = XMVectorGetY(v);
		float b = XMVectorGetZ(v);
		float max = std::fmaxf(std::fmaxf(r, g), b);
		m_radius = (-m_linear +
					std::sqrtf(m_linear * m_linear -
							   4 * m_quadratic * (m_constant - 256.0f * intensity() * max)))
			/ (2 * m_quadratic);
	}
예제 #20
0
XMVECTOR ArcBall::QuatFromBallPoints(XMVECTOR startPoint, XMVECTOR endPoint )
{
	XMVECTOR dotVector = XMVector3Dot(startPoint, endPoint);
	float fDot = XMVectorGetX(dotVector);

	XMVECTOR vPart;
	vPart = XMVector3Cross(startPoint, endPoint);	

	XMVECTOR result = XMVectorSet(XMVectorGetX(vPart), XMVectorGetY(vPart), XMVectorGetZ(vPart), fDot);
	return result;
}
예제 #21
0
파일: Scene.cpp 프로젝트: verrev/0
void Scene::render()
{
	t.begin();

	DirectX11Core::clearRenderTargetViews();

	terrain.draw();
	box.draw();
	sphere.draw();
	car.draw();

	static float f = 0.0f; f += 0.001f;

	Input::update();

	//cbl.lightPosW = XMFLOAT3(-2 * sin(f), 2 * cos(f), -1);
	
	cbl.lightPosW = XMFLOAT3(XMVectorGetX(c->getPos()), XMVectorGetY(c->getPos()), XMVectorGetZ(c->getPos()));

	DirectX11Core::mDeviceContext->UpdateSubresource(light, 0, 0, &cbl, 0, 0);
	DirectX11Core::mDeviceContext->VSSetConstantBuffers(2, 1, &light);

	float lr = 0, bf = 0, dt = t.getDelta(), factor = 4.5f;
	if (Input::isKeyDown(DIK_W)) {
		bf = dt * factor;
	}
	else if (Input::isKeyDown(DIK_S)) {
		bf = -dt * factor;
	}
	if (Input::isKeyDown(DIK_A)) {
		lr = -dt * factor;
	}
	else if (Input::isKeyDown(DIK_D)) {
		lr = dt * factor;
	}
	static float yaw = 0, pitch = 0, mouseFactor = 1.2f;
	yaw += Input::getMouseX() * dt * mouseFactor;
	pitch += Input::getMouseY() * dt * mouseFactor;
	c->update(lr, bf, yaw, pitch);

	s.draw(c->getPos());

	DirectX11Core::endScene();
	t.end(1);

	FrameStats fs = t.getStats();
	std::wstring s = L"FPS: ";
	s.append(std::to_wstring((int)fs.fps));
	s.append(L" frametime: ");
	s.append(std::to_wstring(fs.msPerFrame));
	s.append(L" (ms)");
	SetWindowText(DirectX11Core::mWindow, s.c_str());
}
예제 #22
0
void Graphics::exe_cam_curr_pos(uint32_t const _i_zad) {
	XMVECTOR _v = XMVectorSet(cam.v.x, 0.0f, cam.v.z, 0.0f);
	XMVECTOR _dl_v = XMVector3LengthEst(_v);
	if(XMVectorGetX(_dl_v) != 0.0f) {
		_v = XMVector3Rotate(_v, XMLoadFloat4(&cam.quat));
		_v = XMVectorSetY(_v, 0.0f);
		XMVECTOR _v_modul = XMVectorAbs(_v);
		_v = _v / (XMVectorGetX(_v_modul) + XMVectorGetZ(_v_modul)) * _dl_v;
	}
	_v = XMVectorSetY(_v, cam.v.y);
	XMStoreFloat3(&cam.pos, XMLoadFloat3(&cam.pos) + _v);
	task.erase(_i_zad);
}
예제 #23
0
		void Camera::Update(float elapsedTime)
		{

			//Calculate the move vector in camera space 
			XMFLOAT3 move(0, 0, 0);
			if (m_KeysPressed.a)
				move.x -= 1.0f;
			if (m_KeysPressed.d)
				move.x += 1.0f;
			if (m_KeysPressed.w)
				move.z -= 1.0f;
			if (m_KeysPressed.s)
				move.z += 1.0f;

			if (fabs(move.x) > 0.1f && fabs(move.z) > 0.1f)
			{
				XMVECTOR vector = XMVector3Normalize(XMLoadFloat3(&move));
				move.x = XMVectorGetX(vector);
				move.z = XMVectorGetZ(vector);
			}
			float moveInterval = m_MoveSpeed * elapsedTime;
			float rotateInterval = m_TurnSpeed * elapsedTime;

			if (m_KeysPressed.left)
				m_Yaw += rotateInterval;
			if (m_KeysPressed.right)
				m_Yaw -= rotateInterval;
			if (m_KeysPressed.up)
				m_Pitch += rotateInterval;
			if (m_KeysPressed.down)
				m_Pitch -= rotateInterval;

			// Prevent looking too far up or down.
			m_Pitch = min(m_Pitch, XM_PIDIV4);
			m_Pitch = max(-XM_PIDIV4, m_Pitch);

			// Move the camera in model space.
			float x = move.x * -cosf(m_Yaw) - move.z * sinf(m_Yaw);
			float z = move.x * sinf(m_Yaw) - move.z * cosf(m_Yaw);
			m_Pos.x += x * moveInterval;
			m_Pos.z += z * moveInterval;

			// Determine the look direction.
			float r = cosf(m_Pitch);
			m_Look.x = r * sinf(m_Yaw);
			m_Look.y = sinf(m_Pitch);
			m_Look.z = r * cosf(m_Yaw);

		}
예제 #24
0
BBox ComputeBoundingBoxFromPoints(const XMFLOAT3* points, uint32 numPoints, uint32 stride)
{
	BBox out;
	XMVECTOR MinX, MaxX, MinY, MaxY, MinZ, MaxZ;
	GetBoundCornersFromPoints(points, numPoints, sizeof(XMFLOAT3), MinX, MaxX, MinY, MaxY, MinZ, MaxZ);

	float maxx = XMVectorGetX(MaxX);
	float maxy = XMVectorGetY(MaxY);
	float maxz = XMVectorGetZ(MaxZ);

	float minx = XMVectorGetX(MinX);
	float miny = XMVectorGetY(MinY);
	float minz = XMVectorGetZ(MinZ);

	out.Max.x = maxx;
	out.Max.y = maxy;
	out.Max.z = maxz;

	out.Min.x = minx;
	out.Min.y = miny;
	out.Min.z = minz;

	return out;
}
예제 #25
0
	//---------------------------------------------------------------------
	LooseOctreeZonePtr & LooseOctreeZone::getFitChildZone(const Util::AABBPtr & aabb)
	{
		XMVECTOR nodeCenter = aabb->getCenterPoint();
		XMVECTOR myCenter = mAABB->getCenterPoint();

		Util::u_int x = (XMVectorGetX(nodeCenter) > XMVectorGetX(myCenter)) ? 1 : 0;
		Util::u_int y = (XMVectorGetY(nodeCenter) > XMVectorGetY(myCenter)) ? 1 : 0;
		Util::u_int z = (XMVectorGetZ(nodeCenter) > XMVectorGetZ(myCenter)) ? 1 : 0;

		if (NULL == mChildZones[x][y][z])
		{
			XMVECTOR minPoint = mAABB->getMinPoint();
			XMVECTOR maxPoint = mAABB->getMaxPoint();
			XMFLOAT3 newMin;
			XMFLOAT3 newMax;

			if (0 == x)
			{
				newMin.x = XMVectorGetX(minPoint);
				newMax.x = XMVectorGetX(myCenter);
			}
			else
			{
				newMin.x = XMVectorGetX(myCenter);
				newMax.x = XMVectorGetX(maxPoint);
			}

			if (0 == y)
			{
				newMin.y = XMVectorGetY(minPoint);
				newMax.y = XMVectorGetY(myCenter);
			}
			else
			{
				newMin.y = XMVectorGetY(myCenter);
				newMax.y = XMVectorGetY(maxPoint);
			}

			if (0 == z)
			{
				newMin.z = XMVectorGetZ(minPoint);
				newMax.z = XMVectorGetZ(myCenter);
			}
			else
			{
				newMin.z = XMVectorGetZ(myCenter);
				newMax.z = XMVectorGetZ(maxPoint);
			}

			mChildZones[x][y][z] = boost::make_shared<LooseOctreeZone>(XMLoadFloat3(&newMin), XMLoadFloat3(&newMax), mDepth + 1);
			mChildZones[x][y][z]->setParentZone(this->shared_from_this()); 
		}

		return mChildZones[x][y][z];
	}
예제 #26
0
XMMATRIX Camera::getViewMatrix() const
{

	XMMATRIX m_view = XMMatrixIdentity();

	XMVECTOR x = -XMVector3Dot(XMLoadFloat4(&v_Right), XMLoadFloat4(&v_Pos));
	XMVECTOR y = -XMVector3Dot(XMLoadFloat4(&v_Up),    XMLoadFloat4(&v_Pos));
	XMVECTOR z = -XMVector3Dot(XMLoadFloat4(&v_Look),  XMLoadFloat4(&v_Pos));


	m_view(0,0) = v_Right.x;		m_view(0,1) = v_Up.x;			m_view(0,2) = v_Look.x; 	
	m_view(1,0) = v_Right.y;		m_view(1,1) = v_Up.y;			m_view(1,2) = v_Look.y; 
	m_view(2,0) = v_Right.z;		m_view(2,1) = v_Up.z;			m_view(2,2) = v_Look.z; 
	m_view(3,0) = XMVectorGetX(x);  m_view(3,1) = XMVectorGetY(y);  m_view(3,2) = XMVectorGetZ(z);


	return m_view;
}
예제 #27
0
XMVECTOR HydraManager::getRotation(int controllerIndex) const
{
	if (sixenseIsControllerEnabled(controllerIndex))
	{
		XMVECTOR axis;
		float angle;

		XMQuaternionToAxisAngle(&axis, &angle, XMLoadFloat4(&XMFLOAT4(&mAcd.controllers[controllerIndex].rot_quat[0])));

		axis = XMVectorSet(-XMVectorGetX(axis), XMVectorGetY(axis), -XMVectorGetZ(axis), 0.0f);

		XMVECTOR rotationQuat = XMQuaternionRotationAxis(axis, angle);

		return rotationQuat;
	}
	
	return XMQuaternionIdentity();
}
예제 #28
0
파일: main.cpp 프로젝트: GainLee/OculusSDK
    void MainLoop()
    {
	    Layer[0] = new VRLayer(Session);

	    // Create a trivial model to represent the left controller
	    TriangleSet cube;
	    cube.AddSolidColorBox(0.05f, -0.05f, 0.05f, -0.05f, 0.05f, -0.05f, 0xff404040);
	    Model * controller = new Model(&cube, XMFLOAT3(0, 0, 0), XMFLOAT4(0, 0, 0, 1), new Material(new Texture(false, 256, 256, Texture::AUTO_CEILING)));
	
	    // Main loop
	    while (HandleMessages())
	    {
		    // We don't allow yaw change for now, as this sample is too simple to cater for it.
		    ActionFromInput(1.0f,false);
		    ovrTrackingState hmdState = Layer[0]->GetEyePoses();

		    //Write position and orientation into controller model.
		    controller->Pos = XMFLOAT3(XMVectorGetX(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.x,
			                           XMVectorGetY(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.y,
			                           XMVectorGetZ(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.z);
		    controller->Rot = XMFLOAT4(hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.x, 
                                       hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.y,
			                           hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.z, 
                                       hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.w);

		    //Button presses are modifying the colour of the controller model below
		    ovrInputState inputState;
		    ovr_GetInputState(Session, ovrControllerType_Touch, &inputState);

		    for (int eye = 0; eye < 2; ++eye)
		    {
			    XMMATRIX viewProj = Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye);

			    // Render the controller model
			    controller->Render(&viewProj, 1, inputState.Buttons & ovrTouch_X ? 1.0f : 0.0f,
				                                 inputState.Buttons & ovrTouch_Y ? 1.0f : 0.0f, 1, true);
		    }

		    Layer[0]->PrepareLayerHeader();
		    DistortAndPresent(1);
	    }

        delete controller;
    }
예제 #29
0
void  SceneNode::update_collision_tree(XMMATRIX* world, float scale)
{
	// the m_local_world_matrix matrix will be used to calculate the local transformations for this node
	XMMATRIX m_local_world_matrix = XMMatrixIdentity();

	m_local_world_matrix = XMMatrixRotationX(XMConvertToRadians(m_xangle));
	m_local_world_matrix *= XMMatrixRotationY(XMConvertToRadians(m_yangle));
	m_local_world_matrix *= XMMatrixRotationZ(XMConvertToRadians(m_zangle));

	m_local_world_matrix *= XMMatrixScaling(m_scale, m_scale, m_scale);

	m_local_world_matrix *= XMMatrixTranslation(m_x, m_y, m_z);

	// the local matrix is multiplied by the passed in world matrix that contains the concatenated
	// transformations of all parent nodes so that this nodes transformations are relative to those
	m_local_world_matrix *= *world;

	// calc the world space scale of this object, is needed to calculate the  
	// correct bounding sphere radius of an object in a scaled hierarchy
	m_world_scale = scale * m_scale;

	XMVECTOR v;
	if (m_p_model)
	{
		v = XMVectorSet(m_p_model->GetBoundingSphere_x(),
			m_p_model->GetBoundingSphere_y(),
			m_p_model->GetBoundingSphere_z(), 0.0);
	}
	else v = XMVectorSet(0, 0, 0, 0); // no model, default to 0

	// find and store world space bounding sphere centre
	v = XMVector3Transform(v, m_local_world_matrix);
	m_world_centre_x = XMVectorGetX(v);
	m_world_centre_y = XMVectorGetY(v);
	m_world_centre_z = XMVectorGetZ(v);

	// traverse all child nodes, passing in the concatenated world matrix and scale
	for (int i = 0; i< m_children.size(); i++)
	{
		m_children[i]->update_collision_tree(&m_local_world_matrix, m_world_scale);
	}
}
예제 #30
0
XMVECTOR LimitAngle(const XMVECTOR& quat, const XMVECTOR& rotmin, const XMVECTOR& rotmax)
{
	XMVECTOR rot_xyz = GetAngle(quat);
	/*	XMMATRIX mtx = XMMatrixRotationQuaternion(quat);

	//ZYX Y=-90〜90°Y軸=ねじり方向
	float rx = -atan2f(XMVectorGetY(mtx.r[2]),XMVectorGetZ(mtx.r[2]));
	float ry = asinf(XMVectorGetX(mtx.r[2]));
	float rz = -atan2f(XMVectorGetX(mtx.r[1]),XMVectorGetX(mtx.r[0]));
	XMVECTOR rot_xyz = {rx,ry,rz,0};
	*rotang_before = rot_xyz;
	*/
	rot_xyz = XMVectorMax(rot_xyz, rotmin);
	rot_xyz = XMVectorMin(rot_xyz, rotmax);
	XMMATRIX mtx = XMMatrixRotationZ(XMVectorGetZ(rot_xyz));
	mtx = XMMatrixMultiply(mtx, XMMatrixRotationY(XMVectorGetY(rot_xyz)));
	mtx = XMMatrixMultiply(mtx, XMMatrixRotationX(XMVectorGetX(rot_xyz)));

	return XMQuaternionRotationMatrix(mtx);
}