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 / Some examples of the use of vectors, please:)

Author
Message
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 6th Dec 2002 11:51
Ive been reading about maths and physics on various C++ forums and they all use vectors for almost everything. I see that DBPro has vector commands but I wouldnt even know where to start to use them. If some people are kind enough to do a few coded examples I would be most grateful
haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 6th Dec 2002 17:27
Its not really a case of just using vectors, its really about using them in a situation where it would be useful, you could use them in collision, lightmapping, physics simulation, simple motion.

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 6th Dec 2002 17:41
Here is a simple example of vectors, in my crappy version of pong



Heres a little more complex usage of vectors:-



Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 6th Dec 2002 21:50
Would you please try and explain the command in more detail.... not just give the example code?

I couldnt figure it out from there and would realy appreciate some explanation.

haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 6th Dec 2002 21:58
The commands are actually quite simple, its just understanding vector maths that can be difficult, here is a link that has lots of info on vectors :-

http://www.flipcode.com/geometry/

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 6th Dec 2002 22:06
Thats excellent Haggisman, thanks alot
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 7th Dec 2002 07:31
Can someone please tell me what Im doing wrong here. Probably most of it if not all

haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Dec 2002 11:33
The only problems i could find was a few - signs were in the wrong place, it should work now but when the velocity of the ball increase so much it will eventually be able to jump through the walls and escape



Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 7th Dec 2002 22:20
So how would I replace these two functions with a vector based function? I think basing my code on vectors would drasticly improve efficiency



Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 7th Dec 2002 22:24
Sorry, there is a plus sign missing in this line

distance3d = sqrt((x1 - x2)^2 + (y1 - y2)^2 (z1 - z2)^2)

it should be

distance3d = sqrt((x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2)

Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 7th Dec 2002 23:30
Thanks again Haggisman

With the latest code snippet how can I add in trials that can be adjusted so that they have a limited life time??
haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 8th Dec 2002 13:11
firstly heres some trail code:-



Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 8th Dec 2002 15:33
secondly:-
Hilmi2k i tried to convert your code to use vectors completely, i got to this point on the 1st function.



I thought it would work, but it only ever returned a 0 for the distance, after some messing about with the code i eventually discovered a bug in vectors. This code explains it:-



I have already sent an email too Lee hopefully it will be fixed soon.

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 8th Dec 2002 21:10
You are awesome
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 9th Dec 2002 08:14
Is there any such thing as a curved vector or do u have to join vectors together at different angles. I saw the HERMITE VECTOR3 command is that what Im asking?? and what does normalize mean in vector terms??

Why isnt there examples for each command, why I tells ya
haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 9th Dec 2002 19:42
Im not sure how you would do curves, but all that normalize means is the vectors resultant length is set to 1.

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Dmitry K
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 9th Dec 2002 20:46
2haggisman
It is not bug. You incorrectly declared vectors.
`This code shows how the vectors have a VERY bad bug
`You cant access data out of a vector correctly unless it was the last vector to have data
`entered.
`it even happens when a different type of vector set afterwards

rem Standard Setup Code
sync on : sync rate 0
color backdrop rgb(0,0,128) : hide mouse
set text font "arial" : set text size 12 : set text transparent

rem setup vectors!!!!
vectora=1
vectorb=2
vectorc=3
vectord=4

rf=make vector3 (vectora)
rf=make vector3 (vectorb)
rf=make vector2 (vectorc)
rf=make vector2 (vectord)

set vector3 vectora, 5.0, 6.0, 7.0
set vector3 vectorb, 30.0, 32.0, 23.0
set vector2 vectorc, 50.0, 60.0
set vector2 vectord, 80.0, 85.0

do
text 0, 0, "vectora X: " + str$(x vector3(vectora)) + " vectora Y: " + str$(y vector3(vectora)) + " vectora Z: " + str$(z vector3(vectora))
text 0, 20, "vectorb X: " + str$(x vector3(vectorb)) + " vectorb Y: " + str$(y vector3(vectorb)) + " vectorb Z: " + str$(z vector3(vectorb))
text 0, 40, "vectorc X: " + str$(x vector2(vectorc)) + " vectorc Y: " + str$(y vector2(vectorc))
text 0, 60, "vectord X: " + str$(x vector2(vectord)) + " vectord Y: " + str$(y vector2(vectord))
rem they all use vector D's X and Y value, whilst both vector3's uses vector B's Z value
sync
loop

haggisman
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 9th Dec 2002 21:41
thanks DMiTR0S , you'd think they would put that kinda thing in the manual

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 9th Dec 2002 22:23
Thanx, I finnaly understand how vectors work in darkbasic, but what i still dont understand is where the angle of the vector goes. I can see here point of origin and magnitude.

I just wonder if there is a way to make the syntax more like...


vector_name(magnitude,angleX,angleY,AngleZ,x,y,z)

Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 9th Dec 2002 22:25
ohh yeah, one more thing...

why do you have rf= make vector...
what is the rf for?

Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 13th Dec 2002 23:25
I think rf stands for "response factor" as in the help commands

Could someone help me find the angle of 2 vectors. Im having a little trouble and I'm not sure if I'm on the right track

Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 13th Dec 2002 23:30
hehe, response factor, I mean return float

oops
Cpt Caveman
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: New Zealand
Posted: 15th Dec 2002 20:20
Dont worry, my friend figured it out. He used dotproduct and acos with the standard equation converted to dbpro format and it works pefectly.

Login to post a reply

Server time is: 2024-03-29 10:44:29
Your offset time is: 2024-03-29 10:44:29