usable camera

BlitzMax Forums/OpenGL Module/usable camera

Tom(Posted 2005) [#1]
Hi,

I started ripping the basic out of my GL code last night so you could see how my camera & hierarchy works. Here's something to mess about with, I'll add in the get x/y/z pitch/yaw/roll stuff later.

Check the source for keys to use in this demo, and have a good mess abotu and see how the parenting looks & works. I've tried to keep it as close to Blitz3Ds as possible.

Which reminds me, you really have to appreciate Marks entity functions in Blitz3D, I've NEVER come across such a cool system in any sample code out there on the net.

Well done BRL! :P

Sorry for sloppy code, I'm absolutely full of flu and can't even enjoy a holiday beer because of medication, BLEH!!! :)

Oh, and I use 2 space tabs in my IDE...




Dubious Drewski(Posted 2005) [#2]
That's very good. Bravo. Now if I can get the Nehe tutorial 13 to load
meshes into this, I might get a jump-start on finally making games in 3d.

Splendid work, my friend.


Tom(Posted 2005) [#3]
Updated with entity.getX() Y & Z, entity.getPitch() Yaw & Roll


ChiefDano(Posted 2005) [#4]
Tom - good work on the camera sample.

Drew - I am Just curious how you are going to implement collision detection. Are you going use bounding boxes (or other primitives) only, or some type of polygon to polygon collision test also?


Dubious Drewski(Posted 2005) [#5]
I am almost certain I will go with the most basic aproach I
can get away with. That would be points and planes. I have
most of the mechanics worked out and I'm testing different
methods like mad. This seems to be the easiest and most
reliable solution for me.


Chris C(Posted 2005) [#6]
do a search for loadbsp I did theres some ray to poly collision code, didnt work with the bsp sometimes (maybe odd bsp winding)

If its useful I could tidy it up a bit


Chris C(Posted 2005) [#7]
@tom
The light dawns!
If yawV <> 0.0 glRotatef yawV , mat.m[1], mat.m[5], mat.m[9]
If pitchV<> 0.0 glRotatef pitchV, mat.m[0], mat.m[4], mat.m[8]
If rollV <> 0.0 glRotatef rollV , mat.m[2], mat.m[6], mat.m[10]

neat work tom!


Tom(Posted 2005) [#8]
Updated, scaling is in. I just realised I was doing it wrong too, sorted! :)

Use square brackets to scale cube2


Tom(Posted 2005) [#9]
Added PointAt()


Chris C(Posted 2006) [#10]
nice work tom, thanks for sharing, at this rate no ones gonna want to buy the 3d module ;)


Tom(Posted 2006) [#11]
Hell, I will! :)

I hope it comes out sooner rather than later though. Might go bug Mark for an update on it actualy.


Chris C(Posted 2006) [#12]
had troubles with view ports that overlap, ie say 1 full screen with 1 smaller window over the top of it, how do you clear the smaller viewport so it cant be seen through...


Tom(Posted 2006) [#13]
Haven't tried overlapping yet, will see what happens.


Chris C(Posted 2006) [#14]
There seems to be a problem with getPitch it will sometimes return NAN

I notice its calculated in a different way to getYaw and getRoll, which two matrix elements you I need to use for pitch?


Jim Teeuwen(Posted 2006) [#15]
This is a very nice piece of work. Thanks for sharing!

I was reading through the code and noticed some inconsistencies though. May be just because the code needs some cleaning up.

For instance, in the tEntity.SetParent() method, there is a code block that is never executed.

...
Else 'Parent Globaly *WORKING*
	'Remove Self from any existing parents childlist
	'and multiply the matrix to leave it in its current
	'world space position and rotation
	If parent
		Local gpa:tEntity = parent
	
		'Transform matrix into world space
		While gpa
			mat.Multiply(gpa.mat)
			gpa = gpa.parent
		Wend
	
		'Remove Self from the old Parents list
		RemoveLink parentLink
		parentLink = Null
		parent = Null
	End If



The part between 'If parent..' and 'end if' will never be called, since a few lines up you are performing:

If parent
	RemoveLink parentLink
	parentLink = Null
	parent = Null
End If


So if it reaches the first posted snippet, parent will always be Null.

Nothing Important, but may be worth cleaning up sometime to make it easier to read.

Oh, and the tCamera.ScreenProject() method isn't finished :)

And another one: the RenderEntity() method has a type-o
			If ThisScaleMode = 1
				glEnable GL_RESCALE_NORMAL
			Else If ThisScaleMode = 2
				glEnable GL_NORMZLIZE
			End If
	End Select


'glEnable GL_NORMZLIZE' should be 'glEnable GL_NORMALIZE'.


Tom(Posted 2006) [#16]
Well spotted, prize is in the post :P


kfprimm(Posted 2006) [#17]
glEnable GL_NORMZLIZE

thats why we have Strict :)


Pineapple(Posted 2006) [#18]
I like the wireframe cameras... very cool! :)

Great stuff Tom

Dabz