Draw3dMouse() - Should This Not Work?

Blitz3D Forums/Blitz3D Programming/Draw3dMouse() - Should This Not Work?

Gabriel(Posted 2003) [#1]
Just writing a little 3dMouse function which draws a quad where the mouse is, relative to camera and zoom. The mesh is setup in an Init Function, and works fine if I don't zoom the camera. In fact, I can see the mouse if I use a lower camzoom than the real value, but obviously it's out of it's depth. The camzoom# I'm using in my program is currently 2.5 and it works at 1.5 ( but wrong depth obviously ) so I figured it was a zorder problem. But I've got it set as -99 so it should be drawn first, no?

I'm using it in combination with FonText, but I don't think that's relevant as I can't see it elsewhere on the screen either. Any ideas what might be wrong?

Function Draw3dMouseRelative(cam,camzoom#)

mx=MouseX()
my=MouseY()
ClearSurface mousesurface
x1=mx-mousehw
x2=mx-mousehw+50
z1=mousehw*camzoom#
y1=mousehh-my
y2=mousehh-my-50

; TRANSFORMING OF POINTS

TFormPoint x1,y1,z1,cam,0
tx1=TFormedX#()
ty1=TFormedY#()
tz1=TFormedZ#()
TFormPoint x2,y1,z1,cam,0
tx2=TFormedX#()
ty2=TFormedY#()
tz2=TFormedZ#()
TFormPoint x2,y2,z1,cam,0
tx3=TFormedX#()
ty3=TFormedY#()
tz3=TFormedZ#()
TFormPoint x1,y2,z1,cam,0
tx4=TFormedX#()
ty4=TFormedY#()
tz4=TFormedZ#()


; ADD VERTICES

v1=AddVertex(mousesurface,tx1,ty1,tz1,0,0)
v2=AddVertex(mousesurface,tx2,ty2,tz2,1,0)
v3=AddVertex(mousesurface,tx3,ty3,tz3,1,1)
v4=AddVertex(mousesurface,tx4,ty4,tz4,0,1)


; ADD TRIANGLES
AddTriangle(mousesurface,v1,v2,v4)
AddTriangle(mousesurface,v2,v3,v4)

EntityOrder mousemesh,-99

End Function


Ross C(Posted 2003) [#2]
Sorry, not really related to your problem, but i belive it's faster to not clear the surface all the time. Just re-adjust the vertexs.


Jeppe Nielsen(Posted 2003) [#3]
Couldnīt you use a second camera like in this piece of code?:
HidePointer
Graphics3D 800,600,16,2



Init3DMouse("Pointer.png")


Repeat
Cls


Draw3DMouse(MouseX(),MouseY())

RenderWorld

Flip

Until KeyDown(1)
End

Global mousecamera3d
Global mousepivot3d
Global mouseentity3d,mousetexture3d

Function Init3DMouse(file$,flags=1+2+16+32,order=-99,x#=10000,y#=10000,z#=10000)
Clear3DMouse()

mousecamera3d=CreateCamera()
PositionEntity mousecamera3d,x,y,z
CameraClsMode mousecamera3d,0,1
CameraRange mousecamera3d,1,2
EntityOrder mousecamera3d,order

mousepivot3d=CreatePivot(mousecamera3d)

PositionEntity mousepivot3d,-1,Float(GraphicsHeight())/GraphicsWidth(),1
scale#=2.0/GraphicsWidth()
ScaleEntity mousepivot3d,scale,-scale,1

mousetexture3d=LoadTexture(file$,flags)
mouseentity3d=CreateMesh(mousepivot3d)
EntityFX mouseentity3d,1+8

surf=CreateSurface(mouseentity3d)

w#=Float(TextureWidth(mousetexture3d))
h#=Float(TextureHeight(mousetexture3d))

v=AddVertex(surf,0,0,0 ,0,0)
AddVertex(surf,w,0,0 ,1,0)
AddVertex(surf,w,h,0 ,1,1)
AddVertex(surf,0,h,0 ,0,1)

AddTriangle(surf,v,v+1,v+2)
AddTriangle(surf,v,v+2,v+3)

EntityTexture mouseentity3d,mousetexture3d

End Function

Function Clear3DMouse()

If mousetexture3d<>0 Then FreeTexture mousetexture3d: mousetexture3d=0
If mouseentity3d<>0 Then FreeEntity mouseentity3d: mouseentity3d=0
If mousepivot3d<>0 Then FreeEntity mousepivot3d: mousepivot3d=0
If mousecamera3d<>0 Then FreeEntity mousecamera3d: mousecamera3d=0

End Function

Function Draw3DMouse(x,y)

	PositionEntity mouseentity3d,x,y,0

End Function



GfK(Posted 2003) [#4]
I've got a 3D mousepointer going with FONText.

If you intend to use camerazoom on your main camera, then you'll find you'll get into all sorts of bother trying to get the HUD to work on the same camera.

Set up a dedicated camera for the HUD and do it that way. Place it miles away from your game area, pointing the opposite direction. You'll find it'll render just as quickly as if you were using a single camera.


Gabriel(Posted 2003) [#5]
I realised what my problem was. The tforming and 3d<>2d coordinate conversion was producing z coordinates greater than the camerarange, so it was easy to fix.

Jeppe : Thanks for the code. I'll look through it when I have a chance and see what I can learn. I'm really, really bad at reading other people's code, which is why I wanted to fix my own really. I do appreciate it though, and I'm sure I can learn something from it.

GFK : I'm not actually zooming the camera, I just have it set to something other than 1 when I first create it. It's still a constant though, and it would be quite a lot of code to change to move all my FonText Hud stuff to a separate camera. I'll certainly keep that in mind if I do need proper camera zooming though.


Gabriel(Posted 2003) [#6]
Oops, missed Ross in middle there. I'm using ClearSurface because I use it in my single surface sprite and entity system. In that context, it's considerably faster to rebuild than to manipulate. In the context of a single sprite though, you may be right. I'll check on that.