| |
Recent posts by Omrelap on Kongregate
Omrelap
137 posts
|
Topic: Game Programming /
[AS3] Quickest Hittest?
i know it wouldn’t be hard but it would be massive
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
[AS3] Quickest Hittest?
Originally posted by UnknownGuardian:
EDIT And I would love to see what Omrelap’s Triangle code would look like on a single line. Haha.
me to :)
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
[AS3] Quickest Hittest?
TriangularTest.as:
package mrp.hittest
{
import flash.geom.Point;
/**
* ...
* @author Omrelap
*/
public class TriangularTest
{
public static function PointHittest(hittestPoint:Point, triA:Point, triB:Point, triC:Point):Boolean
{
return sameSide(hittestPoint, triA, triB, triC) && sameSide(hittestPoint, triB, triA, triC) && sameSide(hittestPoint, triC, triA, triB);
}
public static function TriangleHittest(triA1:Point, triA2:Point, triA3:Point, triB1:Point, triB2:Point, triB3:Point):Boolean
{
return PointHittest(triB1, triA1, triA2, triA3) || PointHittest(triB2, triA1, triA2, triA3) || PointHittest(triB3, triA1, triA2, triA3) || PointHittest(triA1, triB1, triB2, triB3) || PointHittest(triA2, triB1, triB2, triB3) || PointHittest(triA3, triB1, triB2, triB3);
}
private static function sameSide(p1:Point, p2:Point, p3:Point, p4:Point): Boolean
{
return ((counterClockOrder(p1,p3,p4) == counterClockOrder(p2,p3,p4)));
}
private static function counterClockOrder(p1:Point, p2:Point, p3:Point):Boolean
{
return (p3.y-p1.y) * (p2.x-p1.x) > (p2.y-p1.y) * (p3.x-p1.x);
}
}
}
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
[AS3] Quickest Hittest?
RectangularTest.as:
package mrp.hittest
{
import flash.geom.Point;
/**
*
* @author Omrelap
*/
public class RectangularTest
{
public static function pointHittest(hittestPoint:Point, sqrA:Point, sqrB:Point):Boolean
{
return hittestPoint.x-sqrA.x > 0 && hittestPoint.y-sqrA.y > 0 && hittestPoint.x-sqrA.x < sqrB.x-sqrA.x && hittestPoint.y-sqrA.y < sqrB.y-sqrA.y;
}
public static function triangleHittest(rectA:Point, rectB:Point, triA:Point, triB:Point, triC:Point):Boolean
{
return pointHittest(triA, rectA, rectB) || pointHittest(triB, rectA, rectB) || pointHittest(triC, rectA, rectB);
}
/*public static function rectangleHittest(rectA1:Point, rectA2:Point, rectB1:Point, rectB2:Point):Boolean
{
var left1:Number = rectA1.x;
var right1:Number = rectA2.x;
var top1:Number = rectA1.y;
var bottom1:Number = rectA2.y;
var left2:Number = rectB1.x;
var right2:Number = rectB2.x;
var top2:Number = rectB1.y;
var bottom2:Number = rectB2.y;
}*/
}
}
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
[AS3] Quickest Hittest?
- - pixel perfect hittesting is the most accurate hittesting, although this is very slow. geometrical hittesting is probably the fastest and can be very accurate if done correctly. I started making a collection of geometrical collision detections and other classes that will hittest groups of shapes with other groups of shapes. I havent finished the classes hittesting multiple shapes but i have finished rectangular tests and triangular tests. the circular hittest is completely finished, it has only got circle to point hittest, i haven’t figured out a fast circle to rectangle, or circle to triangle.
I have spent alot of time testing each hittest and making it as fast as possible.
Ill post the rect and triangle hittests for you.
Edit: oh and the rect to rect isnt workin.
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
triangular hittest
@Ratosh
wow your version runs at the full 120 FPS, i refussed to belief it so i checked if it about 4 times.
i even tested if it was actually using any CPU, so i uped it to 50000 tests per 30 ms, even then it ran at 65.166 FPS.
here is the current hittest class, if anyone wants to try to see if they can make a faster one just ask me and ill test it for ya.
package
{
import flash.geom.Point;
/**
* ...
* @author Omrelap
*/
public class SimpleGeomHittest
{
public static function TriangleHittest(hittestPoint:Point, triA:Point, triB:Point, triC:Point):Boolean
{
if (sameSide(hittestPoint, triA, triB, triC) && sameSide(hittestPoint, triB, triA, triC) && sameSide(hittestPoint, triC, triA, triB))
{
return true;
} else
{
return false;
}
}
public static function sameSide(p1:Point, p2:Point, p3:Point, p4:Point): Boolean
{
return ((counterClockOrder(p1,p3,p4) == counterClockOrder(p2,p3,p4)));
}
private static function counterClockOrder(p1:Point, p2:Point, p3:Point):Boolean
{
return (p3.y-p1.y) * (p2.x-p1.x) > (p2.y-p1.y) * (p3.x-p1.x);
}
}
}
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
triangular hittest
wow. i changed it so it uses the inbuilt crossProduct function and done a test to compair the 2 versions of the hittest.
wat i did was i set the frame rate to 120, and made a ball move side to side( so i could see the lag) and i got a messurement on the average FPS. for the test i set a for() loop to run the hittest test 10000 times per 30 ms.
the first test with the function that used an array recorded 17.791 FPS
and the second test using the inbuilt function recorded 41.46 FPS
i was amazed so i even tested it twice to see if it was my computer or the script.
heres the new sameSide function, nothing else has changed other then i deleted the crossProduct function:
private static function sameSide(p1:Point, p2:Point, a:Point, b:Point):Boolean
{
var cp1v:Vector3D = new Vector3D(b.x - a.x, b.y - a.y, 0).crossProduct(new Vector3D(p1.x - a.x, p1.y - a.y, 0));
var cp2v:Vector3D = new Vector3D(b.x - a.x, b.y - a.y, 0).crossProduct(new Vector3D(p2.x - a.x, p2.y - a.y, 0));
if (cp1v.dotProduct(cp2v) >= 0)
{
return true;
} else
{
return false;
}
}
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
triangular hittest
yay, i got it up and running and i found functions for crossProduct and dotProduct in the Vector3D class.
now im going to try to make it exclusively for 2d, because im not going to be using 3d and im gonna b using this in a bigger project some im gonna try and squeeze every bit of performance out of it :P.
anyway heres the code:
public static function TriangleHittest(hittestPoint:Point, triA:Point, triB:Point, triC:Point):Boolean
{
if (sameSide(hittestPoint, triA, triB, triC) && sameSide(hittestPoint, triB, triA, triC) && sameSide(hittestPoint, triC, triA, triB))
{
return true;
} else
{
return false;
}
}
private static function sameSide(p1:Point, p2:Point, a:Point, b:Point):Boolean
{
var cp1 = crossProduct([b.x - a.x, b.y - a.y, 0], [p1.x - a.x, p1.y - a.y, 0]);
var cp2 = crossProduct([b.x - a.x, b.y - a.y, 0], [p2.x - a.x, p2.y - a.y, 0]);
var cp1v:Vector3D = new Vector3D(cp1[0], cp1[1], cp1[2]);
var cp2v:Vector3D = new Vector3D(cp2[0], cp2[1], cp2[2]);
if (cp1v.dotProduct(cp2v) >= 0)
{
return true;
} else
{
return false;
}
}
private static function crossProduct(v1:Array, v2:Array):Array
{
return new Array(v1[1]*v2[2]-v1[2]*v2[1] , v1[2]*v2[0]-v1[0]*v2[2] , v1[0]*v2[1]-v1[1]*v2[0]);
}
Edit: yer i know i could of used the vector3d.crossPoduct() but i was excited that i got it workin and i didnt change it :P
Double Edit: i just figured out how it works nd now i understand that this is as 2d as it’s gonna get
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
triangular hittest
@MaToMaStEr
ok i kinda understand.
is (p1-a)x(b-a) and (p2-a)x(b-a) the cross product part?
and if it is, when ur doing to math functions on them do u do that for the point’s x and y values?
edit:
maybe if u write a function it in a actionscipt function it might help. thx
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
triangular hittest
i was searching the web for irregular shaped hittests and came across this.
http://www.blackpawn.com/texts/pointinpoly/default.html
it seems very usefull but im having alot of trouble understanding it. could someone plz translate it for me :P. it would be VERY!!! useful
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
bitmaps
i can get to about 20 new particals per update b4 it starts lagging, so if u do the math it’s about 5333.33 particals on the screen at once.
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
/**
* ...
* @author Omrelap
*/
public class TestImage extends Sprite
{
public var bitmap:Bitmap;
public var particalPos:Array = [];
public var update:Timer;
public function TestImage()
{
var bitmapData:BitmapData = new BitmapData(400, 400, true, 0x7F000000);
bitmap = new Bitmap(bitmapData);
addChild(bitmap);
update = new Timer(20);
update.start();
update.addEventListener(TimerEvent.TIMER, updateImage);
}
public function updateImage( timerEvent:TimerEvent ):void
{
for (var j:Number = 0; j < 20; j++)
{
createNewParticle();
}
bitmap.bitmapData.lock();
bitmap.bitmapData.fillRect(bitmap.getRect(bitmap), 0xFF000000);
for (var i:String in particalPos)
{
particalPos[i].y += 1.5;
bitmap.bitmapData.setPixel(Math.round(particalPos[i].x), Math.round(particalPos[i].y), 0xFF0000);
if (particalPos[i].y > bitmap.getRect(bitmap).bottom) particalPos.splice(i, 1);
}
bitmap.bitmapData.unlock();
}
public function createNewParticle():void
{
particalPos.push( new Point(Math.round(Math.random() * 400), 0) );
}
}
}
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
bitmaps
ok im experimenting with bitmaps and i’ve created a very simple thing were particles jst fall randomly but this is how i update the bitmap.
bitmap.bitmapData.lock();
bitmap.bitmapData.fillRect(new Rectangle(0, 0, 400, 400), 0xFF000000);
for (var i:String in particalPos)
{
particalPos[i].y += 1.5;
bitmap.bitmapData.setPixel(Math.round(particalPos[i].x), Math.round(particalPos[i].y), 0xFF0000);
}
bitmap.bitmapData.unlock();
see how im filling the bitmap with black before i redraw every particle?
it seems to me that that would be very inifitiant, is that true?
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
Image formats
so it won’t effect the file size if the file is JPEG or PNG or BMP?
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
Image formats
ok im going out of my way to find out which file formats are best used in certain situations.
I’ve done a bit of research and found a list of files that flash imports.
Adobe Illustrator (version 10 or earlier) .ai
Adobe Photoshop .psd
AutoCAD® DXF .dxf
Bitmap .bmp
Enhanced Windows Metafile .emf
FreeHand .fh7, .fh8, .fh9, .fh10, .fh11
FutureSplash Player .spl
GIF and animated GIF .gif
JPEG .jpg
PNG .png
Flash Player 6/7 .swf
Windows Metafile .wmf
my first question is, if im using the Flex Compiler with FlashDevelop, are these formats supported in the Flex compiler aswell?
I’ve been researching mainly BMP, GIF, JPEG and PNG. and here are my conclusions:
BMP is not a very good file format to use because of it’s size and therefore not very good for use on the internet.
GIF supports transpancy and animation although a popular alternitive is the PNG format because although PNG doesn’t support animation it has better compression techneques and a better color range.
JPEG is a great format for storing “natural images”, images that dont have sharp lines. the JPEG image is great because it has a very small file size.
The PNG file format supports truecolor (16 million colors) while the GIF supports only 256 colors. The PNG file excels when the image has large, uniformly colored areas.
GIF and PNG are both use lossless compression while JPEG doesn’t, meaning JPEG will lose quality and devolop small “artifacts” after each time you edit it.
ok my second question is, will the file stay as the original file type when compiled? and if so is it worth worrying about the file size?
|
|
|
Omrelap
137 posts
|
Topic: Collaborations /
need team for bike game
MUST OWN? i see the need for the the artists to work with flash to keep the image size down by using vector graphics but everyone else has no need to have Flash CS4. programmers could use FlashDevelop, which i think is alot better then Flash at editing AS files.
apart from my issues with your requirements, im interested in being a casual programmer but i would like to know what part you will play aswell.
Oh and i have the “trial” version of flash CS4 but i choose not to use it.
|
|
|
Omrelap
137 posts
|
Topic: Off-topic /
"That's Gay"
Originally posted by DMinor:
I’ve noticed a lot of people say “that’s gay” like it’s not big deal, and even more people respond poorly to such a comment. I want to bring attention to a couple of things…
Words have more than one meaning. First of all, “gay” used to mean “happy”. Now it means “homosexual”, and it is slowly evolving to mean “stupid”. I know people have a problem with that, but how is it different from other words? Is it okay to say “that’s dumb”? I mean, “dumb” originally meant “mute”. Can we say “that’s lame”, “that’s idiotic”? “Lame” refers to people who can’t move certain body parts. “Idiot” used to be a real medical term for a mental retard. So what’s the difference between these words, which we use for synonyms of “stupid” now? Can we even say “stupid”? Is saying these words meaning that we are hating on mutes, quadriplegics, retards, and stupid people? If we can’t say “that’s gay”, why should we be allowed to say “that’s lame/dumb/idiotic/stupid”? Is saying “that’s gay” REALLY a discriminatory term? Is it more offensive than saying “that’s lame/dumb/idiotic/stupid”? Or do the people who complain about other people saying “that’s gay” have a serious case of butthurt they need to get over(no pun intended)?
I’m a lesbian, and I don’t have a problem with people using “that’s gay” to describe a stupid situation or thing. It’s just another meaning of a word that also describes homosexuals and happiness. What’s the problem with that?
I agree with you
|
|
|
Omrelap
137 posts
|
Topic: Off-topic /
Pick your doom of 2012
in 2012 i believe Kongregate will become inundated with thousands of crappy games and then the kongregate server will blow up, causing a huge elctromagnic field which will pull the moon towards earth and there will be a huge nuclear winter because of the explosion but that won’t matter because the moon is just about to crash into russia. The impact of the moon won’t kill all of the world’s population, most australians will live because of our pure awesomeness but large and small particals of the moon will start raining on the earth and the last remaining survivers will probably be cosumed by little tiny dust mights living it the moon dust.
THE END.
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
PNG files
yea i figured it out, im using gimp
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
PNG files
how do i get transparent backgrounds for a png file so i can use it in a flash game?
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
[Results] GotW #14
Adrift cuz it was fun :)
|
|
|
Omrelap
137 posts
|
Topic: Off-topic /
hmmm what to do?
Originally posted by overkill861:
and yes i have stabed my self it felt good……im not emo…..
become one? that’ll replace ur boredom emotion with depression XP
|
|
|
Omrelap
137 posts
|
Topic: Off-topic /
How to defeat a troll?
Originally posted by Minnakht:
What is this you’re talking about, it’s not about trolls for sure
But I did safespot them with my Dragon Halberd.
woot NWN is awesome.
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
Flex?
k dat worked thx
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
Flex?
Play in popup didnt work
|
|
|
Omrelap
137 posts
|
Topic: Game Programming /
Flex?
ive been looking into flex and i’m wondering whats the difference between it and flash
Edit: ok another question.
Im using flash develop and ive got it running with the flex compiler and is there anyway i can display trace() commands?
|
|
|