'Billboard' effect with a Quad
Blitz3D Forums/Blitz3D Programming/'Billboard' effect with a Quad
| ||
Graphics3D 640,480,32,0 SetBuffer BackBuffer() Type character Field sprite Field rot# End Type pivot=CreatePivot() camera=CreateCamera(pivot) PositionEntity camera,0,3,-5 : RotateEntity camera,30,0,0 ground=CreatePoly(-5,5,10,10) : RotateEntity ground,90,0,0 : EntityAlpha ground,0.5 : EntityOrder ground,1 ; Create 5 characters For i=-4 To 4 Step 2 c.character=New character c\sprite=CreatePoly(-0.5,0.5,1,1) : PositionEntity c\sprite,i,0,0 EntityFX c\sprite,1 c\rot#=0 Next sprite=CreateSprite() : PositionEntity sprite,0,0,4 ;------------------- ;Main Game Loop -------------- ;------------------- While Not KeyDown(1) For a.character=Each character PointEntity a\sprite,camera Next ;Keyboard Control If KeyDown( 208 )=True Then pitch#=pitch#-1 If KeyDown( 200 )=True Then pitch#=pitch#+1 If KeyDown( 203 )=True Then yaw#=yaw#-2 If KeyDown( 205 )=True Then yaw#=yaw#+2 RotateEntity pivot,pitch#,yaw#,0 RenderWorld Flip Wend End ;Functions ;------------ Function CreatePoly(xpos#,zpos#,x#,z#) ;Create a backless Square (sprite) sprite=CreateMesh() he=CreateBrush(255,255,255) v=CreateSurface(sprite,he) FreeBrush he AddVertex (v,xpos#,zpos#,0, 1,0) AddVertex (v,xpos#+x#,zpos#,0, 0,0) AddVertex (v,xpos#+x#,zpos#-z#,0,0,1) AddVertex (v,xpos#,zpos#-z#,0, 1,1) AddTriangle(v,2,1,0) AddTriangle(v,0,3,2) AddTriangle(v,0,1,2) AddTriangle(v,2,3,0) Return sprite End Function I'm trying to achieve the same 'billboarding' effect that Blitz3D automatically gives Sprites, but in a Quad. The example code shows five of these Quads pointing at the Camera with PointEntity, and a Sprite behind them. Moving the camera with the cursor keys, it's clear that the Quads aren't acting in the same way as the Sprite. Does anyone have ideas as to how the correct 'roll' value for each Quad can be calculated? Thanks. |
| ||
I guess you need first to check how many degrees the quad is away from the camera view center, and then add (or subtract?) this from the cameras yaw plus 90°. Or something. In the Code Archives there is an example for In-FOV-of-entity, might be useful. |