Weird problem with Camera parenting
Blitz3D Forums/Blitz3D Beginners Area/Weird problem with Camera parenting
| ||
Dear all, Mucking about as usual and have come across a scenario I don't understand. Just creating simple stuff and parenting my camera to my player. However, the following code didn't seem to work... Graphics3D 800,600,32,2 SetBuffer BackBuffer() light=CreateLight() ;***************** cam=CreateCamera(player) PositionEntity cam,0,5,-10 ;********************* cube=CreateCube() PositionEntity cube,-2,0,10 ;ground ground=CreateCube() ScaleEntity ground,1000,1,1000 EntityColor ground,0,255,0 PositionEntity ground,0,-1,0 ;player player=CreateSphere() ScaleEntity player,1,3,1 PositionEntity player,0,3,0 ;paste to here ;main loop While Not KeyDown(1) If KeyDown(200) MoveEntity player,0,0,1 If KeyDown(208) MoveEntity player,0,0,-1 RenderWorld Flip Wend End However, in the above code, the camera doesn't follow the player. So, I thought I'd try placing the camera creation after the point where I set up the player... Graphics3D 800,600,32,2 SetBuffer BackBuffer() light=CreateLight() cube=CreateCube() PositionEntity cube,-2,0,10 ;ground ground=CreateCube() ScaleEntity ground,1000,1,1000 EntityColor ground,0,255,0 PositionEntity ground,0,-1,0 ;player player=CreateSphere() ScaleEntity player,1,3,1 PositionEntity player,0,3,0 ;paste to here ;***************** cam=CreateCamera(player) PositionEntity cam,0,5,-10 ;********************* ;main loop While Not KeyDown(1) If KeyDown(200) MoveEntity player,0,0,1 If KeyDown(208) MoveEntity player,0,0,-1 RenderWorld Flip Wend End ...which made the camera follow the player, but the player's scaling goes out the window! I'm sure I'm making a total noob mistake, but I can't find anything in the forums to assist me. Would anyone like to point their finger and laugh at me? Toby. |
| ||
I recently came across this myself with MiniB3D, what you need to know is, the cameras scale during a render is affected by its parent scale. Therefore if you parent it to a sphere, and scale the sphere, your rendered scene will also become scaled. I came up with a much cleaner solution for you: Graphics3D 800,600,32,2 SetBuffer BackBuffer() light=CreateLight() cube=CreateCube() PositionEntity cube,-2,0,10 ;ground ground=CreateCube() ScaleEntity ground,1000,1,1000 EntityColor ground,0,255,0 PositionEntity ground,0,-1,0 ;player player_pivot=CreatePivot() player_mesh = CreateSphere(8, player_pivot) ScaleEntity player_mesh,1,3,1 PositionEntity player_mesh, 0, 3, 0 ;paste to here ;***************** player_cam=CreateCamera(player_pivot) PositionEntity player_cam,0,5,-10 PointEntity player_cam, player_mesh ;********************* ;main loop While Not KeyDown(1) If KeyDown(200) MoveEntity player_pivot,0,0,1 If KeyDown(208) MoveEntity player_pivot,0,0,-1 RenderWorld Flip Wend End Instead create a Pivot (Just a entity with no mesh) and use it to control the movement of your player, add a sphere and make it a child of the pivot, and add a camera also. I also added a line PointEntity to point your camera at the sphere. |
| ||
So, in layman's terms... If a camera is parented to something, it will morph the screen to whatever scaling its parent had. However, if the parent has no scaling (even though the parent itself may have a scaled parent) it will not affect the view. Is that correct? |
| ||
Not exactly, any child of a scaled parent ( using scaleentity ) will adopt it's parents scaling. If you use scalemesh it all works just fine and saves all the bodging ...Graphics3D 800,600,32,2 SetBuffer BackBuffer() light=CreateLight() cube=CreateCube() PositionEntity cube,-2,0,10 ;ground ground=CreateCube() ScaleEntity ground,1000,1,1000 EntityColor ground,0,255,0 PositionEntity ground,0,-1,0 ;player player=CreateSphere() ScaleMesh player,1,3,1 PositionEntity player,0,3,0 ;paste to here ;***************** cam=CreateCamera(player) PositionEntity cam,0,5,-10 ;********************* ;main loop While Not KeyDown(1) If KeyDown(200) MoveEntity player,0,0,1 If KeyDown(208) MoveEntity player,0,0,-1 RenderWorld Flip Wend End |
| ||
Thanks, Stevie. So ScaleMesh, as opposed to ScaleEntity, is singular to the named entity. If the named entity acts as a parent to any other child, its scaling isn't adopted? That's what the last bit of code (above) suggests ...to me anyhow! (the help file on ScaleMesh is somewhat sparse). Toby |
| ||
ScaleMesh actually deforms the mesh data. It changes the position of the vertices. Any copy that was made using CopyEntity will change along. ScaleEntity only deforms the entity that wraps the mesh. So no (vertex) information is changed, just the transformation matrix that is used for rendering the entity. Changing the matrix does effect any children, changing the mesh does not. The same goes for RotateMesh vs RotateEntity and PositionMesh vs PositionEntity. |
| ||
Blimey! There's a million little nuances with this package, aint there? Thanks, folks. T |