diff --git a/examples/tank.png b/examples/tank.png index 48eec1c..bde4866 100644 Binary files a/examples/tank.png and b/examples/tank.png differ diff --git a/gladius/README.md b/gladius/README.md index d926a48..8004f98 100644 --- a/gladius/README.md +++ b/gladius/README.md @@ -30,7 +30,9 @@ Start by cloning the repository or downloading a zipped version from github. Inside the project directory you'll find pre-built versions of the following modules: * gladius-core: the engine core; you'll definitely need to load this -* gladius-cubicvr: CubicVR rendering backend +* gladius-cubicvr: CubicVR renderer +* gladius-box2d: Box2D physics +* gladius-input: user input We tested the examples with these module versions. If you build your own modules, the examples might still work, but they also might not. diff --git a/gladius/examples/assets/images/red-tank-diffuse.jpg b/gladius/examples/assets/images/red-tank-diffuse.jpg new file mode 100644 index 0000000..685cc41 Binary files /dev/null and b/gladius/examples/assets/images/red-tank-diffuse.jpg differ diff --git a/gladius/examples/assets/procedural-sphere.js b/gladius/examples/assets/procedural-sphere.js new file mode 100644 index 0000000..aa71436 --- /dev/null +++ b/gladius/examples/assets/procedural-sphere.js @@ -0,0 +1,26 @@ +function proc( options ) { + + options = options || {}; + options.type = options.type || "sphere"; + options.radius = options.radius || 0.5; + options.latDetail = options.latDetail || 24; + options.lonDetail = options.lonDetail || 24; + + var mesh = + { + primitive: { + type: options.type, + radius: options.radius, + lat: options.latDetail, + lon: options.lonDetail, + uvmapper: { + projectionMode: "cubic", + scale: [1, 1, 1] + } + }, + compile: true + }; + + return mesh; + +} \ No newline at end of file diff --git a/gladius/examples/camera-rotate/camera-rotate.js b/gladius/examples/camera-rotate/camera-rotate.js index 676785b..86931dd 100644 --- a/gladius/examples/camera-rotate/camera-rotate.js +++ b/gladius/examples/camera-rotate/camera-rotate.js @@ -111,13 +111,9 @@ document.addEventListener( "DOMContentLoaded", function( e ) { space.add( parentCube ); var task = new engine.FunctionTask( function() { - var cubeRotation = new engine.math.Vector3( space.findNamed( "cube" ).findComponent( "Transform" ).rotation ); - cubeRotation = engine.math.vector3.add( cubeRotation, [0, space.clock.delta * 0.0003, 0] ); - space.findNamed( "cube" ).findComponent( "Transform" ).setRotation( cubeRotation ); + space.findNamed( "cube" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.0003; - var cameraRotation = new engine.math.Vector3( space.findNamed( "camera" ).findComponent( "Transform" ).rotation ); - cameraRotation = engine.math.vector3.add( cameraRotation, [0, space.clock.delta * 0.0003, 0] ); - space.findNamed( "camera" ).findComponent( "Transform" ).setRotation( cameraRotation ); + space.findNamed( "camera" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.0003; }, { tags: ["@update"] }); diff --git a/gladius/examples/cube-collision/cube-collision.js b/gladius/examples/cube-collision/cube-collision.js index db393e7..d22e711 100644 --- a/gladius/examples/cube-collision/cube-collision.js +++ b/gladius/examples/cube-collision/cube-collision.js @@ -32,12 +32,12 @@ document.addEventListener( "DOMContentLoaded", function( e ) { var box2dOptions = { resolver: { - gravity: [0,-0.5] + dimensionMap: box2dExtension.services.resolver.service.prototype.DimensionMaps.XY } }; engine.registerExtension( cubicvrExtension, cubicvrOptions ); - engine.registerExtension( box2dExtension);//, box2dOptions); + engine.registerExtension( box2dExtension, box2dOptions); var resources = {}; @@ -102,13 +102,14 @@ document.addEventListener( "DOMContentLoaded", function( e ) { var lightDefinition = new cubicvr.LightDefinition({ intensity: 1, + distance: 20, light_type: cubicvr.LightDefinition.LightTypes.POINT, method: cubicvr.LightDefinition.LightingMethods.DYNAMIC }); space.add( new engine.Entity( "camera", [ - new engine.core.Transform( [0, 0, 5] ), + new engine.core.Transform( [0, 0, 10] ), new cubicvr.Light( lightDefinition ), new cubicvr.Camera( { targeted:false @@ -117,7 +118,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { )); var bodyDefinition = new box2d.BodyDefinition(); - var fixtureDefinition = new box2d.FixtureDefinition({shape:new box2d.BoxShape(0.25,0.25)}); + var fixtureDefinition = new box2d.FixtureDefinition({shape:new box2d.BoxShape(1,1)}); for (var cubeIndex = 0; cubeIndex < 5; cubeIndex++){ @@ -132,7 +133,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { }; var firstCube = new engine.Entity( "cube1", [ - new engine.core.Transform( [3 + cubeIndex * 1.5, 0.125, 0], [0, 0, 0], [0.5, 0.5, 0.5] ), + new engine.core.Transform( [3 + cubeIndex * 3, 0.25, 0], [0, 0, 0]), firstBody, new cubicvr.Model( resources.mesh, resources.material ) ] @@ -151,14 +152,14 @@ document.addEventListener( "DOMContentLoaded", function( e ) { var secondCube = new engine.Entity( "cube2", [ - new engine.core.Transform( [-3 - cubeIndex * 1.5, -0.125, 0], [0, 0, 0], [0.5, 0.5, 0.5] ), + new engine.core.Transform( [-3 - cubeIndex * 3, -0.25, 0], [0, 0, 0]), secondBody, new cubicvr.Model( resources.mesh, resources.material ) ] ); space.add( secondCube ); - new engine.Event("LinearImpulse", {impulse: [-0.25,0]}).dispatch(firstCube); - new engine.Event("LinearImpulse", {impulse: [0.25,0]}).dispatch(secondCube); + new engine.Event("LinearImpulse", {impulse: [-1,0]}).dispatch(firstCube); + new engine.Event("LinearImpulse", {impulse: [1,0]}).dispatch(secondCube); } var task = new engine.FunctionTask( function() { diff --git a/gladius/examples/cube-impulse/cube-impulse.js b/gladius/examples/cube-impulse/cube-impulse.js index f916a08..e370ce7 100644 --- a/gladius/examples/cube-impulse/cube-impulse.js +++ b/gladius/examples/cube-impulse/cube-impulse.js @@ -122,22 +122,25 @@ document.addEventListener( "DOMContentLoaded", function( e ) { var cubePosition = new engine.math.Vector3( space.findNamed( "cube").findComponent( "Transform").position); // var camera = space.findNamed("camera").findComponent("Camera"); // camera.setTarget(cubePosition); - if (cubePosition[1] < -1.5){ + + var cubeY = cubePosition.y; + var cubeX = cubePosition.x; + if (cubeY < -1.5){ var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,0.1), getRandom(0,1)]}); impEvent.dispatch(parentCube); } - if (cubePosition[1] > 1.5){ + if (cubeY > 1.5){ var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,0.1) * -1, getRandom(0, 1) * -1]}); impEvent.dispatch(parentCube); } - if (cubePosition[0] < -1.5){ + if (cubeX < -1.5){ var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,1), 0]}); impEvent.dispatch(parentCube); var angEvent = new engine.Event('AngularImpulse',{impulse: getRandom(0, 0.1)}); angEvent.dispatch(parentCube); } - if (cubePosition[0] > 1.5){ + if (cubeX > 1.5){ var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0, 1) * -1, 0]}); impEvent.dispatch(parentCube); diff --git a/gladius/examples/cube/cube.js b/gladius/examples/cube/cube.js index 3cb7aa3..b9fd6b2 100644 --- a/gladius/examples/cube/cube.js +++ b/gladius/examples/cube/cube.js @@ -99,13 +99,9 @@ document.addEventListener( "DOMContentLoaded", function( e ) { space.findNamed( "light-marker" ).setParent( space.findNamed( "light-center" ) ); var task = new engine.FunctionTask( function() { - var cubeRotation = new engine.math.Vector3( space.findNamed( "cube" ).findComponent( "Transform" ).rotation ); - cubeRotation = engine.math.vector3.add( cubeRotation, [space.clock.delta * 0.003, space.clock.delta * 0.001, space.clock.delta * 0.0007] ); - space.findNamed( "cube" ).findComponent( "Transform" ).setRotation( cubeRotation ); + space.findNamed( "cube" ).findComponent( "Transform" ).rotation.add([space.clock.delta * 0.003, space.clock.delta * 0.001, space.clock.delta * 0.0007]); - var lightRotation = new engine.math.Vector3( space.findNamed( "light-center" ).findComponent( "Transform" ).rotation ); - lightRotation = engine.math.vector3.add( lightRotation, [0, space.clock.delta * 0.001, 0] ); - space.findNamed( "light-center" ).findComponent( "Transform" ).setRotation( lightRotation ); + space.findNamed( "light-center" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.001; }, { tags: ["@update"] }); diff --git a/gladius/examples/tank/index.html b/gladius/examples/tank/index.html index 81f2028..5193d4d 100644 --- a/gladius/examples/tank/index.html +++ b/gladius/examples/tank/index.html @@ -15,7 +15,9 @@