#include "SceneQuery.h" #include "glInterface.h" #include "Vector3.h" #include "Camera.h" #include "SceneQuery.h" #include "RenderTraverser.h" void startil(); void stopil(); namespace CHCDemoEngine { using namespace std; const static int viewport[4] = {0, 0, 512, 512}; //static DepthComponent *sDepth = NULL; SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer): mSceneBox(sceneBox) { Prepare(renderer); } bool SceneQuery::CalcIntersection(Vector3 &pt) { int px = (pt.x - mSceneBox.Min(0)) * (viewport[2] - 1) / mSceneBox.Size(0); int py = (pt.y - mSceneBox.Min(2)) * (viewport[3] - 1) / mSceneBox.Size(2); const float d = 1.0f;// - sDepth->getPixel(px, py); if (d > 0.0f) { pt.z = mSceneBox.Size(2) * d + mSceneBox.Min(2); cout << "new depth " << pt.z << " (" << d << ")" << endl; return true; } return false; } void SceneQuery::Prepare(RenderTraverser *renderer) { cout << "Preparing scene queries" << endl; // center camera on "highest" point Vector3 pos; pos.x = mSceneBox.Center(0); pos.y = mSceneBox.Max(1); pos.z = mSceneBox.Center(2); // for ortho cam this is the width const Vector3 len = mSceneBox.Size(); Camera *orthoCam = new Camera(len.x, len.y); //orthoCam->SetOrtho(true); orthoCam->SetNear(0.0f); //orthoCam->SetFar(len.z); orthoCam->SetPosition(pos); cout << "fov: " << orthoCam->GetFov() << endl; cout << "near: " << orthoCam->GetNear() << endl; //cout << "far: " << orthoCam->GetFar() << endl; cout << "aspect: " << orthoCam->GetAspect() << endl; cout << "pos: " << orthoCam->GetPosition() << endl; cout << "view: " << orthoCam->GetDirection() << endl; cout << "up: " << orthoCam->GetUpVector() << endl; //orthoCam->SetDirection(Vector3(0, 1, 0)); //orthoCam->Yaw(M_PI * 0.5f); renderer->SetCamera(orthoCam); //OffscreenRenderArea *of = new OffscreenRenderArea(); //of->Init(viewport[2], viewport[3]); renderer->RenderScene(); //sDepth = of->GetDepthFloat(); delete orthoCam; } }