Now let me explain the process that I go through every time the player moves. There must be something that I could eliminate, as it seems unnecessarily bulky.
[list=1][*]get direction vectors from player to each corner of one of the blocks[*]dot product every direction vector combination of to find the maximum angle in order to see which corners get their rays extended.[*]extend the rays from the two corners found in last step to well beyond the bounds of the movie[*]calculate intercept between movie bounds and the two rays then change the endpoint of each[*]find what corners of the movie should be filled and add them to the draw list[*]draw and repeat for each obstacle[/list=1]
Now originally I didn't do step 4 or 5, but it started acting weird on me and ran just as slowly. What can I do???
Is the acos function slow? What about sqrt? Could I put some lookup tables in (i don't need perfect accuracy).
And I know about the bugs.
Last edited by devnull_2k; 10-17-2002 at 12:49 AM.
The future belongs to those who prepare for it today.
Originally posted by devnull_2k [list=1][*]dot product every direction vector combination of to find the maximum angle in order to see which corners get their rays extended.[*]extend the rays from the two corners found in last step to well beyond the bounds of the movie[/list=1]
These seem like the time-consuming steps to me. First, a dot product for every vector combination would be quite a lot of calculations, right? And second, if you're extending the rays a very long way, then flash might simply be taking a long time to render it.
I'm guessing it's #1
For War's a banker, flesh his gold. There by the furnace of Troy's field, Where thrust meets thrust, he sits to hold His scale, and watch the spear-point sway; And back to waiting homes he sends Slag from the ore, a little dust To drain hot tears from hearts of friends
Limehouse, Ontario - Never heard of it? Not surprised.
Posts
785
But its necessary. How else would I find what corners extend the shadows? Its always the two with the largest angle between them. If you have another way, I'd be happy to hear it.
But you gave me an idea. Right now I'm calling sqrt 14 times per obstacle per frame. I can cut it down to 4.
And about extending the rays. They're extended but not drawn. Its just math until the end.
I also noticed that the variables stay set across frames. Should I unset them to free mem?
Last edited by devnull_2k; 10-17-2002 at 12:56 PM.
The future belongs to those who prepare for it today.
Originally posted by devnull_2k I also noticed that the variables stay set across frames. Should I unset them to free mem?
unless there are a lot of variables, this probably isn't causing any harm.
if you post the fla I'll take a look at it
For War's a banker, flesh his gold. There by the furnace of Troy's field, Where thrust meets thrust, he sits to hold His scale, and watch the spear-point sway; And back to waiting homes he sends Slag from the ore, a little dust To drain hot tears from hearts of friends
Limehouse, Ontario - Never heard of it? Not surprised.
Posts
785
Maybe in a bit. At the moment my classes and functions are almost entire uncommented and I'm sure a bit confusing (though quite organized).
I was also thinking of something else. I haven't totally worked it out in my head yet, but it would be something like this. On one frame it would check it any of the shadows overlap, then on the next few it would eliminate corner calculations for the covered corners until uncovered. I'm not sure if it would speed it up or not.
The future belongs to those who prepare for it today.
ok, sorry not to get back for so long, a client of mine suddenly escalated a project and I had to get by head back into work-mode
In the end, I decided that really the cause of your code's slow speed was just all the math. If this was just an in-between stage to a bigger goal and you need the math as it was, hmmm...
But in the meantime, I started over from scratch and worked the same effect using large if statements instead of mucho math (unlike trig functions, flash handles if statements very well). The overall effect is largely the same, although not 100% complete.
On my computer, I'm getting in the mid-40s frames-per-second. Pretty good improvement
The drawbacks are:
[list=1][*]I didn't have time to add methods to calculate shadows when the light-source is inside the outer bounds of the object.[*]I didn't have time to comment the code. So if you have trouble with any of it just ask. Sorry, but just didn't have the time for it.[*]there's a weird bug when the light source is underneath the blue box on the bottom. I have no idea what is causing that. Again, no time to look into it.[/list=1]
But on the up-side, the points are draggable, which was a neat feature that my code allowed me to add very quickly (it literally took me about 90 seconds to go from static to dynamic points!) -- and it shouldn't be too hard to add a flexible number of points also.
For War's a banker, flesh his gold. There by the furnace of Troy's field, Where thrust meets thrust, he sits to hold His scale, and watch the spear-point sway; And back to waiting homes he sends Slag from the ore, a little dust To drain hot tears from hearts of friends
nope, all you have to do is drag the corners. It uses the same calculations.
the only problem goes back to how I didn't add the code to compute what happens if the lightsource is from within the block -- and with angled blocks there is 'empty space' that is still technically within the outer bounds of the block.
but from a normal position, it works fine.
For War's a banker, flesh his gold. There by the furnace of Troy's field, Where thrust meets thrust, he sits to hold His scale, and watch the spear-point sway; And back to waiting homes he sends Slag from the ore, a little dust To drain hot tears from hearts of friends