void PositionJavaPinButtonExample::Project (const Eegeo::Space::LatLongAltitude& location, Eegeo::v3& screenPosition)
{
	//project a 3D Ecef location to the screen
	Eegeo::m44 finalMatrix;

	Eegeo::Camera::RenderCamera renderCamera(GetGlobeCameraController().GetRenderCamera());

	Eegeo::m44::Mul (finalMatrix,
	                 renderCamera.GetProjectionMatrix(),
	                 renderCamera.GetViewMatrix());

	Eegeo::v3 local = (location.ToECEF() - renderCamera.GetEcefLocation()).ToSingle();
	Eegeo::v4 inVector(local, 1.0f);

	// get clip space coords
	Eegeo::v4 outVector = Eegeo::v4::Mul(inVector, finalMatrix);

	// divide through by w to get normalized device space coords -- range [-1, 1]
	screenPosition.SetX((outVector.GetX()/outVector.GetW()));
	screenPosition.SetY((outVector.GetY()/outVector.GetW()));
	screenPosition.SetZ((outVector.GetZ()/outVector.GetW()));

	// transform from [-1, 1] to [0, 1]
	screenPosition.SetX((screenPosition.GetX() + 1.0f) * 0.5f);
	screenPosition.SetY(1.0f - ((screenPosition.GetY() + 1.0f) * 0.5f));

	float viewport[] = {0, 0, renderCamera.GetViewportWidth(), renderCamera.GetViewportHeight()};

	// transform from [0, 1] to screen coords.
	screenPosition.SetX((screenPosition.GetX()*(viewport[2]-viewport[0])) + viewport[0]);
	screenPosition.SetY((screenPosition.GetY()*(viewport[3]-viewport[1])) + viewport[1]);
}
void PositionJavaPinButtonExample::Draw()
{
	//lazily create the pin button when we start drawing so it is not displayed on top of the loading screen
	if(m_world.Initialising())
	{
		return;
	}
	else if(m_buttonID == 0)
	{
		CreateButton();
	}

	//get an env for the current thread
	//
	//AndroidSafeNativeThreadAttachment will detach the thread if required at the end of the method
	AndroidSafeNativeThreadAttachment attached(m_nativeState);
	JNIEnv* env = attached.envForThread;

	//calculate a screen position for the pin based on an ECEF location
	const Eegeo::Space::LatLongAltitude pinLocation = Eegeo::Space::LatLongAltitude::FromDegrees(37.7858,-122.401, 0.f);
	Eegeo::v3 screenPosition;
	Project(pinLocation, screenPosition);

	//update the screen position of the pin using the cached update method on the cached object reference to
	//the pin controller, using the parameters we have calculated and the handle to the pin created earlier
	env->CallVoidMethod(
	    m_hudPinController,
	    m_updateLocationMethodId,
	    m_buttonID,
	    screenPosition.GetX(),
	    screenPosition.GetY()
	);
}
 void WorldPinsScaleController::GetScreenLocation(const WorldPinItemModel& worldPinItemModel,
         Eegeo::v2& screenLocation,
         const Eegeo::Camera::RenderCamera& renderCamera) const
 {
     Eegeo::dv3 ecefLocation;
     m_worldPinsService.GetPinEcefAndScreenLocations(worldPinItemModel, ecefLocation, screenLocation);
     Eegeo::v3 cameraLocal = (ecefLocation - renderCamera.GetEcefLocation()).ToSingle();
     Eegeo::v3 screenPos;
     renderCamera.Project(cameraLocal, screenPos);
     screenLocation.Set(screenPos.GetX(), screenPos.GetY());
 }
コード例 #4
0
    void BoundsVisualiser::Build(const Eegeo::v3& minExtents, const Eegeo::v3& maxExtents)
    {
        Vertex vertexBuffer[NumVerts];
        u16 indexBuffer[NumIndices];
        
        float minX = minExtents.GetX();
        float minY = minExtents.GetY();
        float minZ = minExtents.GetZ();
        float maxX = maxExtents.GetX();
        float maxY = maxExtents.GetY();
        float maxZ = maxExtents.GetZ();

        std::vector<Eegeo::v3> verts;
        verts.push_back(Eegeo::v3(minX, minY, minZ));
        verts.push_back(Eegeo::v3(minX, minY, maxZ));
        verts.push_back(Eegeo::v3(minX, maxY, minZ));
        verts.push_back(Eegeo::v3(minX, maxY, maxZ));
        verts.push_back(Eegeo::v3(maxX, minY, minZ));
        verts.push_back(Eegeo::v3(maxX, minY, maxZ));
        verts.push_back(Eegeo::v3(maxX, maxY, minZ));
        verts.push_back(Eegeo::v3(maxX, maxY, maxZ));
        
        for(size_t i = 0; i < NumVerts; ++ i)
        {
            vertexBuffer[i].x = verts[i].GetX();
            vertexBuffer[i].y = verts[i].GetY();
            vertexBuffer[i].z = verts[i].GetZ();
        }
        
        indexBuffer[0] = 0;
        indexBuffer[1] = 1;
        indexBuffer[2] = 2;
        
        indexBuffer[3] = 1;
        indexBuffer[4] = 3;
        indexBuffer[5] = 2;
        
        indexBuffer[6] = 4;
        indexBuffer[7] = 5;
        indexBuffer[8] = 6;
        
        indexBuffer[9] = 5;
        indexBuffer[10] = 7;
        indexBuffer[11] = 6;
        
        indexBuffer[12] = 4;
        indexBuffer[13] = 1;
        indexBuffer[14] = 0;
        
        indexBuffer[15] = 4;
        indexBuffer[16] = 5;
        indexBuffer[17] = 1;
        
        indexBuffer[18] = 5;
        indexBuffer[19] = 3;
        indexBuffer[20] = 1;
        
        indexBuffer[21] = 7;
        indexBuffer[22] = 3;
        indexBuffer[23] = 5;
        
        indexBuffer[24] = 2;
        indexBuffer[25] = 3;
        indexBuffer[26] = 7;
        
        indexBuffer[27] = 7;
        indexBuffer[28] = 6;
        indexBuffer[29] = 2;
        
        indexBuffer[30] = 4;
        indexBuffer[31] = 0;
        indexBuffer[32] = 6;
        
        indexBuffer[33] = 2;
        indexBuffer[34] = 6;
        indexBuffer[35] = 0;
        
        InitMeshGLBuffers(vertexBuffer, indexBuffer);
    }