bbcameraproject problem\mystery
Archives Forums/Blitz3D SDK Programming/bbcameraproject problem\mystery
| ||
Supposing I have a 3d table with some balls on it and for some reason I wanted to draw a cross over each one in 2D. Unless I'm going a bit mad this should work: For Local that:ball=EachIn ball_list[active_player] bbCameraProject table_camera,bbEntityX (that.ball_mesh),bbEntityY (that.ball_mesh),bbEntityZ (that.ball_mesh) Local sx=bbProjectedX() Local sy=bbProjectedY()+letterbox_bar bbLine sx-100,sy,sx+100,sy bbLine sx,sy-100,sx,sy+100 Next Except it doesn't. The X coord is fine but the y coord is way off (up the screen) After tons of fiddling I had to add approx 1/3 of the viewport height to the y coord. No idea what's going on but it works in various resolutions. Local sy=bbProjectedY()+letterbox_bar+(viewport_h/3.33) Any idea what's going on? letterbox_bar = viewport distance from top of screen. viewport_h = height of viewport |
| ||
would changing the global space flag on the entityx y & z commands make any difference? |
| ||
My experience says: When a coordinate of a 3D point cannot be projected on the screen becuase that point is outside of the viewport then ProjectedX() and ProjectedY() functions cannot return a valid screen coordinated. Thus you need to check first if your ball is visible by your camera using first bbEntityInView function. If is not visible then you shouldn't draw the cross: For Local that:ball=EachIn ball_list[active_player] local sx, sy if (bbEntityInView(that.ball_mesh, table_camera) bbCameraProject table_camera,bbEntityX (that.ball_mesh),bbEntityY (that.ball_mesh),bbEntityZ (that.ball_mesh) sx=bbProjectedX() sy=bbProjectedY()+letterbox_bar bbLine sx-100,sy,sx+100,sy bbLine sx,sy-100,sx,sy+100 end if Next |
| ||
I would check 2d drawing origin by drawing a test frame with lines around the viewport, but you may already have done that. |
| ||
@Moraldi, all the balls are visibile at all times. @skid, I'll double check that, ta. EDIT: Yep the 2D origin is fine. Projectedy() just seems to be out by viewport_height/3.333. Drawing a 2D cross was just a test, I needed the coords for something else and they were just coming out wrong so I wrote the above code. It's definitely the numbers that are out. |
| ||
@Leon I tried the global space flag and it made no difference. Thanks for that though I didn't know about that flag!. I've been detatching and reattaching objects from their parents to do that. In this case, balls are all parented to an object (a pivot) at 0,0,0 anyway. |
| ||
how odd, i dont seem to have that trouble. im using the same commands for doing a cheap wireframe overlay. but im doing it in a canvas, i had an offcentered issue in the beginning but it had to do with me not resetting the 2d viewport and the camera viewport. |