Hello,
for a simple game I'm working on I need to be able to 'camerapick' sprites to work out whether a masked/alphaed pixel/texel has been picked. I'm using an orthographic projection (Camera aligned to vector -1,-1,1 in x,y,z coords). As you know the pick commands do not work with sprites using 'polygon' pick detection.
I have managed to write some code that does what I need (it returns the UV location on a sprite's texture) by a bit of trial and error with particular numeric values taking in to account the camera zoom and sprite scale and sprite handleoffset (handlesprite command)
However - there is obviously an equation/formula which would be able to give me this result for any camera zoom, for any sprite scale and any sprite 'handlesprite' offset.
If someone would be able to assist with this I would appreciate that.
Thanks very much.
EDIT - here is the code I currently use to do this:
That is a short snippet, I haven't included the type declarations but it should be fairly obvious what is going on there...
for a simple game I'm working on I need to be able to 'camerapick' sprites to work out whether a masked/alphaed pixel/texel has been picked. I'm using an orthographic projection (Camera aligned to vector -1,-1,1 in x,y,z coords). As you know the pick commands do not work with sprites using 'polygon' pick detection.
I have managed to write some code that does what I need (it returns the UV location on a sprite's texture) by a bit of trial and error with particular numeric values taking in to account the camera zoom and sprite scale and sprite handleoffset (handlesprite command)
However - there is obviously an equation/formula which would be able to give me this result for any camera zoom, for any sprite scale and any sprite 'handlesprite' offset.
If someone would be able to assist with this I would appreciate that.
Thanks very much.
EDIT - here is the code I currently use to do this:
CameraProject camera,EntityX(Creature\SpriteHandle,True),EntityY(Creature\SpriteHandle,True)+(Template\SpriteScale)^2*0.35,EntityZ(Creature\SpriteHandle,True) f#=0.0105 ;I'd like to know how to calculate what this factor should be rather than just using one from trial and error ulx=ProjectedX()-(template\spritescale/(f)) ;0.015 is the camera zoom with the orthographic camera in use uly=ProjectedY()-((template\spritescale)/(f)) lrx=ProjectedX()+(template\spritescale/(f)) lry=ProjectedY()+((template\spritescale)/(f)) ;Color 255,255,255 ;Rect ulx,uly,Abs(lrx-ulx),Abs(lry-uly),0 If MX>=ulx And MY>=uly And MX<lrx And MY<lry And LRX<>ULX And LRY<>ULY Then ;we are within this creature's bounding box for the sprite texture If Creature\TexHandle<>0 Then ;this creature has a valid texture handle...hopefully.we'll soon see. ;convert the coordinates into UV coords for the texture....(mx and my are mouse coordinates) U#=Float(MX-ULX)/Float(Abs(LRX-ULX)) V#=(Float(MY-ULY)/Float(Abs(LRY-ULY))) If U<0 Then U=0 If V<0 Then V=0 If U>1 Then U=1 If V>1 Then V=1 SetBuffer TextureBuffer(Creature\TexHandle) XCoord=TextureWidth(Creature\TexHandle)*U YCoord=TextureHeight(Creature\TexHandle)*V If XCoord>=TextureWidth(Creature\TexHandle) Then XCoord=TextureWidth(Creature\TexHandle)-1 If YCoord>=TextureHeight(Creature\TexHandle) Then YCoord=TextureHeight(Creature\TexHandle)-1
That is a short snippet, I haven't included the type declarations but it should be fairly obvious what is going on there...