A flashlight - How to do perspective projection?

Blitz3D Forums/Blitz3D Programming/A flashlight - How to do perspective projection?

bytecode77(Posted 2007) [#1]
hi!

i was working on a flashlight source a time ago and i discovered that tformpoint helps a lot. it helps me to project the flashlight texture.
the only problem is that the texture is projected parallel and not perspectively. parallel in this case means, that the flashlight spot will appear with the same size in every possible distance!!!
it's like the flashlight has a diameter of 2 meters and would project like a laser!!!

is there a way to project this whole thing perspectively?

http://dev-ch.de/upload/files/Devils%20Child/Flashlight.zip (786.82 KB)

if you don't find out, you still have my source code which works almost well Smiley
thanks for ANY help!!:)
bye


Dreamora(Posted 2007) [#2]
Your calculations use the flash light radius and fixed values.
But there is no calculation basing on the distance and the zoom / Field of View
That would be needed to calculate the real radius depending on the distance to the flash light source


big10p(Posted 2007) [#3]
I havent looked at the source but cant you just scale the radius based on distance?


bytecode77(Posted 2007) [#4]
if i scale down the flashlight spot for every vertex, i get a spot with a shape of a heart or something...

but i could use the Z-DISTANCE instead of radial distance. i dont know how to do that or wheter it will work!


Dreamora(Posted 2007) [#5]
The main problem actually will be that the UV needs to be stretched from the center out. So you will most likely need Fredborgs code archive entry for PickedU PickedV to get the "picking point" UV and stretch it from there.

Your projection has a different problem anyway: you only do one pic ... that can not work unless you are prependicular to the wall and the wall is flat ...

btw: Did you have a look at Fredborgs image projector sources he uploaded long ago? (the batman like projector in a closed room)


bytecode77(Posted 2007) [#6]
i know that badmap projector. its pretty cool! also, it causes the "hear-shape" problem i described before



Dreamora(Posted 2007) [#7]
Thats an issue not bound to the projection.

Thats an issue thanks to the fact that the line of disortion there is a polygon border between 2 triangles ... Thats the same as the texture disortion you get with 2 polygons next to each other where it looks like the texture is targetting the top right corner.


bytecode77(Posted 2007) [#8]
so the soultion must be something between fredborg's idea and mine.
fredborg is projecting it the way, that the spot gets dynamicly bigger on each distance. that causes the glitch of that "heard shape" i dont have. but i have no size-correction...
or how ever i should explain:(


so whats your idea?


Dreamora(Posted 2007) [#9]
Identifying fredborgs projection method and trying to integrate it into yours.

But I'm not sure if yours does not suffer this problem actually. The pillars are a very bad object to check for it as they always have near-perpendicular surfaces

But as you are the master of "stencils" ;-): Wouldn't it be simpler just project it that way instead of trying to fake something that will not work with objects smaller than the light radius at the given distance (you would need far more than only 1 pick to make that work)

Alternatives are investigating jRenderMonkey, OGRE and others texture projectors.


bytecode77(Posted 2007) [#10]
i thought about stencils for a moment but than realized that this is not possible with stencils but rather with some tformpoint or pick operation...

but every solution i tried yet ends up in crippled "heard like shape" or in parallel projection :(


Dreamora(Posted 2007) [#11]
"some" is exactly the problem.
You would need a far higher amount of picks ... if you did that, you could actually do it easily by using Fredborgs PickedU PickedV even with projection :)


bytecode77(Posted 2007) [#12]
yes, so i actually need to double and tripple every polygon in the scene. even if i use 10 times more polys it doesn't look very better


Dreamora(Posted 2007) [#13]
I don't see where more polygons should help with that problem that a perspective projection should check the perspective to project :)

But I am sure there must be a more intelligent way to solve this issue.
You mentioned that stencils don't work for this purpose.
But there are still z Buffers and Acum Buffers to missuse although I don't think that the later one is an option in DX7


bytecode77(Posted 2007) [#14]
well then, at best would to ask Tom.
so Tom if you read this, can you help us please :)