Finding On Screen X, Y
Blitz3D Forums/Blitz3D Programming/Finding On Screen X, Y
| ||
Alright I have a vertex (x,y,z) and need to find the on screen x,y of that vertex and its distance from the camera. I want to draw a black line around the edges of objects... a bit like cell shading. |
| ||
Look at the help document for the cameraproject command The pertinent information being: CameraProject camera,x#,y#,z# ; the coordinates in 3D you want screenx# = ProjectedX#() ; x position on 2D camera view point screeny# = ProjectedY#() ; y position Its also a good idea to check the source mesh in is view of the camera even if your projecting a single vertex so wrap your code with: If (EntityInView(object,camera)=true) then Endif Last edited 2011 |
| ||
On-screen coordinates: CameraProject() (EDIT: dang, too slow) Black-line around the edges of a [possibly animated] object: - Load your character. - Clone him using CopyEntity(), so bones, vertex-weights and keys are cloned as well. - Parent him to the original. - Traverse through every vertex of this cloned character and move each vertex a certain value along its normal, effectively expanding his geometry (a simple ScaleEntity() will not do, you really need to expand vertices through their normals - search the code archives for this). The 'certain value' you expand each vertex is the thickness of the outline. - Paint this cloned character in a fullbright, black brush. - Use FlipMesh() to flip the faces of this cloned character so it outlines your normal-sized character. - When animating the normal character, animate the clone too so it doesn't sit static. - When checking for collisions, ignore the outline mesh. Always use the original. Last edited 2011 |
| ||
hey u guys are awesome. ill try ur suggestions. thanx! |
| ||
btw if your going through a lot of vertices and drawing something to the screen you will have 2 issues: 1) It will be very very slow with all the 2D rendering 2) You will have occlusion issues i.e. where half a model is behind a wall and half of it visible you will still be drawing 2D elements for bits that can't be seen on screen Ideally you want to be using something like Kryzon suggested as this will have the benefit of being 3D hardware accelerated and correctly work with the z-buffer in 3D. |
| ||
The code archive entry I was referring to, that expanded each vertex along their normals: http://blitzbasic.com/codearcs/codearcs.php?code=446 This would require testing, but I believe this expansion should preserve even in meshes with skeletal animation. |