Game Development Community

Projective textures

by Gabriel Bianco · in Torque Game Engine · 11/25/2004 (9:38 am) · 11 replies

Hi... We are trying to make a flashlight for our game. We tried this resource but it didn't really look like a flashlight to me.

So I did some research on how to simulate a spotlight and all the stuff I've found is very similar to this
http://www.opengl.org/resources/tutorials/advanced/advanced96/node27.html.

After a lot of hacking in the engine, I finally found a way to make the three passes work and a lot of hacking later I managed to get it working the way it should. So, now I have the flashlight working, but I can't place it were I want it to be. Here's the relevant piece of code:

glMatrixMode( GL_TEXTURE );
glPushMatrix();
	glLoadIdentity();
	glTranslatef( 0.5f, 0.5f, 0.5f );  // We should use this line, but it works better without it...
	glScalef( 0.5f, 0.5f, 0.5f );
	gluPerspective( 65.0, 0.75, 0.1, 2.2 );

	MatrixF mProj, mView;
	dglGetProjection( &mProj );
	dglGetModelview( &mView );
	mProj.mul( mView );
	mProj.transpose();
	glMultMatrixf( mProj );
Doing that, before the second pass, makes it look like we have a flashlight placed on the camera. But we want it to be on one of the player's mount nodes. According to what I've read, I should, then, apply to the texture matrix "the inverse of the transformations needed to move the light source away from the eye position".

I have the mount transform and the current ObjToWorld matrix, which, I think, are the necessary matrices to get where we want, together with the current model view. But I really can't make it work . :-(
Another way to do it would be to use "gluLookAt()" after the call to "gluPerspective()"... I have the flashlight position, and the it's direction... So calculating all necessary vectors is easy, but I can't get it to work either... :-(

So this is where I'm stuck... Can anyone give a helping hand here? I've been trying to make this work for quite a long time now. I didn't find anything on projective textures in the resources, nor the forums.

#1
11/25/2004 (10:26 am)
I think you need the camera-relative transform matrix for where you want the flashlight to be.

Any changes of this being made into a resource? :)
#2
11/25/2004 (12:18 pm)
Sure... when I manage to get it working properly. :-)

And you are right about the matrix I need... I just can't find the way to calculate it... :P

This is how I think it should be:
Quote:
m -> the matrix we want
mCam -> the camera matrix... I'm not sure if it should be the actual camera matrix or the current model view matrix...
mFL -> where we want the flashlight to be

mCam * m = mFL
m = mCam(-1) * mFL

(-1) = inverse :P

I think my math is right... I guess the problem is in mCam... and mFL might actually be:
mFL = ObjToWorld(-1) * mFL

At this point, I have no idea :-). I'm just trying every single possibility I can think of, hoping one will work...
#3
11/25/2004 (2:31 pm)
Try posting it on the math forum with "help with matrixes" as a title.
#4
11/25/2004 (4:03 pm)
I will give that a shot...
You guys realize the three of us are Brazilian? :-)
#5
11/26/2004 (6:54 am)
Hmm... someone deleted it from the math forum :/
#6
01/05/2005 (8:52 am)
@Gabriel:
Just upgrade to the new TGE 1.3 code base and try to implement the same thing.

So I'm wondering if you've figured out the solution for this?
#7
02/05/2006 (6:08 pm)
I'm curious if you've gotten this to work as well.
#8
02/05/2006 (6:54 pm)
This post is from a year ago.
#9
02/05/2006 (10:59 pm)
So he's curious if they got it to work. This would be the proper place to inquire.
#10
02/06/2006 (1:01 pm)
Yes, just making sure he understands if he doesn't get a response. I ment nothing by it.
#11
02/06/2006 (1:32 pm)
I try to cover all my bases in my inquiries. :P

1. Search, find post, ask.

2. E-mail key posters.

3. Post new thread.