Polyvector advantages....

Previous topic - Next topic

Kyo

QuoteKitty Hello
1. Not, yet. I try to allow that with an ALPHAMODE in between the POLYVECTOR calls.


Great News  :good:

monono

A different alpha within the polyvector definition works for me. I always change alphamode after newgroup. But it doesnÃ,´t works in the full range from -1 to 1. Just -1 to 0 and 0 to1 within the same polyvec.

My pros and cons to the opening question:

Pros

  • I can have all the spritegraphics on one huge texture and just change the texture coords per polynewgroup
  • There is still hope it is faster.
  • You canÃ,´t deform-scale and rotate at the same time with the sprite commands.
Cons

  • The far I know there is no pixelperfect collusion using polyvecs !....???

Kyo

Quote from: monono on 2010-Apr-23
A different alpha within the polyvector definition works for me. I always change alphamode after newgroup. But it doesnÃ,´t works in the full range from -1 to 1. Just -1 to 0 and 0 to1 within the same polyvec.

My pros and cons to the opening question:

Pros

  • I can have all the spritegraphics on one huge texture and just change the texture coords per polynewgroup
  • There is still hope it is faster.
  • You canÃ,´t deform-scale and rotate at the same time with the sprite commands.
Cons

  • The far I know there is no pixelperfect collusion using polyvecs !....???

you use:

Code (glbasic) Select


STARTPOLY 0,2

ALPHAMODE -.4

LOCAL c%=RGB(255,255,255)
POLYVECTOR  0, 0, 0,0,c
POLYVECTOR  0,40, 0,0,c
POLYVECTOR 40,20, 0,0,c
POLYVECTOR 40,40, 0,0,c

POLYNEWSTRIP

ALPHAMODE 0

// same at 100,100
POLYVECTOR 100,100, 0,0,c
POLYVECTOR 100,140, 0,0,c
POLYVECTOR 140,120, 0,0,c
POLYVECTOR 140,140, 0,0,c

ENDPOLY


and it works?

Scott_AW

[qoute]
  • The far I know there is no pixelperfect collusion using polyvecs !....???
[/quote]

You can still compare the sprites against each other but it won't include deformations or rotations.  If you are simply drawing with polyvector, to scale, you can use sprcoll to comapre the sprites without having to draw them.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

monono

Quoteand it works?
Yes ... but not exactly.
Try -.1 for the second alphamode. 0 seems to disturb the other alpha settings. The problem with the range (blendingmodes) I descriped earlier doesnÃ,´t show up any more. In the code where it happend there were a few hundred polystrips. IÃ,´ll try to reproduce what I did.

@Scott: thanks for your thoughts, but I dont know exactly how to do that. I donÃ,´t draw one polyvector for one sprite. I do draw nearly all sprites with one polyvector. ThatÃ,´s why I canÃ,´t use sprcoll with the image source. ItÃ,´s one big image, with all single graphics together, splitted up all over my polyvector. Can you pls explain what you mean in code. (I hope gregbug is satisfied and this is not too off-topic)

gregbug

Quote from: monono on 2010-Apr-23
Quoteand it works?
@Scott: thanks for your thoughts, but I dont know exactly how to do that. I donÃ,´t draw one polyvector for one sprite. I do draw nearly all sprites with one polyvector. ThatÃ,´s why I canÃ,´t use sprcoll with the image source. ItÃ,´s one big image, with all single graphics together, splitted up all over my polyvector. Can you pls explain what you mean in code. (I hope gregbug is satisfied and this is not too off-topic)

Thanks to all for the explanations!

@Monono I use the same technique to draw my sprites ... (One big texture) (I try to squeeze more fps from my iPhone)
for the collision I have implemented (or rather trying to implement) bbc technique (Bounding box collision) and for the sprites that are rotated OBBC (oriented bounding box collision)

