OpenGL Camera

Advanced game related topics
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

OpenGL Camera

Post by Polo »

I'm trying to do a camera with OpenGL, but it seems to be extremely difficult. I have readed some C++ tutorials, but, for the moment, I have some troubles to make it in Purebasic, it don't seems easy to translate it... Could someone help ? Perhaps someone here have already does that and can post his code :)
DarkDragon
Addict
Addict
Posts: 2348
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Uhm, you can define the view with glMatrixMode_(#GL_PROJECTION) : glLoadIdentity_() : Your Code : glMatrixMode_(#GL_MODELVIEW)
"Your Code" can be replaced by glOrtho, glViewport and so on. Look in the OpenGL tutorials.

My favorites:
1: http://nehe.gamedev.net/
2: http://gametutorials.com/
3: http://www.ultimategameprogramming.com/index2.php

And I have the OpenGL helpfile, but I don't know where you can download it.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

I have already looked at all these tutorial, the fact is I can't make them in Purebasic, because it uses Vector, and I can't use it on Pure...
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

If you can translate the camera tutorial 3 of Gametutorials in Purebasic, well, please do it, me I can't :)
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo wrote:If you can translate the camera tutorial 3 of Gametutorials in Purebasic, well, please do it, me I can't :)
What exactly is your problem with this?
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo wrote:[...]because it uses Vector, and I can't use it on Pure...[...]
:?:

"Vector" is neither C nor OpenGl-related.

I'm just taking a guess here, but maybe this may bring you on the right track:

Code: Select all

Structure Vector3
  x.f
  y.f
  z.f
EndStructure
and this

Code: Select all

float Magnitude(CVector3 vNormal)
{
	// This will give us the magnitude or "Norm" as some say of, our normal.
	// The magnitude has to do with the length of the vector.  We use this
	// information to normalize a vector, which gives it a length of 1.
	// Here is the equation:  magnitude = sqrt(V.x^2 + V.y^2 + V.z^2)   Where V is the vector

	return (float)sqrt( (vNormal.x * vNormal.x) + 
						(vNormal.y * vNormal.y) + 
						(vNormal.z * vNormal.z) );
}
becomes

Code: Select all

Procedure.f Magnitude(*vNormal.Vector3)
  ProcedureReturn Sqr( (*vNormal\x * *vNormal\x) + (*vNormal\y * *vNormal\y) + (*vNormal\z * *vNormal\z) )
EndProcedure
and so on...
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Ok, thanks, I see. But is there a way to do camera without vectors ?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Have troubles with translating that :

// Normalize the direction.
float dp = (float)sqrt(xLookDirection * xLookDirection + yLookDirection * yLookDirection + zLookDirection * zLookDirection);
xLookDirection /= dp;
yLookDirection /= dp;
zLookDirection /= dp;


Well, I don't know what I'm supposed to put ...
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

Polo wrote:Have troubles with translating that :

Code: Select all

; Normalize the direction. 
dp.f = Sqr(xLookDirection * xLookDirection + yLookDirection * yLookDirection + zLookDirection * zLookDirection)
xLookDirection / dp
yLookDirection / dp
zLookDirection / dp
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

The problem is that what Danila as wrote don't work at all... If I don't put it, (I have translated all except this), well, it works, but the camero don't always go where it is supposed to, and if I put what Danilo as wrote, well, the camera don't move :oops:
...
Does someone know how to make it works ? I have worked on it for 4 hours, and it still doesn't work :?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo wrote:The problem is that what Danila[...]
:lol:
Does someone know how to make it works ? I have worked on it for 4 hours, and it still doesn't work :?
The problem must be somewhere else as Danilos "translation" is correct

Ok, thanks, I see. But is there a way to do camera without vectors ?
Vector-Math is one of the essentials in 3D programming. Is that what you mean?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Forget what I say with vectors....
Well, I join an EXE file of my camera test, and you'll see the problem :

http://www.gtnsoft.com/Pure3D.exe

To move, just use the Arrow keys...
DarkDragon
Addict
Addict
Posts: 2348
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

^^ Black. I have the same problem, when I use gluPerspective, gluPerspectivef or gluPerspective__. I don't know what I'm making wrong, because I have tryed gluPerspective with all known standardparameters of other languages.

Can you give us your code to test it?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo wrote:Forget what I say with vectors....
done. :)
Well, I join an EXE file of my camera test, and you'll see the problem :
With "Problem", do you mean seeing "nothing" or a not expected behaviour in movement?
I can't see anything on my pc at work (ATI) but it displays fine on my Geforce4 at home.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

You see nothing ? Well... No it wasn't the problem :(
Well, can you try the camera with th pc where it works, and tell me what I'm doing wrong ?

For the other problem, well...

Darkdragon, do you get an error message or is it just black ??
Post Reply