Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / camera coding problem ?

Author
Message
Justice
20
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 12th Apr 2006 12:26
Hi,

I have just written a small program which allows me to walk around a 3d world created using 3dWorld Studio & NGC V4.01.
I place my collision sphere(object number 2) on the ground and move it around using my mouse.

Here is the code (This works great)

mouse_control:

rotate object 2,object angle x(2)+(mousemovey()/mousesence),object angle y(2)+(mousemovex()/mousesence),0
rotate object 2,object angle x(2)+(mousemovex()/mousesence),object angle y(2)+(mousemovex()/mousesence),0
if object angle x(2)>90 then xrotate object 2,90
if object angle x(2)<-90 then xrotate object 2,-90

cx=object angle x(2)
cy=object angle y(2)
cz=object angle z(2)

rotate camera cx,cy,cz
rotate object 2,cx,cy,cz

if mouseclick()=1
xrotate object 2,0
move object 2,5
xrotate object 2,cx
endif

if mouseclick()=2
xrotate object 2,0
move object 2,-5
xrotate object 2,cx
endif

nx=object position x(2)
ny=object position y(2)
nz=object position z(2)

position object 2,nx,ny,nz
position camera 0,nx,ny+50,nz

return

What i would like to do (and i'm having great problems with) is :

I want to have an object (ie a gun) above the ground above my sphere, so it looks like i'm carrying it (like in the doom games)
and then i want the gun to move with my mouse movement (so i can rotate & move back and forth like i can with my collision sphere)

Can anyone help me ?
Its driving me crazy at the moment !
Justice
20
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 12th Apr 2006 12:32
Sorry i posted this on the wrong forum board as i'm using darkbasicpro
Dark Eternity
20
Years of Service
User Offline
Joined: 10th Jul 2004
Location: Vana Diel
Posted: 12th Apr 2006 13:16
no problem it happens to everybody once

I am DarkEternity (DE for short) OWNER OF ANIRE!!!
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 12th Apr 2006 14:13 Edited at: 12th Apr 2006 14:17
the following lines will make it follow the camera at a fixed position (no walk wobble or anything like that)

position object objnum,camera position x(),camera position y(),camera position z()
set object to camera orientation objnum

will get the gun object (objnum) faceing the same way and angle as the camera and position it wherever the camera is, the trouble is its right in the middle of the screen and not far enough forwards to see properly(inside the camera cull range), so do..

pitch object down objnum,45
move object objnum,3

the first will point the gun downwards 45 degrees and the second will move it forwards and down a distance of 3, the exact distance and angle is up to where you want the gun to appear exactly, at the moment it will now be visible in front of you and turn with the camera etc, but its pointing downwards 45deg (or whatever), so do

pitch object up objnum,45
sync

this will ensure the gun is level again, then just do that sequence of commands every loop, it might look slow but actualy positioning objects is very fast, the system can do the math internaly at least as fast as you could do it in code, heres an example where a cube takes the place of the gun, note that the angles and distance where modified for this code, once you have the position you can add a bit of code to make it wave about when you walk, but this is ok for a start.



also notice that I disabled the objects zdepth in this code, try remming the line out and see what happens to the gun when you approach spheres, I don`t mention lock object on (glues an object to a fixed position on the screen, almost the same as this code does), because it`s no use if you want to add walk motion or aiming dither, two things that make a FPS look better, this gives a fixed position but you can add in motion to its position to make it wave around the average or move from side to side etc.



Dr Frankenstiens mum told him to make some new friends, not knowing where this was going to lead.
Dark Eternity
20
Years of Service
User Offline
Joined: 10th Jul 2004
Location: Vana Diel
Posted: 12th Apr 2006 14:28
games are good and it is cool to see people finding better ways for realism

I am DarkEternity (DE for short) OWNER OF ANIRE!!!

Login to post a reply

Server time is: 2025-05-23 19:04:31
Your offset time is: 2025-05-23 19:04:31