for perfect pixel collision I do not know how to implement them! any suggestions?  (Scott_AW?) =D
Ciao Ciao,
Gianluca. (l'Aquila tornerà a volare alta nel cielo!!!!)

Scott_AW

Well it wouldn't work with one big texture holding all the individual sprites, you'd have to have them as individuals to do the checking.  What you could do is keep your sprite based on tile maps and make individual ones that are simple black & white masks.

I've been using CONSTANTs to flag my image starter indexes since I use individual sprites, you can use this to match up to the tilemap with the masks sprites.  To save time but not processing you can have this done on loading.

Assuming you're using a tile/sprite map that has both rows and columns, here is a snip that should convert tilemap to masks.  Just don't use black as a transparent color though.  I wrote it in notepad, so I can only guess if it works.

Code (glbasic) Select

  //Generate masks...
  constant tileimage = # //Set the tilemap image index lower than the masks...
  constant tilemask = #  //Set the masks' index start
  constant tilewidth = ##
  constant tileheight = ##
  constant tilecount = ## //row*col
  constant tilecolcnt = ## //how many columns per row...
 
  loadsprite "image.bmp", tileimage

  local count = 0, x = 0, y = 0
  clearscreen rgb(244,0,244)  //Use your transparent color
  for count = 0 < tilecount
    if count < tilecolcnt
      x = count * tilewidth
    else
      local adjust
      adjust = integer(count / tilecolcnt)
      x = count - (tilecolcnt * count) * tilewidth
      y = adjust * tileheight
    endif
    //Make mask
    startpoly tileimage, 0
      polyvector x, y, x, y, rgb(0,0,0)
      polyvector x, y + tileheight, x, y + tileheight, rgb(0,0,0)
      polyvector x + tilewidth, y + tileheight, x + tilewidth, y + tileheight, rgb(0,0,0)
      polyvector x + tilewidth, y, x + tilewidth, y, rgb(0,0,0)
    endpoly
    //Capture
    grabsprite tilemask + count, 0, 0, tilewidth, tileheight
  next


After you have your masks, assuming you have your sprite positions on the tile map stored you can then matchup that sprite to the correct mask.  Since this method creates a 1d list of indexs and you may be using a 2d list of images, X & Y, you just multiply the x and y values to achieve the index.  If your X & Y values are actual positions on the tilemap, then (x/tilewidth) * (y/tilewidth) to produce the index.  A 1d index that just has X positions for the tiles would just have to be (x/tilewidth).  You can choose to use integer() on them, but if your tile size is constant it shouldn't be needed.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Moru

You can also store the mask-data as animation sheets if your sprites are all the same size. Load them with:

LOADANIM

Specifying the size of the single sprites. Then use:

ANIMCOLL

To test for collisions. Animcoll keeps track of the index into the sprite array so you don't have to do it yourself.

This ofcourse won't work if you have different sizes of sprites all over the place like some of you have :-)

Scott_AW

Forgot about anicoll.  That would make it a lot easier.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Dark Schneider

Quote2. why on normal polyvector the color param or alphamode is so slow?
Quote2. colour pointers are very expensive on OpenGL|ES devices. Use a texture instead wherever applicable.

Please clarify me, that means that setting and ALPHAMODE other than 0 or passing a param col% to POLYVECTOR is slow on iPhone and other OpenGL ES devices?.

gregbug

Quote from: Dark Schneider on 2010-Apr-24
Please clarify me, that means that setting and ALPHAMODE other than 0 or passing a param col% to POLYVECTOR is slow on iPhone and other OpenGL ES devices?.

on my iPhone 3gs passing color param to polyvector the fps pass from solid 30fps at 2-3FPS!!!

alphamode runs fine.
Ciao Ciao,
Gianluca. (l'Aquila tornerà a volare alta nel cielo!!!!)

monono

@ Scott and the others: Thanks for the explanation I will try soon.

@ gregbug:
QuoteI have implemented (or rather trying to implement) bbc technique (Bounding box collision) and for the sprites that are rotated OBBC
So we are doing the same thing. I already got a working boxcoll. It even works with deformed, scaled and rotated sprites.
Asume x,y are is one corner of object1 and x1-x4,y1- y4 are the corners of object2:
Code (glbasic) Select

IF ((y - y1) * (x2 - x1)) - ((x - x1) * (y2 - y1)) <= 0 THEN RETURN FALSE
IF ((y - y2) * (x3 - x2)) - ((x - x2) * (y3 - y2)) <= 0 THEN RETURN FALSE
IF ((y - y3) * (x4 - x3)) - ((x - x3) * (y4 - y3)) <= 0 THEN RETURN FALSE
IF ((y - y4) * (x1 - x4)) - ((x - x4) * (y1 - y4)) <= 0 THEN RETURN FALSE
RETURN TRUE

If it returns true there is a hit. You can do that with all 4 corners of object1.
For the corners I use some code here from the forum http://www.glbasic.com/forum/index.php?topic=1545.msg10302#msg10302
Code (glbasic) Select


sphi=QSIN(T_Objects[item].ang)
cphi=QCOS(T_Objects[item].ang)
spx = T_Objects[item].width
spy = T_Objects[item].height
dx=spx/2*T_Objects[item].scalex
dy=spy/2*T_Objects[item].scaley

LOCAL hx, hy , _x,_y

hx = (spx/2-T_Objects[item].originx)*T_Objects[item].scalex#
hy= (spy/2-T_Objects[item].originy)*T_Objects[item].scaley#

_x =T_Objects[item].xPos
_y =T_Objects[item].yPos

x1 = _x - cphi*(dx-hx) - sphi* (dy-hy)
y1 = _y - cphi*(dy-hy) + sphi*(dx-hx)
x2 = _x - cphi*(dx-hx) + sphi* (dy+hy)
y2 = _y + cphi*(dy+hy) + sphi*(dx-hx)
x3 = _x + cphi*(dx+hx) + sphi*(dy+hy)
y3 = _y + cphi*(dy+hy) - sphi*(dx+hx)
x4 = _x + cphi*(dx+hx) - sphi*(dy-hy)
y4 = _y - cphi*(dy-hy) - sphi*(dx+hx)

T_Objects[item].cornerx[1]=x1 ; T_Objects[item].cornery[1]=y1
T_Objects[item].cornerx[2]=x2 ; T_Objects[item].cornery[2]=y2
T_Objects[item].cornerx[3]=x3 ; T_Objects[item].cornery[3]=y3
T_Objects[item].cornerx[4]=x4 ; T_Objects[item].cornery[4]=y4


I just slightly modefied it. It regards angle, scale x and y, origin x and y. Maybe you can use that. Especially the origin comes in handy. You can group sprites and let them have all the same origin to for example rotate them around one point.

Another idea for pixelperfect collusion came to my mind. CouldnÃ,´t I just draw all the polystrips belonging to one texture on another screen. To test for collusion I then first check the boxes and secondly check if there is a pixelperfect one with the big createscreen-sprite. Are there any concerns about speed if it is coming to createscreen.

Scott_AW

I believe sprcoll performs a boxcoll first.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Kitty Hello

fixed in the next update.

monono

sorry I canÃ,´t follow  :S What are you going to fix exactly, Gernot?