int OSCSender::getMostLegitimateBody() {
	if (bodies.size() == 1) {
		return 0;
	}
	UINT64 legitimate = getMostCenteredBodyId();
	if (legitimate != currLegitimateTrackingId) {
		if (legitimate != newcomerId) {
			WinLog(L"New Comer", legitimate);
			newcomerId = legitimate;
			newcomerNumPresence = 0;
		}
		if (newcomerNumPresence++ > 60) {
			WinLog(L"New legitimate", legitimate);
			currLegitimateTrackingId = legitimate;
			newcomerId = -1;
			newcomerNumPresence = 0;
		}
	}
	else {
		if (newcomerNumPresence > 0) {
			WinLog(L"Reset new comer presence", legitimate);
			newcomerNumPresence = 0;
		}
	}

	if (currLegitimateTrackingId != -1) {
		return getBodyIdFromTrackingId(currLegitimateTrackingId);
	}
	return -1;
}
void OSCSender::updateBodyCount(){
	int bodyCount = bodies.size();
	if (bodyCount != prevBodyCount) {
		if (prevBodyCount == 0 && bodyCount > 0) {
			currLegitimateTrackingId = bodies[0].id;
			WinLog(L"First user (legitimate)", currLegitimateTrackingId);
			sendMessage("/first_user_entered");
		}
		else if (prevBodyCount > 0 && bodyCount == 0) {
			WinLog(L"Lost last user", currLegitimateTrackingId);
			currLegitimateTrackingId = -1;
			newcomerNumPresence = 0;
			newcomerId = -1;
			sendMessage("/last_user_left");
		}
		prevBodyCount = bodyCount;
	}
}
bool GraphicsClass::Initialize(HWND hwnd)
{
	bool result;

	// Create the Direct3D object.
	m_D3D = new D3DClass();
	if(!m_D3D)
	{
		MessageBox(hwnd, L"Could not create the D3DClass object!", L"Error", MB_OK);
		return false;
	}

	// Initialize the Direct3D object.
	result = m_D3D->Initialize(hwnd, FULL_SCREEN);
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize Direct3D!", L"Error", MB_OK);
		return false;
	}

	// Create the Sphere object.
	m_Sphere = new SphereModelClass();
	if(!m_Sphere)
	{
		MessageBox(hwnd, L"Could not create the Sphere object.", L"Error", MB_OK);
		return false;
	}

	// Initialize the Sphere object.
	result = m_Sphere->Initialize(m_D3D->GetDevice());
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize the Sphere object.", L"Error", MB_OK);
		return false;
	}

	// Create the cube8 object.
	m_Cube = new CubeModelClass();
	if(!m_Cube)
	{
		MessageBox(hwnd, L"Could not create the cube8 object.", L"Error", MB_OK);
		return false;
	}

	// Initialize the cube object.
	result = m_Cube->Initialize(m_D3D->GetDevice());
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize the cube8 object.", L"Error", MB_OK);
		return false;
	}

	// Create the Plane field object.
	m_PlaneModel = new PlaneModelClass();
	if(!m_PlaneModel)
	{
		MessageBox(hwnd, L"Could not create the Plane field object.", L"Error", MB_OK);
		return false;
	}

	// Initialize the model object.
	result = m_PlaneModel->Initialize(m_D3D->GetDevice());
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize the Plane field object.", L"Error", MB_OK);
		return false;
	}

	// Create the camera object.
	m_Transform = new TransformationClass();
	if(!m_Transform)
	{
		MessageBox(hwnd, L"Could not create the camera object.", L"Error", MB_OK);
		return false;
	}

	m_Transform->Initialize(hwnd);
	// Set the initial position of the camera.
	m_Transform->SetCameraPosition(D3DXVECTOR3(0.0f,5.0f, -10.0f));
	m_Transform->SetCameraTarget(D3DXVECTOR3(0.0f, 2.0f, 0.0f));
	m_Transform->SetCameraUPV(D3DXVECTOR3(0.0f, 1.0f, 0.0f));

	// Create the trivial shader object.
	m_LightingShader = new LightingShaderClass();
	if(!m_LightingShader)
	{
		MessageBox(hwnd, L"Could not create the color shader object.", L"Error", MB_OK);
		return false;
	}

	// Initialize the trivial shader object.
	result = m_LightingShader->Initialize(m_D3D->GetDevice(), hwnd);
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize the color shader object.", L"Error", MB_OK);
		return false;
	}

	// Create the first light object.
	m_Light = new LightClass;
	if(!m_Light)
	{
		return false;
	}

	// Initialize the first light object.
	m_Light->SetLightPosition(-3.0f,8.0f, -8.0f);
	m_Light->SetLightDiffuseColor(255.0f, 255.0f, 0.0f, 1.0f);
	m_Light->SetLightAmbient(0.1f, 0.1f, 0.1f, 0.0f);
	m_Light->SetLightAtt(0.4f, 0.02f, 0.0f);
	m_Light->SetLightDir(0.4f, -1.0f, 1.0f);
	m_Light->SetLightCone(10.0f);
	m_Light->SetLightRange(1000.0f);

	
	LightColorBufferType a = m_Light->GetLightColorBuffer();		
	WinLog(L"The Answer x", (float)a.myLightPosition.x);
		WinLog(L"The Answer y", (float)a.myLightPosition.y);
			WinLog(L"The Answer z", (float)a.myLightPosition.z);

	return true;
}
Example #4
0
GLuint Label::LoadBMPTexture(const char * imagepath) {


	unsigned char header[54]; // Each BMP file begins by a 54-bytes header
	unsigned int dataPos;     // Position in the file where the actual data begins
	unsigned int imageSize;   // = width*height*3
	// Actual RGB data


	// Open the file
	FILE * file = fopen(imagepath, "rb");
	if (!file) {
		printf("Image could not be opened\n");
		WinLog(L"Image could not be opened");
		return 0;
	}

	// The first thing in the file is a 54-bytes header. It contains information such as “Is this file really a BMP file?”, the size of the image, the number of bits per pixel, etc. So let’s read this header :
	if (fread(header, 1, 54, file) != 54) { // If not 54 bytes read : problem
		printf("Not a correct BMP file\n");
		WinLog(L"Not a correct BMP file\n");
		return false;
	}

	if (header[0] != 'B' || header[1] != 'M') {
		printf("Not a correct BMP file\n");
		WinLog(L"Not a correct BMP file\n");
		return 0;
	}

	// Read ints from the byte array
	dataPos = *(int*)&(header[0x0A]);
	imageSize = *(int*)&(header[0x22]);
	fileWidth = *(int*)&(header[0x12]);
	fileHeight = *(int*)&(header[0x16]);

	// Some BMP files are misformatted, guess missing information
	if (imageSize == 0)    imageSize = fileWidth*fileHeight * 3; // 3 : one byte for each Red, Green and Blue component
	if (dataPos == 0)      dataPos = 54; // The BMP header is done that way

	textureData = new unsigned char[imageSize];

	// Read the actual data from the file into the buffer
	fread(textureData, 1, imageSize, file);

	//Everything is in memory now, the file can be closed
	fclose(file);

	float * data;
	// Define some data to upload into the texture
	data = new float[fileWidth * fileHeight * 4];

	// generate_texture() is a function that fills memory with image data
	//generate_texture(data, fileWidth, fileHeight);

	// Create one OpenGL texture
	glGenTextures(1, &textureID);
	glBindTexture(GL_TEXTURE_2D, textureID);

	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fileWidth, fileHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, textureData);

	glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB16, fileWidth, fileHeight);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 0);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, fileWidth, fileHeight, GL_BGR, GL_UNSIGNED_BYTE, textureData);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

    return 0;
}