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.

Newcomers DBPro Corner / Anyone have simple code for 3D grid movement

Author
Message
rik72
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location:
Posted: 25th Jul 2004 22:23
Hi I have a 3D grid 50X50 with an object the same size as 1 grid square and want to the move the object everytime the arrow keys are pressed from one grid square to another. Has anyone some simple code for this.

Rik
rik72
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location:
Posted: 25th Jul 2004 23:24
Sorry forgot to mention using DBP.
Rik
rik72
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location:
Posted: 26th Jul 2004 00:04
And this is the code

set display mode 1024, 768, 32

restore level1
cubesize = 50

for j = 1 to 15
for i = 1 to 15

read a

if a = 1
inc objectcounter
make object cube objectcounter, cubesize
position object objectcounter, j * cubesize, 0, i * cubesize
COLOR OBJECT objectcounter,objectcounter*100

endif
next i
next j
objectcounter=objectcounter+1
make object cube objectcounter,cubesize
position object objectcounter,50,50,50
position camera 250,200,-350




do
control camera using arrowkeys 0, 1, 1
if mouseclick() then move object objectcounter,1


loop

level1:
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
bibz1st
21
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 26th Jul 2004 00:23 Edited at: 26th Jul 2004 00:26
IF UPKEY()=1 AND PRESSEDUP=0
POSITION OBJECT 1,X,Y,Z+50
PRESSEDUP=1
ENDIF

IF UPKEY()=0 THEN PRESSEDUP=0

you could do the same for each arrow key,PRESSEDDOWN, PRESSEDRIGHT etc
thats one way
Rocket Puppy
20
Years of Service
User Offline
Joined: 25th Jul 2004
Location:
Posted: 26th Jul 2004 00:46 Edited at: 26th Jul 2004 00:47
I don't use dark basic professional but this should work with it, I added some remarks so that it will be eaisier to change to what you are using.

P.S. use the source button at the bottom of my post to get my code
Rocket Puppy
20
Years of Service
User Offline
Joined: 25th Jul 2004
Location:
Posted: 26th Jul 2004 00:49
if you are looking for only camera source code without the world creator however, this should work fine.

P.S. same as above the source is attached
rik72
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location:
Posted: 26th Jul 2004 01:15
Thanks bibz1st got the idea and played around with a loop FOR/NEXT and got the effect I was after, however needed to put in the wait command to slow things down. Is there another way of slowing down the loop to make it run the same speed on different computers without using the wait command.

Rik


set display mode 1024, 768, 32

restore level1
cubesize = 50

for j = 1 to 15
for i = 1 to 15

read a

if a = 1
inc objectcounter
make object cube objectcounter, cubesize
position object objectcounter, j * cubesize, 0, i * cubesize
COLOR OBJECT objectcounter,objectcounter*100

endif
next i
next j
objectcounter=objectcounter+1
make object cube objectcounter,cubesize

position camera 250,200,-350

x=50:y=50:z=50
position object objectcounter,x,y,z





do


IF UPKEY()=1 and keypressed=0
keypressed=1
for stp=1 to cubesize
inc z
POSITION OBJECT objectcounter,X,Y,Z
wait 10
next stp
keypressed=0
ENDIF


loop

level1:
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
bibz1st
21
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 28th Jul 2004 01:19
Got this off another thread...
Quote: "Forced Timing For Better Performance
Orgull

Hey there!
Forgive me if this gets a bit long, but speed optimization seems to be the big issue with DarkBasic, so I feel this is a very important subject. I have examined source code for about two dozen games written in DB and I have NOT ONCE seen anyone use this technique. I'd like to share it with you all. If you know and use this already, I apologize if I come across sounding preachy, I get zealous when a topic matters to me. F.Y.I., I developed this method back in the late 80's, when the vast differences in speed between machines meant that you had to time your code carefully, or else it wouldn't run on every system. The method is called "Forced Timing".

Q) What is forced timing and how do I use it in DarkBasic?

In a sentence, forced timing is a method of calling functions and subroutines from the main loop at a fixed rate. This is done using a simple set of variables. I'll give an example program that calls three subroutines: Userinput, Cameracontrol, and Playercontrol. Immediately before your main program loop begins, include the follwing lines:

basetime = timer()

inputtime = basetime
playertime = basetime
cameratime = basetime
...

Then, immediately following the start of the main loop, add yet another timer line.

MAIN:
do

basetime = timer()

Simple so far? That's part one, the setup. Now part two comes when you call your subroutines. This won't make sense yet, so please bear with me. Here's how you call your subroutines.

if inputtime < basetime then gosub Userinput
if playertime < basetime then gosub Playercontrol
if cameratime < basetime then gosub Cameracontrol

gosub Updatevisuals
sync

loop

The first time through, each of the subroutines will be called since inputtime, playertime, and cameratime are all less than basetime. Notice that basetime updates itself EVERY loop.
This is part two, the timed call. Now the third part happens at the end of each subroutine.
Remembering that the timer increments 1000 times per second, add this line to the end of every timed subroutine, just above the return statement.

...
inputtime = basetime + 40
return

Now, the Userinput subroutine will only be called when basetime catches up with inputtime. Since we've given this routine a time of 40, it will be called at a rate of 25 times per second. (1000/40) Do the same for all the other timed routines. This is the third and final part of "Forced Timing".

Ask yourself, how often to visuals need to be updated. Answer: as often as possible. But, how often do we need to get user input? Not as often. Even in the fastest game, calling userinput 25 times a second instead of during every loop will free up speed for the visuals.(which really is the whole idea here isn't it?) In one program I just wrote, I use the following times

viewcontrol = basetime + 20 (calls 50 times a second)
cameracontrol = basetime + 40 (calls 25 times a second)
playerinput = basetime + 80 (calls 12.5 times a second)
refreshstatusbar = basetime + 250 (calls 4 times a second)

Using this method I regulary get 60-75 fps on my PII-450 even when displaying complex multiple objects. (which is something DB has a terrible time doing quickly)

I hope this method helps. There is more to it, but I don't want to write a book... not today anyway."

Login to post a reply

Server time is: 2024-11-27 02:26:17
Your offset time is: 2024-11-27 02:26:17