source: GTP/trunk/App/Demos/Vis/CHC_revisited/SceneQuery.cpp @ 2764

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