Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    29
    Thanks
    4
    Thanked 3 Times in 3 Posts

    canvas/js 2d perspective transform

    not sure if this is the right place to ask canvas questions, but if it is, i'm trying to program a game like air hockey (with some twists). it works pretty well now but the table is viewed from overhead, and i would prefer to show the game from the player's perspective, as in the pic, without having to rewrite my existing code. anyone know of any js libraries or formulas which can accomplish this?

    Last edited by ereignis; 07-13-2011 at 11:08 AM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    I never actually tried this, but I can refer you to http://stackoverflow.com/questions/5...h-html5-canvas

    Code:
    var cs = Math.cos(angle1), sn = Math.sin(angle1);
    var h = Math.cos(angle2);
    var a = 100*cs, b = -100*sn, c = 200;
    var d = h*100*sn, e = h*100*cs, f = 200;
    ctx.setTransform(a, d, b, e, c, f);

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    29
    Thanks
    4
    Thanked 3 Times in 3 Posts
    not looking for isometric though... way too many resources on that...

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,366
    Thanks
    11
    Thanked 590 Times in 571 Posts
    use css transforms to skew the canvas element...
    css3 should work in all the same places as canvas.


    https://developer.mozilla.org/en/css...css_transforms
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • Users who have thanked rnd me for this post:

    ereignis (07-14-2011)

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    29
    Thanks
    4
    Thanked 3 Times in 3 Posts
    awesome! not aware of these, probably cos i'm usually developing for the least common denominator of browsers and css3 is like a faraway dream...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •