2d mouse pointer on a 3d map
Blitz3D Forums/Blitz3D Beginners Area/2d mouse pointer on a 3d map
| ||
does anyone have any idea how i would get a sprite to line up with my mouse? I've programed in 2d and that seemed pretty easy (just tell b3d to draw the image and mouseX() and mouseY()) However now that I'm working with 3d if i tell b3d to draw the sprite at the mouseX() and mousey() i have to hold the mouse at the top left of the screen to get it at the center of the map What I'm really looking to do is move the mouse to the left edge of the screen and have the camera move left, or move the mouse to the top end of the screen and have the cam move up if anyone can explain to me what i need to do, that would be much appreciated, or any examples would be wonderful -Droolbucket |
| ||
I use this code to move my camera: if uses some global variables...gwidth/height is the size of screen mapwidth/height is the size of playing field. you will probably have to change some of the other constants to make it work for you Function update_camera() If MouseX() > (gwidth - 10) Then TranslateEntity camera,1,0,0 If MouseX() < 10 Then TranslateEntity camera,-1,0,0 If MouseY() > (gheight - 10) Then TranslateEntity camera,0,0,-1 If MouseY() < 10 Then TranslateEntity camera,0,0,1 ;this part just makes sure the camera stays within some bounderies... If EntityX#(camera,True) < 0 Then PositionEntity camera,0,EntityY#(camera,True),EntityZ#(camera,True),True If EntityX#(camera,True) > mapWidth Then PositionEntity camera,mapWidth,EntityY#(camera,True),EntityZ#(camera,True),True If EntityZ#(camera,True) < -15 Then PositionEntity camera,EntityX#(camera,True),EntityY#(camera,True),-15,True If EntityZ#(camera,True) > mapHeight-15 Then PositionEntity camera,EntityX#(camera,True),EntityY#(camera,True),mapHeight,True End Function for the actual cursor, make sure that you draw after renderworld and before the flip: ;do all 3d stuff updateworld() renderworld() drawimage(cursor,mousex(),mousey()) ;do other 2d stuff flip |
| ||
so is it true that i can use 2d commands as long as they are after "updateworld and renderworld"? for the cursor i used rect (which is a 2d command) are all the 2d commands included in 3d graphics? or just a few? oh and thanks, as simple as this is it helped a lot |
| ||
all of the 2d commands work in 3d, but only after the renderworld and before flip. I have heard that the 2d commands used in 3d are slower though...(not by much) |
| ||
There was some code posted a while ago that converted mouse coordinates into 3d coords, however I can't find it. I normally use a plane: rotate it and make it pickable (EntityPickMode 2). Then use camerapick camera, mousex(), mousey() and read back pickedx(), pickedy() and pickedz() |