Camera Help

Previous topic - Next topic

kamakazieturtle

Ok, so I have been trying to learn how to make a 3rd person camera for like the last 2 weeks :S, and so far no success from the search. So if someone has code for one they wouldn't mind sharing. Or if someone feels like taking the time to explain how rotating a point around another works, I could really use the help.


kamakazieturtle

I've read over it before, but I'm not really all that great at 3d. I've been programming for years, but have only been doing 2d and would be intermediate if at that. I can draw objects and have object rotation down, but now i want to rotate the camera around the character, so i can use the code later for 3rd person once I finish my person. I'll go over this again and try so suck it all in but if u have and helpful key points to cameras it'll help :), Thanks.

Moru

Ok, then try this one: http://www.glbasic.com/forum/index.php?topic=2021.0

Makes it a lot easier to use 3D on GLBasic.

kamakazieturtle

This still didn't really help, but I kept googling math and stuff and came up with something. I help this might help anyone with my same problem. Its just basic camera code. Thanks for all your help Moru.

Code (glbasic) Select

X_LOADOBJ "object.ddd", 2 //Insert the name for your object you want to view.

cx = 0
cy = 0
cz = 50
czoom = 50
mx = 0
my = 0

WHILE TRUE
X_MAKE3D 1,2000,45
X_CULLMODE 0
IF MOUSEAXIS(2) = 1
czoom = czoom - 3
ELSEIF MOUSEAXIS(2) = -1
czoom = czoom + 3
ENDIF
mx = mx - MOUSEAXIS(0)
my = my - MOUSEAXIS(1)
IF mx < 0 THEN mx = 360
IF mx > 360 THEN mx = 0
IF my < 0 THEN my = 360
IF my > 360 THEN my = 0
IF my > 270 THEN my = 270
IF my < 90 THEN my = 90
cx = czoom * SIN(mx)
cy = czoom * SIN(my)
cz = czoom * COS(mx)
X_CAMERA cx,cy,cz,0,0,0
X_DRAWOBJ 2, 0
SHOWSCREEN
WEND

kamakazieturtle

I didn't feel like making a new topic for this, but does anyone know how to rotate my object along with the camera?

Schranz0r

you need X_POPMATRIX and X_PUSHMATRIX
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

If you want to rotate your object with the camera, you must X_MOVEMENT, X_ROTATION it accordingly. Usually you do it the other way round: Move your player, and have the camera movve with the object. That's a lot easier.