cameraproject() working?

BlitzMax Forums/MiniB3D Module/cameraproject() working?

Spacechimp(Posted 2009) [#1]
I am having a little trouble with cameraproject() projectedx() (and y,z) are giving me some weirdness. (I can't even make sense out of the returns)

Could someone verify if this works/is broken for me? If it is not working properly like I suspect, I was going to rewrite the type. Since I am horrible at math, this looks very scary.


Thank you so much.


Uncle(Posted 2009) [#2]
Cameraproject does work correct. Be aware though you will get strange results if the are projecting a point which out side the camera view.


Spacechimp(Posted 2009) [#3]
Ok, I wrote a test program to try and figure out why this isn't working. I also created a youtube video of this program running, so people could see the results I am getting. (they don't make any sense to me)

I am using Minib3d v0.52 along with Minib3d extended

This is the you tube video of what happens when I run the code below: http://www.youtube.com/watch?v=0uMw33ge86s (you won't be able to read the text unless you press the HD mode button)


'Example file for problems I having with "CameraProject()"




Import "includes/bbvkey.bmx"
Import sidesign.minib3d



Global GFXW = 1024
Global GFXH = 768
'Global GFXD = 32
Global GFXM = 2
'Global GFXR = 60


Graphics3D GFXW, GFXH, GFXD, GFXM, GFXR


'camera control globals
'----------------------
Global forward:Float,straferight:Float,strafeleft:Float,backward:Float
Global x:Float, y:Float, z:Float



'make the camera
'---------------
camera = createcamera() 
light = createlight()
positionentity light, 0, 50, 0
rotateentity light,-40,30,0

'make a room
'-----------
cube = createcube() 
scaleentity cube, - 55, - 55, - 55
entitycolor cube,80,190,70





'make our sphere so we can see the 3d location to be transformed
'---------------------------------------------------------------
sphere = createsphere()
Global SPHEREX=15:Float
Global SPHEREY=3:Float
Global SPHEREZ=13:Float

positionentity sphere, SPHEREX, SPHEREY, SPHEREZ
entitycolor sphere, 255, 0, 0

	
	
		
	
'===================
'**** Main Loop ****
'===================

While Not vkeyhit(1) = True
	

	'----------------------------------------
	'-------   Camera Project Stuff   -------
	'----------------------------------------
	CameraProject camera, SPHEREX, SPHEREY, SPHEREZ
	sphere_projx = projectedx() 
	sphere_projy = projectedy() 
	
	'----------------------------------------
	
	
	
	
	'just some camera controls
	'-------------------------
	
	mxs = (MouseX() - GFXW / 2) 'see how far the mouse has been moved 
	mys = (MouseY() - GFXH / 2)
	MoveMouse (GFXW / 2), (GFXH / 2) 'put the mouse back in the middle of the screen 
	
	
	camerapitch = (camerapitch + mys) 
	camerayaw = (camerayaw + mxs)
	
	
	If vKeyDown(17) 
		forward = .03
	Else
		forward = 0
	EndIf
	
	If vKeyDown(31) 
		backward = -.03
	Else
		backward= 0
	EndIf
	
	If vKeyDown(30) 
		strafeleft = -.03
	Else
		strafeleft = 0
	EndIf
	
	If vKeyDown(32) 
		straferight = .03
	Else
		straferight = 0
	EndIf
	
	z = (forward + backward) 
	x = (strafeleft + straferight)
	
	
	rotateentity camera, camerapitch/5, -camerayaw/5, 0
	
	moveentity camera,x,y,z
	
	
	
	
	UpdateWorld
	RenderWorld
		
	

	Text 3, 10, "Move the camera around with the WASD keys and Mouse."
	Text 3, 25, "Is Projected(X) returning the 2d transformation of the red sphere correctly?"
	Text 3, 40, "(This is set at 1024 * 768)"

	
	Text 3, 130, "ProjectedX() = " + sphere_projx
	Text 3, 160, "ProjectedY() = " + sphere_projy
	
	
	
Flip(False) 


Wend
End



could someone else run this and see if the projectedx() projectedy() make sense?


GfK(Posted 2009) [#4]
Don't know, but is 1FPS normal for such a basic app??


Spacechimp(Posted 2009) [#5]
The video? oh, the actual program doesn't run like that. Only when I am recording for a video. sorry.


simonh(Posted 2009) [#6]
Works fine here (V0.52). This version prints the text at the location of the sphere:




Spacechimp(Posted 2009) [#7]
I have a Fresh reinstall of BMax and MiniB3d. The projection works now.

Thanks for the help, and for having patience with me. If I figure out what caused the problem, I will let you know.

Thanks!


Difference(Posted 2009) [#8]
simonhs version shows correct results for me.

Spacechimps version shows the weird results.

[EDIT]: Actually I think they are both ok, it's just results for when the sphere is offscreen.

simons version is easier to check


Difference(Posted 2009) [#9]
.


Spacechimp(Posted 2009) [#10]
Ty Peter