Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Quad and Triangle primatives — Gideros Forum

Quad and Triangle primatives

techdojotechdojo Guru
edited April 2012 in Suggestions & requests
I'd like to request a simple Quad and or Triangle primitive to be added to the rendering functions.
I realise that you can do the same with shapes (but not knowing how shapes are processed internally) I think the ability to draw an arbitrary quad or triangle from a simple table of 4 (or 3) coordinates would be really useful.

In theory it should also be possible to specify vertex colour values (RGBA) so that gradients can be drawn easily as well.

something else I was wondering as well - would it be possible to change the vertex coordinates after the object has been created (I was thinking of this in respect to lines / shapes initially), but if I want to animate a box or triangle (or polyline) during an "onEnterFrame" event, it seems really wasteful to have to recreate the object every time (plus it means extra work for the GC when it kicks in).

My $0.02

Jon...

Likes: MikeHart

Dislikes: amaximov

WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
+1 -1 (+1 / -1 )Share on Facebook

Comments

  • ndossndoss Guru
    edited April 2012

    something else I was wondering as well - would it be possible to change the vertex coordinates after the object has been created (I was thinking of this in respect to lines / shapes initially), but if I want to animate a box or triangle (or polyline) during an "onEnterFrame" event, it seems really wasteful to have to recreate the object every time (plus it means extra work for the GC when it kicks in).
    I know you aren't asking for a shape solution, but you can do some of what you want with shapes without creating new shapes each time you change vertices.

    The following function draws a polygon from a list of vertices (doesn't do gradients though):
    function Shape:drawPoly(points)
    	self:beginPath()
    	for i,p in ipairs(points) do
                  self:lineTo(p[1], p[2])
    	end
    	self:closePath()
    	self:endPath()
    end
    And here's an example of how to change points w/o creating new object new shapes by using Shape:clear():
    local shape = Shape.new()
    stage:addChild(shape)
     
    local points = { {100,100}, {200,100}, {200,200}, {150,250},{100,200} }
    shape:drawPoly(points)
     
    function onEnterFrame()
    	for i,p in ipairs(points) do
    		p[1] = p[1] + math.random(-20,20)/20
    		p[2] = p[2] + math.random(-20,30)/20
    	end
    	shape:clear()
    	shape:setLineStyle(3)
    	shape:setFillStyle(Shape.SOLID, 0x0000cc, 0.5)
    	shape:drawPoly(points)
    end
     
    shape:addEventListener(Event.ENTER_FRAME, onEnterFrame)
  • atilimatilim Maintainer
    As you know there are 2 types of fill styles: Shape.SOLID and Shape.TEXTURE. Also I'm planning to add Shape.GRADIENT.

    Likes: ndoss, OZApps, techdojo

    +1 -1 (+3 / -0 )Share on Facebook
  • @techdojo I plan to release my library very soon. you'll be able to draw everything through simple calls - even bezier curves. you'll see a thread on this.
    @atilim would be veryyy neat! I already have a use for this!

    Likes: ndoss, techdojo

    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
    +1 -1 (+2 / -0 )Share on Facebook
  • Thanks for all the responses, @ndoss - I thought shape:clear() would do the job I just haven't had the time to experiment yet, the "beer" SDK also has "polyline" support which I was using to recreate the old windows "mystify" screen saver - however I was really disappointed when I discovered that there was no way to adjust vertices without having to go through all the headache and waste of allocating a whole bunch of new objects every frame (plus not to mention battering the garbage collector).

    Also I "suspect" (but have never been able to prove) that in the other SDK - calls to generate primitives actually end up being rendered to textures and then blit as normal (draw a rotating line and watch what happens to the amount of video memory used when the line get's to 45 deg).

    @jack0888 - sounds great, I'll look forward to seeing it.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Sign In or Register to comment.