Tuesday, November 27, 2012

Drawing lines in QML

QML is very nice way to build stuff, but it does lack some features that has bugged at least myself quite a lot. There is no Line element for drawing arbitrary lines from point x1,y1 to x2,y2.

Fortunately there is the Rectangle element. And what is a rectangle with a height of 1 ? More or less a line. Rectangles can be set to be at x1,y1 and you can specify the rotation. And that gives us a line from x1,y1 with a rotation. And digging deep in your brain for some basic math gives us a line drawing algorithm.

Just calculate the length from x1,y1 to x2,y2 and that gives us the width of the rectangle. Then calculate the slope and we have the rotation we need.


And here you have a Line element ready to go for your QtQuick project, free to use so enjoy!
(Note: This is a workaround for having no canvas like element in Qt 4.7/8, if you are using Qt 5 then you can use the Canvas)

import QtQuick 1.1

Rectangle {
    id: l
    property alias x1: l.x
    property alias y1: l.y

    property real x2: l.x
    property real y2: l.y

    color: "black"
    height: 2
    smooth: true;

    transformOrigin: Item.TopLeft;

    width: getWidth(x1,y1,x2,y2);
    rotation: getSlope(x1,y1,x2,y2);

    function getWidth(sx1,sy1,sx2,sy2)
    {
        var w=Math.sqrt(Math.pow((sx2-sx1),2)+Math.pow((sy2-sy1),2));
        console.debug("W: "+w);
        return w;
    }

    function getSlope(sx1,sy1,sx2,sy2)
    {
        var a,m,d;
        var b=sx2-sx1;
        if (b===0)
            return 0;
        a=sy2-sy1;
        m=a/b;
        d=Math.atan(m)*180/Math.PI;

        console.debug(a)
        console.debug(b)

        if (a<0 a="" b="" d="" else="" if="" return="">=0 && b>=0)
            return d;
        else if (a<0 b="">=0)
            return d;
        else if (a>=0 && b<0 0="" d="" else="" pre="" return="">

Wednesday, November 21, 2012

Oh, yes!

Awesomenes!

Tuesday, November 20, 2012

Retro pinball, game prototype and qml box2d demo

Something I'm working on, not that special, but kinda fun still. Uses my improved Box2D QML plugin, otherwise it is pure QML only (for now).


Tuesday, November 13, 2012

RIM is definitely doing something right

Just look at these html5test scores, from left to right, Playbook, BB10 Dev Alpha, N9 and a Lumia 800.

Thursday, October 25, 2012

QML Box2D and more features

I'm working on a couple of different games, using the QML Box2D bindings. As I'm targeting the N9, I need to use the Qt 4.x based version that has been pretty much forgotten by the authors, old version of Box2D and many features are missing. So lets scratch that itch then. The Moto Trial Racer sources where consulted for some features and ideas.

So here, my a bit more updated version of the QML Box2D bindings:
  • Box2D upgraded to 2.2.1
  • Joint release/grab
  • WeldJoint added
  • WheelJoint added
  • FrictionJoint added
  • Basic Edge shape support added
  • Missing properties and methods added (gravityScale, getMass(), getInertia(), angularVelocity, etc)
I'm also going to add RopeJoint, PulleJoint and GearJoint  support as time permits (and need arises).

Enjoy !

Wednesday, September 26, 2012

Transfering contacts from N900 to Lumia

I don't know if it has been implemented in some resent update, but at the time of doing this video, sending vCard contacts to the Lumias over bluetooth was not supported. But fortunately the Lumias have an integrated QR Code reader, and I had made a QR Code contact exported plugin for the N900. So here it is, a how to on how to transfer contacts from your N900 to your Nokia Lumia device. I knew it would be useful for something :)

Friday, September 21, 2012

Unfortunate distractions lately

Sorry for not writing for a while. Cases of Alzheimer’s getting worse and possible Trigeminal neuralgia in my family has kept my mind un-focused and development blog writing hasn't been on the top of my mind lately.
Things seem to be getting a bit better at time of writing so hopefully I won't be that distracted in the coming weeks. I hope.