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 Professional Discussion / Question about 2D and 3D space

Author
Message
BitMaster
16
Years of Service
User Offline
Joined: 7th May 2010
Location:
Posted: 7th May 2010 21:31
Hi there all,
I'm new to the forum but not to DarkBasic Pro. I have tried many times to learn it and do well till I get to the 2D and 3D space. I have tried everything I can think of and have had no luck my question is. How do I know where I am putting somethings in 2D or 3D space is there a math you use or a program or a certain method? I know the origin is 0,0 in the top left corner for 2D. And 0,0,0 at top left corner for 3D. Resolution 640x480. When I put in a coordinate I have no idea where my object will end up or wont see them at all. thanks for any help would be greatly appreciated.
wyrleywolves
23
Years of Service
User Offline
Joined: 6th May 2003
Location:
Posted: 7th May 2010 23:49
With 2d the x co-ordinates are 0 to your screen resolution width and the y co-ordinates are 0 to your screen resolution height. With 3d the x co-ordinates(left/right) and z co-ordinates(near/far) are your position and y is your height, but if you don't point the camera at the co-ordinates you want, you will not see your object. Also be sure your object scale is correct.
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 8th May 2010 01:03
3d space position on screen is dependant on where you have placed the camera.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th May 2010 02:38
The link between 2D and 3D in DB is pretty thin.

If you load an image...

load image "image.bmp",1

You can paste it over your screen with...

paste image 1,0,0

Or halfway across and down...

paste image 1,320,240

But with 3D, you have to always consider the camera. I think it's a good idea to make a test bed, rather than just making an object then experiment with it, make a lot of objects so you can get your bearings.

For example, to make a jagged floor...

obj=100
for z=-10 to 10
for x=-10 to 10
make object cube obj,100
position object obj,x*100,0,z*100
rotate object obj,rnd(360),rnd(360),rnd(360)
inc obj,1
next x
next z

That would cover the floor with cubes, rotated randomly.

Then to explore that, it's good to keep it really simple with just some camera moving...

Do

rotate camera mousey(),mousex(),0
move camera (upkey()-downkey())/20.0

Sync
Loop

So that rotates the camera with the mouse, and up and down on the keyboard moves forward and back. I suggest making a little test world, try and get used to all those camera commands and work out rotation and 3D positioning. I found it helped a lot just to experiment with code snippets, the ones for terrain are quite practical, but just take it easy. As you are sitting, consider that if you move your head forward or backward your moving on the Z axis, if you move if sideways you are moving on the X axis. If you raise it up you are moving on the Y axis. The axis in DBPro is like a pivot point for rotation, so rotate 30 degrees on X, like 30,0,0 would be tilting the camera down 30 degrees. Turning left and right is handled with the Y axis, and rotating on the Z axis is like leaning your head left and right. The move camera command simply moves the camera forward or backward on it's current trajectory, more complex movement is best done with trig.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-26 02:36:39
Your offset time is: 2026-07-26 02:36:39