Alright after a bit of thinking about how I could create dynamic shadows I wrote a crude algorerhythm that sort of approaches the problem using SFML. The general idea is that the light source casts out rays and the collision locations of these rays help shape the general outline of the light
Its very simplistic and has quite a few problems that probably will prevent it from working properly let alone being suitable for real time shadows but its simply a jumping board.
What are some suggestions,improvement, or outright replacements you can come up with? And if there are any outright mistakes feel free to point that out as well I didn't check this in the compiler.
Some Current Problems
1. For and while loops: can eliminate them but replacing them with if statements can cause problems with the light not being generated properly.
2. The light ray movement hinders the ability of the light to change quickly
3. Low resolution: Can be solved by increasing amount of rays cast but this may slow things down.
4. Testing rays for collisions against all objects: Slow but I'm not sure what other options there may be.
5. Light Polygon might not form properly if concave.
//Point light:
//place pixel light
light.SetPosition(200,200);
//place light circle
lightcircle.SetPosition(200,200)
//Optional Step: Check for collision of light circle can be substituted with continuous scanning
for(itcirchk=0;itcirchk<=objectlist.size();itcirchk++)
{
if (CircleTestCollision(lightcircle,object[itcirchk].Mass)==1)
{//If collision, start raycasting every x degrees to form shape of light polygon
xlightray=.1;
ylightray=-.9;
do
{
while(distancebetweenobjects(light.Mass,bullet)<=100)//while the ray is in the light's range
{
lightray.move(xlightray,ylightray);
for (itraycolchk=0;itraycolchk<=objectlist.size();itraycolchk++)
{//every step check ray for collision against all objects
if (PixelPerfectCollisionCheck(lightray,objectlist[itraycolchk])==1);
{ //If collision record ray location and add to polygon generation vector.
recordpoint.x=lightray.GetPosition().x;
recordpoint.y=lightray.GetPosition().y;
pointvector.pushback(recordpoint);
pointreached=1;
break;//move on to next ray
}
}
if pointreached==1;
break;//break out of loop to cast next ray
else if (distancebetweenobjects(light.Mass,lightray)>=100)
{//if ray has traveled light's range without collision add another point to polygen vector
recordpoint.x=lightray.GetPosition().x;
recordpoint.y=lightray.GetPosition().y;
pointvector.pushback(recordpoint);
}
}
//change direction ray will travel in clockwise fashion
if ( xlightray>=0 && xlightray<=1 && ylightray>=-1 && ylightray <=0)
{//first quadrant
xlightray=xlightray+.1;
ylightray=ylightray+.1;
}
else if (xlightray >=0 xlightray<=1 && ylightray>=0 && ylightray>=1 )
{//second quad
xlightray=xlightray-.1;
ylightray=ylightray+.1;
}
else if (xlightray>=-1 && xlightray<=0 && ylightray<=1 && ylightray>=0)
{//third quad
xlightray=xlightray-.1;
ylightray=ylightray-.1;
}
else (xlightray>=-1 && xlightray<=0 && ylightray<=0 && ylightray>=-1)
{//fourth quad
xlightray=xlightray+.1;
ylightray=ylightray-.1;
}
}while (xlightray!=0 && ylightray!=-1)//run loop till rays have been cast in full circle
}
}
//Draw light polygon based on points in vector
for (itpolydrw=0;itpolydrw<=pointvector.size();itpolydrw++)
LightPolygon.AddPoint(pointvector[itpolydrw].x,pointvector[itpolydrw].y)
//Color polygon
LightPolygon.SetColor(sf::Color(255, 255, 255, 200));