3 class SimplePlane : Object
5 void Create(DisplaySystem displaySystem)
8 InitializeMesh(displaySystem);
10 mesh.Allocate( { vertices = true, texCoords1 = true, normals = true }, 4, displaySystem);
11 group = mesh.AddPrimitiveGroup({ vertexRange = true, primitiveType = quads }, 0);
14 mesh.LockPrimitiveGroup(group);
15 mesh.vertices[0] = { -0.5f, 0, -.5f };
16 mesh.vertices[1] = { -0.5f, 0, .5f };
17 mesh.vertices[2] = { 0.5f, 0, .5f };
18 mesh.vertices[3] = { 0.5f, 0, -.5f };
19 mesh.texCoords[3] = { 1, 1 };
20 mesh.texCoords[2] = { 1, 0 };
21 mesh.texCoords[1] = { 0, 0 };
22 mesh.texCoords[0] = { 0, 1 };
23 mesh.normals[0] = { 0, 1, 0 };
24 mesh.normals[1] = { 0, 1, 0 };
25 mesh.normals[2] = { 0, 1, 0 };
26 mesh.normals[3] = { 0, 1, 0 };
27 mesh.UnlockPrimitiveGroup(group);
29 SetMinMaxRadius(true);
34 public class PictureRotate : Window
41 public property BitmapResource image
47 RemoveResource(image);
49 material.baseMap = image ? image.bitmap : null;
50 material.opacity = 0.5f;
51 material.flags.translucent = true;
55 public property Degrees angle
60 plane.transform.orientation = Euler { angle, 0, 0 };
61 plane.UpdateTransform();
67 public property double zoom
81 position = { 0, -275, 0 };
83 orientation = Euler { 0, 90, 0 };
90 material.baseMap = image.bitmap;
91 plane.Create(displaySystem);
92 plane.transform.scaling = { 1, 1, 1 };
94 // plane.transform.scaling = { image.bitmap.width, 1.5f, image.bitmap.height };
95 //plane.transform.scaling = { Max(image.bitmap.width, image.bitmap.height), 1.5f, Max(image.bitmap.width, image.bitmap.height) };
96 //camera.aspectRatio = 1.0f;
97 if(!image.bitmap) return false;
98 w = image.bitmap.width;
99 h = image.bitmap.height;
100 camera.position.y = -Max(image.bitmap.height, image.bitmap.height) / sqrt(2);
102 plane.UpdateTransform();
106 mesh.vertices[0] = { -w/2.0f, 0, -h/2.0f };
107 mesh.vertices[1] = { -w/2.0f, 0, h/2.0f };
108 mesh.vertices[2] = { w/2.0f, 0, h/2.0f };
109 mesh.vertices[3] = { w/2.0f, 0, -h/2.0f };
112 plane.mesh.ApplyMaterial(material);
113 plane.mesh.ApplyTranslucency(plane);
118 bool OnResizing(int * w, int * h)
120 Size size = initSize;
121 Anchor anchor = this.anchor;
122 if(image && image.bitmap)
124 Bitmap bitmap = image.bitmap;
125 double m = Max(bitmap.width, bitmap.height) * zoom * sqrt(2);
126 if(!size.w && (!anchor.left.type || !anchor.right.type))
128 if(!size.h && (!anchor.top.type || !anchor.bottom.type))
133 if(!size.w && (!anchor.left.type || !anchor.right.type))
135 if(!size.h && (!anchor.top.type || !anchor.bottom.type))
141 void OnResize(int width, int height)
143 camera.Setup(width, height, null);
146 void OnRedraw(Surface surface)
149 surface.Clear(depthBuffer);
150 display.SetCamera(surface, camera);
151 display.DrawObject(plane);
152 display.SetCamera(surface, null);
159 flags = { translucent = true, noFog = true, doubleSided = true };
161 SimplePlane plane { };
164 static Degrees startAngle;
165 static int startY, startX;
166 static bool rotating;
170 displayDriver = "OpenGL",
174 image = { (((GuiApplication)__thisModule).argc > 1) ? ((GuiApplication)__thisModule).argv[1] : "image.png" };
177 bool OnLeftButtonDown(int x, int y, Modifiers mods)
179 MenuWindowMove(null, mods);
183 bool OnRightButtonDown(int x, int y, Modifiers mods)
196 bool OnRightButtonUp(int x, int y, Modifiers mods)
206 bool OnMouseMove(int x, int y, Modifiers mods)
210 int dx = x-startX, dy = y-startY;
211 if(Abs(dx) > Abs(dy))
212 property::angle = startAngle + Degrees { dx/2.0 };
214 property::angle = startAngle + Degrees { dy/2.0 };
219 bool OnKeyHit(Key key, unichar ch)
221 if(key == escape) Destroy(0);
222 else if(key == wheelDown)
223 property::zoom /= 1.1;
224 else if(key == wheelUp)
225 property::zoom *= 1.1;