Code archives/3D Graphics - Misc/Free third-person camera .
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This code can rotate around a mesh , and the mouse wheel over and out. | |||||
; Code Free Camera. ; ==================== Graphics3D ( 800, 600, 32, 2) SetBuffer ( BackBuffer()) ; Variables Free Camera. Local distCamera = 200 Local mouseVel# = 0.5 Local suaveCamara# = 4.5 Local mxs# Local mys# Local camxa# Local camya# ; Escene. Local Luz% = CreateLight() Local Camera% = CreateCamera() ; Camera. Local Cubo% = CreateCube() ; Player. ScaleMesh Cubo%, 25, 25, 25 HidePointer() ; Bucle. While Not KeyHit(1) ; camera look If MouseDown(2) Then distCamera% = distCamera% + (MouseYSpeed() * mouseVel#) If distCamera% < 200 Then distCamera% = 200 If distCamera% > 500 Then distCamera% = 500 MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2 Else mxs# = CurveValue(MouseXSpeed() * mouseVel#, mxs, suaveCamara#) mys# = CurveValue(MouseYSpeed() * mouseVel#, mys, suaveCamara#) camxa# = camxa - mxs Mod 360 camya# = camya + mys If camya < -45 Then camya = -45 If camya > 45 Then camya = 45 distCamera% = distCamera% + (MouseZSpeed() * 3) MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2 RotateEntity Camera%, camya, camxa, 0.0 If distCamera% < 200 Then distCamera% = 200 If distCamera% > 500 Then distCamera% = 500 EndIf PositionEntity Camera%, EntityX(Cubo%), EntityY(Cubo%), EntityZ(Cubo%) MoveEntity Camera%, 0, 0, -distCamera% RenderWorld Flip Wend End ; Camara libre. ; =============== Function CurveValue#(newvalue#, oldvalue#, increments) If increments > 1 Then oldvalue# = oldvalue# - (oldvalue# - newvalue#) / increments If increments <= 1 Then oldvalue# = newvalue# Return oldvalue# End Function |
Comments
| ||
Hi Yue, always nice to see a contribution. Looks interesting. However it doesn't run straight from the box as some code is missing. I did not go through entire code for I am in bed with a headache (have the flue), so I am bit lazy at the moment. Would help if you made it procedural with cube or sphere for player etc, so could see how good it works. |
| ||
Here is a sample video of how it works. :) Edit: Update Code first post. |
| ||
Nice. Moves like as in a 3d modeling program. Also good for in a world editor if adding a key to drop the model onto the terrain and keys to flip through different models. Thanks for sharing. |
| ||
That fixed it. Not asking for a type now. Thanks |
| ||
Nice example, but not sure why you use a scale so big (*10 ?) Your example with a normal scale and some markers on the ground to see what is going on : Also you should consider to add a eye pivot near the point of view of your character/vehicle, set as a child of the feet/root, so that when you zoom in, the view goes near the eyes, not near the feet/root... |
Code Archives Forum