OSDN Git Service

123123
[psychlops/cpp.git] / win32gl / test / NewFuncFirm2.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;
3
4 /*
5 namespace Psychlops {
6         Point toGround(Point p, double high) {
7                 Point r;
8                 r.z = 0;
9                 r.x = p.x / ((high-p.z)/high);
10                 r.y = p.y / ((high-p.z)/high);
11                 return r;
12         }
13 }
14 void psychlops_main() {
15         Canvas cnv(Canvas::window);
16         Psychlops::Point p[4];
17         p[0]= toGround(Psychlops::Point(60, 60, 60), 120);
18         p[1]= toGround(Psychlops::Point(-60, 60, 60), 120);
19         p[2]= toGround(Psychlops::Point(-60, 60, 0), 120);
20         p[3]= toGround(Psychlops::Point(60, 60, 0), 120);
21         for(int i=0; i<4; i++) { p[i].x+=100; }
22         Image img("monalisa1.png");
23         img.cache();
24         cnv.clear();
25         cnv.drawImage(img, p[0], p[1], p[2], p[3]);
26         cnv.flip();
27         while(!Keyboard::esc.pushed()) {
28         }
29 }
30 */
31
32 namespace Psychlops {
33 namespace VirtualReality {
34
35         class Light {
36         public:
37                 enum { AMBIENT, DIRECTIONAL };
38                 enum Material { DIFFUSE, SPECULAR };
39                 Point position, direction;
40                 void lookAt(Point target);
41                 void locateToLook(Psychlops::Point pos, Point target);
42                 void apply(Drawable3D &target = *Drawable3D::prime);
43         };
44
45         class Camera {
46         public:
47                 double top, bottom, left, right, near, far;
48 //              Point datum, direction;
49                 double topdir;
50                 Camera() {
51                         top = 100;
52                         bottom = -100;
53                         left = -100;
54                         right = 100;
55                         near = 100;
56                         far = 200;
57                 }
58                 void set(Point position, Point target, double top_direction) {
59                 }
60                 void lookAt(Point target, double top_direction) {
61                 }
62                 void draw(Canvas &target = *Canvas::prime);
63
64                 Group contents;
65                 Light lights[4];
66         };
67         void Camera::draw(Canvas &target) {
68                 target.popMatrices();
69                 target.RenderModeSmooth3D(left, right, top, bottom, near, far);
70                 contents.draw(target);
71                 target.popMatrices();
72                 target.pushPixToPixProjection();
73         }
74 }
75 }
76
77 double x=0, y=0;
78
79 void psychlops_main() {
80         Canvas cnvs(Canvas::window);
81         Mouse::show();
82
83         Interval rng;
84         Widgets::Button but(L"ใƒ†ใ‚นใƒˆ");
85         but.centering().shift(100,100);
86         Widgets::Dial dial(40);
87         dial.link(y, 360);
88         dial.centering().shift(-100,0);
89
90         Image gabor(200,200, Image::RGBA);
91         for(int iy=0; iy<200; iy++) {
92                 for(int ix=0; ix<200; ix++) {
93                         gabor.pix(ix,iy,Color(.5+.5*sin(ix/10.0)));
94                         gabor.alpha(ix,iy, exp( -((ix-100)*(ix-100)+(iy-100)*(iy-100)) /2.0 / (30*30) ) );
95                 }
96         }
97         gabor.cache();
98         gabor.centering(0,0);
99
100         VirtualReality::Camera cam;
101         Group h[6];
102         cam.contents.axis.set(1,1,0);
103         cam.contents.scaling.set(.5,.5,.5);
104         cam.contents.centering(0,0,0).shift(0,0,100);
105         Widgets::Slider
106                 sl1(cam.contents.scaling.x, 0<=rng<=100, 1.0, 10.0),
107                 sl2(cam.contents.scaling.y, 0<=rng<=100, 1.0, 10.0),
108                 sl3(cam.contents.scaling.z, 0<=rng<=100, 1.0, 10.0);
109         sl1.shift(100,10);
110         sl2.shift(100,30);
111         sl3.shift(100,50);
112         Widgets::Slider
113                 sl11(cam.left, -1000<=rng<=1000, 1.0, 10.0),
114                 sl12(cam.right, -1000<=rng<=1000, 1.0, 10.0),
115                 sl13(cam.top, -1000<=rng<=1000, 1.0, 10.0),
116                 sl14(cam.bottom, -1000<=rng<=1000, 1.0, 10.0),
117                 sl15(cam.near, -1000<=rng<=1000, 1.0, 10.0),
118                 sl16(cam.far, -1000<=rng<=1000, 1.0, 10.0);
119         sl11.shift(100,110);
120         sl12.shift(100,130);
121         sl13.shift(100,150);
122         sl14.shift(100,170);
123         sl15.shift(100,190);
124         sl16.shift(100,210);
125         
126         for(int i=0; i<6; i++) {
127                 h[i].append(gabor);
128                 cam.contents.append(h[i]);
129         }
130         h[0].shift(0,0,100);
131         h[1].shift(0,0,-100);
132         h[2].shift(0,100,0);
133         h[2].axis.set(1,0,0);
134         h[2].rotation = 90;
135         h[3].shift(0,-100,0);
136         h[3].axis.set(1,0,0);
137         h[3].rotation = 90;
138         h[4].shift(100,0,0);
139         h[4].axis.set(0,1,0);
140         h[4].rotation = 90;
141         h[5].shift(-100,0,0);
142         h[5].axis.set(0,1,0);
143         h[5].rotation = 90;
144         
145         while(!Keyboard::esc.pushed()) {
146                 cnvs.clear( but.pushed() ? Color::red : Color::gray );
147                 sl1.draw();
148                 sl2.draw();
149                 sl3.draw();
150                 sl11.draw();
151                 sl12.draw();
152                 sl13.draw();
153                 sl14.draw();
154                 sl15.draw();
155                 sl16.draw();
156                 cnvs.var(x, 200, 100);
157                 cnvs.var(y, 200, 130);
158                 cam.contents.rotation = y;
159                 cam.draw(cnvs);
160                 but.draw();
161                 dial.draw();
162                 cnvs.flip();
163         }
164 }