source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp @ 2782

Revision 2782, 2.1 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include "SceneQuery.h"
2#include "glInterface.h"
3#include "Vector3.h"
4#include "Camera.h"
5#include "SceneQuery.h"
6#include "RenderTraverser.h"
7
8
9void startil();
10void stopil();
11
12
13namespace CHCDemoEngine
14{
15
16using namespace std;
17
18
19const static int viewport[4] = {0, 0, 512, 512};
20//static DepthComponent<float> *sDepth = NULL;
21
22
23
24SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer):
25mSceneBox(sceneBox)
26{
27        Prepare(renderer);
28}
29
30
31bool SceneQuery::CalcIntersection(Vector3 &pt)
32{
33        int px = (pt.x - mSceneBox.Min(0)) * (viewport[2] - 1) / mSceneBox.Size(0);
34        int py = (pt.y - mSceneBox.Min(2)) * (viewport[3] - 1) /  mSceneBox.Size(2);
35
36        const float d = 1.0f;// - sDepth->getPixel(px, py);
37
38        if (d > 0.0f)
39        {
40                pt.z = mSceneBox.Size(2) * d + mSceneBox.Min(2);
41                cout << "new depth " << pt.z << " (" << d << ")" << endl;
42
43                return true;
44        }
45
46        return false;
47}
48
49
50void SceneQuery::Prepare(RenderTraverser *renderer)
51{
52        cout << "Preparing scene queries" << endl;
53
54        // center camera on "highest" point
55        Vector3 pos;
56
57        pos.x = mSceneBox.Center(0);
58        pos.y = mSceneBox.Max(1);
59        pos.z = mSceneBox.Center(2);
60
61        // for ortho cam this is the width
62        const Vector3 len = mSceneBox.Size();
63
64        Camera *orthoCam = new Camera(len.x, len.y);
65        //orthoCam->SetOrtho(true);
66
67        orthoCam->SetNear(0.0f);
68        //orthoCam->SetFar(len.z);
69
70        orthoCam->SetPosition(pos);
71
72        cout << "fov: " << orthoCam->GetFov() << endl;
73        cout << "near: " << orthoCam->GetNear() << endl;
74        //cout << "far: " << orthoCam->GetFar() << endl;
75        cout << "aspect: " << orthoCam->GetAspect() << endl;
76
77        cout << "pos: " << orthoCam->GetPosition() << endl;
78        cout << "view: " << orthoCam->GetDirection() << endl;
79        cout << "up: " << orthoCam->GetUpVector() << endl;
80
81        //orthoCam->SetDirection(Vector3(0, 1, 0));
82        //orthoCam->Yaw(M_PI * 0.5f);
83       
84        renderer->SetCamera(orthoCam);
85
86        //OffscreenRenderArea *of = new OffscreenRenderArea();
87        //of->Init(viewport[2], viewport[3]);
88
89        renderer->RenderScene();
90        //sDepth = of->GetDepthFloat();
91
92        delete orthoCam;
93}
94
95}
Note: See TracBrowser for help on using the repository browser.