X3D_CAM_INIT, X3D_CAM_SET, X3D_CAM_ROTATION and X3D_CAM_MOVEMENT

Previous topic - Next topic

Schranz0r

Hi,

Dachte mir, ich mach mal Functionen um eine Cam zu steuern.
Da es ja von der Mathematik, einigen nicht ganz leicht fallen wird?!
Könnte man jetzt schön über einen Spieler kleben ;)


hier ein Beispiel:

Code (glbasic) Select
// --------------------------------- //
// Project: Move Cam
// Start: Monday, October 01, 2007
// IDE Version: 5.022



X3D_CAM_INIT(5,90)  // Init all variables

WHILE TRUE

X_MAKE3D 1,1000,45 // Set 3D Modi

X3D_CAM_SET(0,0,-10)   // Set a Cam
X3D_CAM_ROTATION(MOUSEAXIS(0), MOUSEAXIS(1), 2, 2)  // Rotate the Cam
X3D_CAM_MOVEMENT(17,31,30,32)  // Move the Cam

X_DRAWAXES 0,0,0  // Draw a Axes to show how it works

SHOWSCREEN
WEND
END


FUNCTION X3D_CAM_INIT: Move_speed, Degree_UpDown // Degree up to 90 !!!!
GLOBAL PX,PY,PZ,Cam_X,Cam_Y,Cam_Z,phiXZ,phiXZ,Cam
GLOBAL CamSpeed = Move_speed
GLOBAL up_down_limit = Degree_UpDown  //Overall 2*Degree_UpDown
ENDFUNCTION


FUNCTION X3D_CAM_SET: XX, YY, ZZ  // Start Position
IF Cam = FALSE
Cam_X = XX
Cam_Y = YY
Cam_Z = ZZ
phiXZ = 90
Cam = TRUE
ENDIF
X_CAMERA Cam_X, Cam_Y, Cam_Z,   Cam_X+COS(phiXZ), Cam_Y+SIN(-phiXY), Cam_Z+SIN(phiXZ)
ENDFUNCTION

FUNCTION X3D_CAM_ROTATION: LeftRight, UpDown, Factor_UpDown, Factor_LeftRight  

// LeftRight = Use MOUSEAXIS(0)
// UpDown = Use MOUSEAXIS(1)
// Factor = 0 = Fast and higher 0 are slower

INC phiXZ,LeftRight/Factor_LeftRight // Left and Right
INC phiXY,UpDown/Factor_UpDown // Up and Down

IF phiXZ > 359 THEN phiXZ = 0  //Limit Degree
IF phiXZ < 0 THEN phiXZ = 359  //Limit Degree

IF phiXY < -up_down_limit THEN phiXY = -up_down_limit //Limit Degree
IF phiXY > up_down_limit THEN phiXY = up_down_limit   //Limit Degree
ENDFUNCTION

FUNCTION X3D_CAM_MOVEMENT: key_forward, key_back, key_left, key_right
f_up = key_forward
f_down = key_back
f_left = key_left
f_right = key_right

IF KEY(f_up) // forward
INC Cam_Z,SIN(phiXZ)*CamSpeed
INC Cam_X,COS(phiXZ)*CamSpeed
ENDIF
IF KEY(f_down) // back
DEC Cam_Z,SIN(phiXZ)*CamSpeed
DEC Cam_X,COS(phiXZ)*CamSpeed
ENDIF
IF KEY(f_left) // left
INC Cam_Z,SIN(phiXZ-90)*CamSpeed
INC Cam_X,COS(phiXZ-90)*CamSpeed
ENDIF
IF KEY(f_right) // right
INC Cam_Z,SIN(phiXZ+90)*CamSpeed
INC Cam_X,COS(phiXZ+90)*CamSpeed
ENDIF

ENDFUNCTION
Hier nochmal alle Functionen:
Code (glbasic) Select
FUNCTION X3D_CAM_INIT: Move_speed, Degree_UpDown // Degree up to 90 !!!!
GLOBAL PX,PY,PZ,Cam_X,Cam_Y,Cam_Z,phiXZ,phiXZ,Cam
GLOBAL CamSpeed = Move_speed
GLOBAL up_down_limit = Degree_UpDown  //Overall 2*Degree_UpDown
ENDFUNCTION


FUNCTION X3D_CAM_SET: XX, YY, ZZ  // Start Position
IF Cam = FALSE
Cam_X = XX
Cam_Y = YY
Cam_Z = ZZ
phiXZ = 90
Cam = TRUE
ENDIF
X_CAMERA Cam_X, Cam_Y, Cam_Z,   Cam_X+COS(phiXZ), Cam_Y+SIN(-phiXY), Cam_Z+SIN(phiXZ)
ENDFUNCTION

FUNCTION X3D_CAM_ROTATION: LeftRight, UpDown, Factor_UpDown, Factor_LeftRight  

// LeftRight = Use MOUSEAXIS(0)
// UpDown = Use MOUSEAXIS(1)
// Factor = 0 = Fast and higher 0 are slower

INC phiXZ,LeftRight/Factor_LeftRight // Left and Right
INC phiXY,UpDown/Factor_UpDown // Up and Down

IF phiXZ > 359 THEN phiXZ = 0  //Limit Degree
IF phiXZ < 0 THEN phiXZ = 359  //Limit Degree

IF phiXY < -up_down_limit THEN phiXY = -up_down_limit //Limit Degree
IF phiXY > up_down_limit THEN phiXY = up_down_limit   //Limit Degree
ENDFUNCTION

FUNCTION X3D_CAM_MOVEMENT: key_forward, key_back, key_left, key_right
f_up = key_forward
f_down = key_back
f_left = key_left
f_right = key_right

IF KEY(f_up) // forward
INC Cam_Z,SIN(phiXZ)*CamSpeed
INC Cam_X,COS(phiXZ)*CamSpeed
ENDIF
IF KEY(f_down) // back
DEC Cam_Z,SIN(phiXZ)*CamSpeed
DEC Cam_X,COS(phiXZ)*CamSpeed
ENDIF
IF KEY(f_left) // left
INC Cam_Z,SIN(phiXZ-90)*CamSpeed
INC Cam_X,COS(phiXZ-90)*CamSpeed
ENDIF
IF KEY(f_right) // right
INC Cam_Z,SIN(phiXZ+90)*CamSpeed
INC Cam_X,COS(phiXZ+90)*CamSpeed
ENDIF

ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

x-tra

gaaaanz toll, respekt, aber ich verkneif mir das zu nehmen, weil ich lieber selber so eine Steuerung ausknobble, auch wenns das das gleiche Ergebnis hat.

Learning bei doing eben.

Schranz0r

jeden das seine ;)

Zumal ich auch das Falsche Forum genommen habe... :S

Gernot bitte Move to Codeschnipsel!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

Move gibt's bei PunBB nicht :weep: aber super funktion.
Als Tip: Wenn man globale variablen macht, dann möglichst nicht PX oder so nennen, sondern entweder gPX, oder alles in ein TYPE TMyCamera packen.
Nur so ein Tip...

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard