| Index: samples/gpu2d/basic.html
|
| ===================================================================
|
| --- samples/gpu2d/basic.html (revision 0)
|
| +++ samples/gpu2d/basic.html (revision 0)
|
| @@ -0,0 +1,229 @@
|
| +<!--
|
| +Copyright 2010, Google Inc.
|
| +All rights reserved.
|
| +
|
| +Redistribution and use in source and binary forms, with or without
|
| +modification, are permitted provided that the following conditions are
|
| +met:
|
| +
|
| + * Redistributions of source code must retain the above copyright
|
| +notice, this list of conditions and the following disclaimer.
|
| + * Redistributions in binary form must reproduce the above
|
| +copyright notice, this list of conditions and the following disclaimer
|
| +in the documentation and/or other materials provided with the
|
| +distribution.
|
| + * Neither the name of Google Inc. nor the names of its
|
| +contributors may be used to endorse or promote products derived from
|
| +this software without specific prior written permission.
|
| +
|
| +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +-->
|
| +
|
| +<!--
|
| + Sample demonstrating basic 2D vector curve rendering in 3D.
|
| +-->
|
| +
|
| +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
| + "http://www.w3.org/TR/html4/loose.dtd">
|
| +<html>
|
| +<head>
|
| +<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
| +<title>
|
| +O3D GPU2D Sample: Basic Vector Shapes
|
| +</title>
|
| +<!-- Include sample javascript library functions-->
|
| +<script type="text/javascript" src="../o3djs/base.js"></script>
|
| +
|
| +<!-- Our javascript code -->
|
| +<script type="text/javascript" id="o3dscript">
|
| +o3djs.require('o3djs.cameracontroller');
|
| +o3djs.require('o3djs.gpu2d');
|
| +o3djs.require('o3djs.io');
|
| +o3djs.require('o3djs.math');
|
| +o3djs.require('o3djs.rendergraph');
|
| +o3djs.require('o3djs.util');
|
| +
|
| +// Events
|
| +// init() once the page has finished loading.
|
| +// unload() when the page is unloaded.
|
| +window.onload = createClients;
|
| +window.onunload = unload;
|
| +
|
| +// Globals
|
| +var g_o3d;
|
| +var g_math;
|
| +var g_client;
|
| +var g_pack;
|
| +var g_viewInfo;
|
| +var g_o3dElement;
|
| +var g_finished = false; // for selenium testing.
|
| +var g_clientWidth;
|
| +var g_clientHeight;
|
| +var g_path;
|
| +var g_cameraController;
|
| +
|
| +/**
|
| + * Remove any callbacks so they don't get called after the page has unloaded.
|
| + */
|
| +function unload() {
|
| + if (g_client) {
|
| + g_client.cleanup();
|
| +
|
| + // Clear the mouse events.
|
| + onMouseUp();
|
| + }
|
| +}
|
| +
|
| +function createClients() {
|
| + o3djs.util.makeClients(init);
|
| +}
|
| +
|
| +function init(clientElements) {
|
| + // Initializes global variables and libraries.
|
| + var o3dElement = clientElements[0];
|
| + g_o3dElement = o3dElement;
|
| + g_o3d = o3dElement.o3d;
|
| + g_math = o3djs.math;
|
| + g_client = o3dElement.client;
|
| +
|
| + // Store the size of the plugin, so that we can adjust coordinates in
|
| + // full-screen mode. This is necessary because we're not adjusting the aspect
|
| + // ratio; we'd rather that the canvas filled the available area, rather than
|
| + // staying a fixed size or aspect ratio.
|
| + g_clientWidth = g_o3dElement.clientWidth;
|
| + g_clientHeight = g_o3dElement.clientHeight;
|
| +
|
| + // Creates a pack to manage our resources/assets
|
| + g_pack = g_client.createPack();
|
| +
|
| + g_viewInfo = o3djs.rendergraph.createBasicView(
|
| + g_pack,
|
| + g_client.root,
|
| + g_client.renderGraphRoot);
|
| +
|
| + // Set the background color to light gray.
|
| + g_viewInfo.clearBuffer.clearColor = [0.8, 0.8, 0.8, 1];
|
| +
|
| + // Set up our CameraController.
|
| + g_cameraController = o3djs.cameracontroller.createCameraController(
|
| + [0, 0, 0], // centerPos
|
| + 500, // backpedal
|
| + 0, // heightAngle
|
| + 0, // rotationAngle
|
| + g_math.degToRad(15), // fieldOfViewAngle
|
| + updateViewAndProjectionMatrices); // opt_onChange
|
| + g_cameraController.distancePerUnit = 100.0;
|
| + updateViewAndProjectionMatrices();
|
| +
|
| + // Set up event handlers for mouse interaction.
|
| + o3djs.event.addEventListener(o3dElement, 'mousedown', onMouseDown);
|
| + o3djs.event.addEventListener(o3dElement, 'mousemove', onMouseMove);
|
| + o3djs.event.addEventListener(o3dElement, 'mouseup', onMouseUp);
|
| +
|
| + // Create a Path.
|
| + g_path = o3djs.gpu2d.createPath(g_pack, g_viewInfo.zOrderedDrawList);
|
| + g_client.root.addShape(g_path.shape);
|
| +
|
| + // Set the fill of the path.
|
| + g_path.setFill(o3djs.gpu2d.createColor(g_pack, 0.8, 0.0, 0.3, 1.0));
|
| +
|
| + // Draw something on the path.
|
| + g_path.moveTo(25.0, -50.0);
|
| + g_path.cubicTo(75.0, 50.0, 125.0, 25.0, 175.0, 50.0);
|
| + g_path.cubicTo(125.0, -50.0, 75.0, -25.0, 25.0, -50.0);
|
| +
|
| + g_path.moveTo(-25.0, -50.0);
|
| + g_path.cubicTo(-75.0, 50.0, -125.0, 25.0, -175.0, 50.0);
|
| + g_path.cubicTo(-125.0, -50.0, -75.0, -25.0, -25.0, -50.0);
|
| + g_path.close();
|
| +
|
| + // Force an update.
|
| + g_path.update();
|
| +
|
| + g_finished = true; // for selenium testing.
|
| +}
|
| +
|
| +/**
|
| + * Event handler that gets called when a mouse click takes place in
|
| + * the O3D element. It changes the state of the camera controller
|
| + * based on which modifier keys are pressed.
|
| + * @param {!Event} e The mouse down event.
|
| + */
|
| +function onMouseDown(e) {
|
| + if (e.button == 0) {
|
| + if (!e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.MOVE_CENTER_IN_VIEW_PLANE, e.x, e.y);
|
| + } else if (e.metaKey || e.altKey) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.SPIN_ABOUT_CENTER, e.x, e.y);
|
| + } else if (!e.shiftKey && e.ctrlKey) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.DOLLY_IN_OUT, e.x, e.y);
|
| + } else if (e.shiftKey && !e.ctrlKey) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.ZOOM_IN_OUT, e.x, e.y);
|
| + } else if (e.shiftKey && e.ctrlKey) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.DOLLY_ZOOM, e.x, e.y);
|
| + }
|
| + }
|
| +}
|
| +
|
| +/**
|
| + * Event handler that gets called when a mouse move event takes place
|
| + * in the O3D element. It tells the camera controller that the mouse
|
| + * has moved.
|
| + * @param {!Event} e The mouse move event.
|
| + */
|
| +function onMouseMove(e) {
|
| + g_cameraController.mouseMoved(e.x, e.y);
|
| +}
|
| +
|
| +/**
|
| + * Event handler that gets called when a mouse up event takes place in
|
| + * the O3D element. It tells the camera controller that the mouse has
|
| + * been released.
|
| + * @param {!Event} e The mouse up event.
|
| + */
|
| +function onMouseUp(e) {
|
| + g_cameraController.setDragMode(
|
| + o3djs.cameracontroller.DragMode.NONE, e.x, e.y);
|
| +}
|
| +
|
| +/**
|
| + * Updates the view and projection matrices.
|
| + */
|
| +function updateViewAndProjectionMatrices() {
|
| + g_viewInfo.drawContext.view = g_cameraController.calculateViewMatrix();
|
| +
|
| + // Set up a perspective transformation for the projection.
|
| + g_viewInfo.drawContext.projection = g_math.matrix4.perspective(
|
| + g_cameraController.fieldOfViewAngle * 2, // Frustum angle.
|
| + g_o3dElement.clientWidth / g_o3dElement.clientHeight, // Aspect ratio.
|
| + 1, // Near plane.
|
| + 5000); // Far plane.
|
| +}
|
| +</script>
|
| +</head>
|
| +
|
| +<body>
|
| +<h1>O3D GPU2D Sample: Basic Vector Shapes</h1>
|
| +<br/>
|
| +<!-- Start of O3D plugin -->
|
| +<div id="o3d" style="width: 800px; height: 600px;"></div>
|
| +<!-- End of O3D plugin -->
|
| +
|
| +<p><p>See above for output.
|
| +</body>
|
| +</html>
|
|
|
| Property changes on: samples/gpu2d/basic.html
|
| ___________________________________________________________________
|
| Added: svn:mime-type
|
| + text/html
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|