Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: samples/GoogleIO-2009/step02.html

Issue 149438: Add Google IO sample. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/GoogleIO-2009/step01.html ('k') | samples/GoogleIO-2009/step03.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 Copyright 2009, Google Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following disclaimer
13 in the documentation and/or other materials provided with the
14 distribution.
15 * Neither the name of Google Inc. nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 -->
31 <!--
32 Google I/O O3D Sample.
33
34 This sample shows the steps to make a simple frame rate independent game.
35 -->
36 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
37 "http://www.w3.org/TR/html4/loose.dtd">
38 <html>
39 <head>
40 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
41 <title>
42 Google I/O O3D Sample
43 </title>
44 <style type="text/css">
45 html, body {
46 height: 100%;
47 margin: 0;
48 padding: 0;
49 border: none;
50 font-family: Arial, sans-serif;
51 }
52 </style>
53 <!-- Include sample javascript library functions-->
54 <script type="text/javascript" src="../o3djs/base.js"></script>
55
56 <!-- Our javascript code -->
57 <script type="text/javascript">
58 o3djs.require('o3djs.util');
59 o3djs.require('o3djs.math');
60 o3djs.require('o3djs.rendergraph');
61 o3djs.require('o3djs.primitives');
62 o3djs.require('o3djs.material');
63
64 // Events
65 // init() once the page has finished loading.
66 // unload() when the page is unloaded.
67 window.onload = init;
68 window.onunload= unload;
69
70 // global variables
71 var g_o3dElement;
72 var g_o3d;
73 var g_math;
74 var g_client;
75 var g_viewInfo;
76 var g_pack;
77 var g_root;
78 var g_playerTransform;
79 var g_globalParams;
80 var g_o3dWidth;
81 var g_o3dHeight;
82 var g_o3dElement;
83 var g_eye = [15, 25, 50];
84 var g_target = [0, 10, 0];
85 var g_up = [0, 1, 0];
86 var g_viewMatrix;
87
88 /**
89 * Updates the projection matrix.
90 */
91 function updateProjection() {
92 g_viewInfo.drawContext.projection = g_math.matrix4.perspective(
93 g_math.degToRad(45), // field of view.
94 g_o3dWidth / g_o3dHeight, // aspect ratio
95 0.1, // Near plane.
96 5000); // Far plane.
97 }
98
99 /*
100 * Updates the camera.
101 */
102 function updateCamera() {
103 g_viewMatrix = g_math.matrix4.lookAt(g_eye, g_target, g_up);
104 g_viewInfo.drawContext.view = g_viewMatrix;
105 };
106
107 /**
108 * Updates global variables of the client's size if they have changed.
109 */
110 function updateClientSize() {
111 var newWidth = g_client.width;
112 var newHeight = g_client.height;
113 if (g_o3dWidth != newWidth || g_o3dHeight != newHeight) {
114 g_o3dWidth = newWidth;
115 g_o3dHeight = newHeight;
116 updateProjection();
117 }
118 }
119
120 /**
121 * Creates the client area.
122 */
123 function init() {
124 o3djs.util.makeClients(initStep2);
125 }
126
127 /**
128 * Initializes O3D and creates one shape.
129 * @param {Array} clientElements Array of o3d object elements.
130 */
131 function initStep2(clientElements) {
132 // Initializes global variables and libraries.
133 g_o3dElement = clientElements[0];
134 g_o3d = g_o3dElement.o3d;
135 g_math = o3djs.math;
136 g_client = g_o3dElement.client;
137
138 // Creates a pack to manage our resources/assets
139 g_pack = g_client.createPack();
140
141 g_root = g_pack.createObject('Transform');
142
143 g_viewInfo = o3djs.rendergraph.createBasicView(
144 g_pack,
145 g_root,
146 g_client.renderGraphRoot);
147
148 updateClientSize();
149 updateCamera();
150
151 var redMaterial = o3djs.material.createBasicMaterial(
152 g_pack,
153 g_viewInfo,
154 [0.2, 1, 0.2, 1]); // green
155
156 var checkerMaterial = o3djs.material.createMaterialFromFile(
157 g_pack, 'shaders/checker.shader', g_viewInfo.performanceDrawList);
158
159 g_globalParams = o3djs.material.createAndBindStandardParams(g_pack);
160 g_globalParams.lightWorldPos.value = [30, 60, 40];
161 g_globalParams.lightColor.value = [1, 1, 1, 1];
162
163 // Create a ground plane.
164 var shape = o3djs.primitives.createPlane(
165 g_pack, checkerMaterial, 100, 100, 10, 10);
166 var transform = g_pack.createObject('Transform');
167 transform.parent = g_root;
168 transform.addShape(shape);
169
170 // Create a cylinder.
171 var shape = o3djs.primitives.createCylinder(
172 g_pack, redMaterial, 2.5, 5, 20, 1,
173 g_math.matrix4.translation([0, 2.5, 0]));
174 g_playerTransform = g_pack.createObject('Transform');
175 g_playerTransform.parent = g_root;
176 g_playerTransform.addShape(shape);
177
178 window.g_finished = true; // for selenium testing.
179 }
180
181 /**
182 * Remove any callbacks so they don't get called after the page has unloaded.
183 */
184 function unload() {
185 if (g_client) {
186 g_client.cleanup();
187 }
188 }
189 </script>
190 </head>
191 <body>
192 <table style="width: 100%; height:100%;">
193 <tr style="height: 50px;"><td>
194 <div style="width: 100%; height: 50px; font-size: large;">
195 <img src="assets/colorbar.png" width="100%" height="10px"/><br/>
196 Google I/O 2009 O3D Sample
197 </div>
198 </td></tr>
199 <tr style="height: 100%;"><td>
200 <div style="width: 100%; height: 100%;">
201 <div id="o3d" style="width: 100%; height: 100%;"></div>
202 </div>
203 </td></tr>
204 </table>
205 </body>
206 </html>
OLDNEW
« no previous file with comments | « samples/GoogleIO-2009/step01.html ('k') | samples/GoogleIO-2009/step03.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698