Esempio n. 1
0
Ogre::Vector3 SpawnPositionCalculator::GetOgrePositionRelative(const CameraSpacePoint& limbPosition, const CameraSpacePoint& referencePoint)
{
	{
		CameraSpacePoint result = CameraSpacePoint();

		result.X = (-limbPosition.X - -referencePoint.X);
		result.Y = (limbPosition.Y - referencePoint.Y);
		result.Z = (limbPosition.Z - referencePoint.Z);
		
		float mag = Ogre::Math::Sqrt(result.X * result.X + result.Y * result.Y + result.Z * result.Z);

		float div = 1.0f / mag;
		
		return Ogre::Vector3(result.X * div * PROBENDER_HALF_EXTENTS.x, 
			result.Y * div * PROBENDER_HALF_EXTENTS.y, result.Z * div * PROBENDER_HALF_EXTENTS.z);
	}
}
//--------------------------------------------------------------
void ofApp::draw(){
	ofSetColor(255);
	colorImage.draw(0, 0);

	//比較する部分
	unsigned int comparingPart = JointType::JointType_SpineBase;
	CameraSpacePoint center = CameraSpacePoint();
	const float distanceThreshold = 1.5f;

	//ユーザーのナンバーと距離
	vector<float>distanceList;
	if (distanceList.size() != 0) distanceList.clear();
	vector<float>playerNum;
	if (playerNum.size() != 0) playerNum.clear();


	for (int i = 0; i < jointList.size(); i++) {

		//比較する間接位置が追跡状態になければ対象外
		if (jointList[i].joint[comparingPart].TrackingState == TrackingState::TrackingState_NotTracked) {
			continue;
		}

		//追跡状態なら値をとる
		if (jointList[i].joint[comparingPart].TrackingState == TrackingState::TrackingState_Tracked) {
			ofVec3f camspace = ofVec3f(center.X,center.Y,center.Z);
			ofVec3f nowDistance = ofVec3f(jointList[i].joint[comparingPart].Position.X, jointList[i].joint[comparingPart].Position.Y, jointList[i].joint[comparingPart].Position.Z);

			//中心からの距離が近い人を選択
			float distance = camspace.distance(nowDistance);
			if (distance < distanceThreshold) {


				distanceList.push_back(distance);
				playerNum.push_back(i);

			}

		}

		//最後になったら
		if (i == jointList.size() - 1)	{

			cout <<  distanceList.size() << endl;

			float minNum;
			float humanNum = 0;

			if (distanceList.size() != 0) {
				//距離を比較
				for (int i = 0; i < distanceList.size(); i++) {
					if (i == 0) {
						cout << "最初の距離の比較" << endl;

						minNum = distanceList[i];
						humanNum = playerNum[i];
					}else{

						//比較
						if (minNum >= distanceList[i]) {
							minNum = distanceList[i];
							humanNum = i;
						}else{
							
						}

					}
				}

				//関節描画
				for (int type = 0; type < JointType_Count; type++) {
					cout << "描画" << endl;

					ColorSpacePoint colorSpacePoint = { 0 };
					pCoordinateMapper->MapCameraPointToColorSpace( jointList[humanNum].joint[type].Position, &colorSpacePoint );
					int x = static_cast<int>( colorSpacePoint.X );
					int y = static_cast<int>( colorSpacePoint.Y );
					if( ( x >= 0 ) && ( x < colorWidth ) && ( y >= 0 ) && ( y < colorHeight ) ){

						ofSetColor(255,0,0);
						ofCircle(x,y,10);

					}
				}
			}





		}



	}


	/*
	//間接部分の描画
	for (int i = 0; i < jointList.size(); i++) {
	for (int type = 0; type < JointType_Count; type++) {
	ColorSpacePoint colorSpacePoint = { 0 };
	pCoordinateMapper->MapCameraPointToColorSpace( jointList[i].joint[type].Position, &colorSpacePoint );
	int x = static_cast<int>( colorSpacePoint.X );
	int y = static_cast<int>( colorSpacePoint.Y );
	if( ( x >= 0 ) && ( x < colorWidth ) && ( y >= 0 ) && ( y < colorHeight ) ){

	ofSetColor(255,0,0);
	ofCircle(x,y,10);

	}
	}
	}*/

}