Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Lighting in 2D using DX8
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 3

Spodi
Warrior

USA
142 Posts

Posted - Apr 28 2004 :  5:47:06 PM  Show Profile  Visit Spodi's Homepage  Send Spodi an AOL message  Click to see Spodi's MSN Messenger address  Send Spodi a Yahoo! Message  Reply with Quote
"using pythagoras' good old theorem"

Just wondering, how would "A^2 + B^2 = C^2" help? Isn't this to calculate the hypotineus (or slanty-thingy) of a triangle?


vbGORE
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Apr 28 2004 :  5:55:24 PM  Show Profile  Reply with Quote
You can use it to calculate the distance between two points by using the x,y coordinates as two of the sides of the triangle and the "hypotineus" (if it's spelled that way) for the distance.

Whatever. Who knows...
Go to Top of Page

Spodi
Warrior

USA
142 Posts

Posted - Apr 28 2004 :  8:55:41 PM  Show Profile  Visit Spodi's Homepage  Send Spodi an AOL message  Click to see Spodi's MSN Messenger address  Send Spodi a Yahoo! Message  Reply with Quote
OOooooooooooohhhh, okay, that makes sense, thanks. And yeah, I dont think it's "hypotineus", wouldn't trust my spelling. :)

vbGORE
Go to Top of Page

cjb0087
Knave

Australia
76 Posts

Posted - Apr 29 2004 :  04:58:33 AM  Show Profile  Visit cjb0087's Homepage  Reply with Quote
but that would require the deadly square root function, because a=sqr(b*b+c*c) (a*a is faster than a^2), if the light is stationary maybe you could calculate the verticies at load time?

www.bugsplat.tk
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Apr 29 2004 :  09:08:41 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Are there going to be shadows in the game?
Go to Top of Page

EACam
Warrior

154 Posts

Posted - Apr 29 2004 :  12:26:03 PM  Show Profile  Reply with Quote
Shadows? Sure, that would be a cinch...if I make them look kind of cheap. I would simply loop through that box from the inside out and stop when I get to a barrier (that is, stop for that direction only). It would work, kind of...I'll have to develop it tho, so far this is all theoretical.

Aw, the square root function isn't THAT slow, is it? For the example I gave a while ago, that would be, hmmm, let's see here...area = 7x7 = 49, so 49 tiles to possibly go through, then 49x4 since there are 4 vertices in each tile...that's 196 Sqr operations for one, kinda small light. Ok, so maybe I should try optimizing it somehow. Perhaps in my level editor I could make certain lights be precalculated. Then for the moving ones (i'll have enough of those), i'll do it during run-time.

Go to Top of Page

cjb0087
Knave

Australia
76 Posts

Posted - May 01 2004 :  12:10:30 AM  Show Profile  Visit cjb0087's Homepage  Reply with Quote
you could probably check the inline asm thingo at persistant realities, i *think* there is a squareroot function there

www.bugsplat.tk
Go to Top of Page

EACam
Warrior

154 Posts

Posted - May 01 2004 :  6:36:34 PM  Show Profile  Reply with Quote
I did some testing; lighting in 2D [using my method, anyway] works like a charm, with a little optimization it'll be working like Sampson at the treadmill. And Spodi, I don't get the slightest hint of a triangle. It's PERFECTLY attenuated and circular.
Go to Top of Page

Spodi
Warrior

USA
142 Posts

Posted - May 02 2004 :  1:59:27 PM  Show Profile  Visit Spodi's Homepage  Send Spodi an AOL message  Click to see Spodi's MSN Messenger address  Send Spodi a Yahoo! Message  Reply with Quote
Hmm, well I'll try doing it again. Do you think you can send me what you got though for reference?

vbGORE
Go to Top of Page

SuperC
Squire

11 Posts

Posted - May 02 2004 :  2:07:59 PM  Show Profile  Click to see SuperC's MSN Messenger address  Reply with Quote
This might help

http://www.eastcoastgames.com/articles/2dlight.htm
Go to Top of Page

EACam
Warrior

154 Posts

Posted - May 02 2004 :  8:37:42 PM  Show Profile  Reply with Quote
Spodi, this example will work ONLY with how it's set up. I've tried changing the range and things get messed up, but the principle is the same...kind of.

I basically did this:

Range = 200

TileGeom(0).Color = D3DColorRGBA(Range - DistanceBetweenLightAndThisVertex, Range - Distance...., ...., 255) ' Notice, the 255 is the alpha value, so it's opaque. This doesn't work with colored lights or anything. It doesn't have customizable attenuation, but it works.
TileGeom(1).Color = ...
...for all four vertices.

This is a bad example here, because you have to do something else. You have to have a variable that holds the color because you need to check if it's negative. If it is, just make it 0.


Now, my tiles are 32x32. They were all rotating CC in my test app, and everything looked fine. When I increased the range, I got dark splotches in the middle of the light area. When I decreased the light range, the whole thing got dimmer. I'll work on this and pop a post when its fixed up.

Note, this is TOTALLY UNOPTIMIZED. I did this calculation to ALL of the tiles on the screen, not just those within range like I should have. This only works with ONE light. So basically, this is a pretty lame example, but it was perfectly circular.

Sorry this is so confusing...I'll try to fix it up and post my results.

Edited by - EACam on May 02 2004 8:39:53 PM
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.