Top Banner
59

Clutter Fun

Oct 10, 2014

Download

Documents

Sharath Koovill
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Clutter Fun
Page 2: Clutter Fun

Dax - A Clutter based SVG library

Damien Lespiau <[email protected]>

Page 3: Clutter Fun

SVG

<?xml version="1.0"?><svg width="256" height="192" <circle cx="100" cy="100" r="20" fill="orange" /></svg>

Page 4: Clutter Fun

SVG can draw lions...

Page 5: Clutter Fun

...and tigers

Page 6: Clutter Fun

SVG is not just about drawing wild animals

• Styling with CSS, • SVG fonts, • Events (pointer, keyboard, focus, ...), • SMIL Animations, • JavaScript & (µ)DOM, • <audio> and <video> tags.

Page 7: Clutter Fun

Putting things together

• gobject-based DOM tree, • gobject-introspection (DOM API), • gjs (or seed), • Clutter,

Page 8: Clutter Fun

Animations (1)

<rect x="10" y="10" width="48" height="48" fill="orange"> <animate attributeType="XML" attributeName="x" from="10" to="190" dur="4s" repeatCount="indefinite" /> </rect>

Page 9: Clutter Fun
Page 10: Clutter Fun

Animations (2)

<animateTransform attributeName="transform"type="rotate" from="0" to="360" dur="15s"

repeatCount="indefinite"xlink:href="#letter-o" />

Page 11: Clutter Fun
Page 12: Clutter Fun

Events, JavaScript

<script type="application/ecmascript"><![CDATA[ function circle_click(evt) { var circle = evt.target; var currentRadius = circle.getFloatTrait("r"); if (currentRadius == 100) circle.setFloatTrait("r", currentRadius*2); else circle.setFloatTrait("r", currentRadius*0.5); } ]]></script><circle cx="300" cy="225" r="100" fill="red"> <handler type="application/ecmascript" ev:event="click"> circle_click(evt); </handler></circle>

Page 13: Clutter Fun
Page 14: Clutter Fun

Video tag

<video xlink:href="video.avi" audio-level=".8" type="video/x-msvideo" x="50" y="50" width="320" height="240" repeatCount="indefinite"/>

Page 15: Clutter Fun
Page 16: Clutter Fun

Where is this going?

• Growing high level XML library, • Drawing work (stroking, gradients, cairo), • Authoring tool needed, • HMTL 5 experiments, • Own time project.

Page 17: Clutter Fun

Think Clutter!

Toolkits, Flash, SVG,CSS3, MPEG4 BIFS & LaSeR

Page 18: Clutter Fun

Links

• Dax repo: git://git.clutter-project.org/dax • Temporary Clutter branch: git://git.lespiau.name/clutter-guadec • Slides: git://git.lespiau.name/2010-GUADEC • Pinpoint: git://git.clutter-project.org/toys

Page 19: Clutter Fun
Page 20: Clutter Fun
Page 21: Clutter Fun

A library for putting 3D models in a Clutter scene

Page 22: Clutter Fun

Make actors out of models drawn in Blender

Page 23: Clutter Fun

Uses Stanford PLY format via library called RPly

Page 24: Clutter Fun

Blender has a builtin exporter for PLY files

Page 25: Clutter Fun

require 'mash'

Clutter::initstage = Clutter::Stage.get_defaultstage.color = Clutter::Color.new(128, 128, 255, 255)

# Create an actor for the modelmodel = Mash::Model.new(Mash::Data::NEGATE_Y, "example-model.ply")

# Set a size and position. By default the model gets scaled to fill# this size while preserving the aspect ratiomodel.set_size(stage.width * 0.6, stage.height * 0.6)model.set_position(stage.width / 2 - model.width / 2, stage.height / 2 - model.height / 2)

# Add it to the stagestage << model

# Run the main loopstage.showClutter::main

Page 26: Clutter Fun

It doesn't look like much without lighting

Page 27: Clutter Fun

# Create a special container that enables lighting for its childrenbox = Mash::LightBox.new(Clutter::FixedLayout.new)

# Add a light to the scenelight = Mash::PointLight.newlight.x = stage.widthlight.depth = 100box << light

# We now put the model in the box as well instead of directly to the# stagebox << model

# .. and add the box to the stagestage << box

Page 28: Clutter Fun

What happened to the eyes‽

Page 29: Clutter Fun

We need to enable depth testing or partsof the back of the model will show throughand cover up parts of the front.

Page 30: Clutter Fun

# Enable depth testing when the box is paintedbox.signal_connect('paint') do Cogl.set_depth_test_enabled(true) # We can also enable backface culling for a free optimization Cogl.set_backface_culling_enabled(true)end

# Disable it again after the paint depth testing when the box is paintedbox.signal_connect_after('paint') do Cogl.set_depth_test_enabled(false) Cogl.set_backface_culling_enabled(false)end

Page 31: Clutter Fun

The model is an actor so we can useClutter's animation framework with it

Page 32: Clutter Fun

# Set the rotation center to the middle of the actormodel.set_rotation(Clutter::Y_AXIS, 0, model.width / 2.0, 0, 0)# Tell Clutter to animate a rotation and loop itmodel.animate(Clutter::LINEAR, 3000, "rotation-angle-y" => 360).loop = true

Page 33: Clutter Fun

The lights are actors too so wecan also animate those

Page 34: Clutter Fun

# Set the rotation center of the light to the middle of the stagelight.set_rotation(Clutter::Y_AXIS, 0.0, -stage.width / 2.0, 0, 0)# Set a rotation animation and loop itlight.animate(Clutter::LINEAR, 3000, "rotation-angle-y" => 360.0).loop = true

Page 35: Clutter Fun

If the model has texture coordinatesthen we can set a texture to draw

Page 36: Clutter Fun

# Get the Cogl material from the modelmaterial = model.material# Set a texture layer on the materialmaterial.set_layer(0, Cogl::Texture.new("dice-texture.png"))

Page 37: Clutter Fun

The Mash lighting model is directlycopied from the old fixed functionlighting model from OpenGL

Page 38: Clutter Fun

There are three light types

MashDirectionalLightMashPointLightMashSpotLight

Page 39: Clutter Fun

What could it be used for?

Page 40: Clutter Fun

Games

Page 41: Clutter Fun

DFight

Page 42: Clutter Fun

Robot pony

Page 43: Clutter Fun

3D icons in a user interface?

Page 44: Clutter Fun

</presentation>

The angry cat picture is Copyright onefromme on Flickr and is releasedunder the Creative Commons Attribution 2.0 Generic license

Page 45: Clutter Fun

Writing simple, real-time games using Clutter

Page 46: Clutter Fun

Application focuses;• stability• usability• maintainability

Page 47: Clutter Fun

Game focuses;• gameplay

Page 48: Clutter Fun
Page 49: Clutter Fun

Game-writing guidelines"Lord's Laws"

Page 50: Clutter Fun

Law 1 - Steal

Page 51: Clutter Fun

Law 2 - Take advantage of your software

Page 52: Clutter Fun

Law 3 - Use images for everything

Page 53: Clutter Fun

Law 4 - Keep it simple

Page 54: Clutter Fun

Law 5 - Quick and dirty

Page 55: Clutter Fun

Law 6 - Get help

Page 56: Clutter Fun

The results:

Page 57: Clutter Fun

Source:http://gitorious.org/~cwiiishttp://git.clutter-project.org/mx/ ('kinetic-scrolling' branch)http://git.clutter-project.org/clutter-box2d/

Page 58: Clutter Fun

Questions?

Page 59: Clutter Fun