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 / Vectors in DBC

Author
Message
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 18th Mar 2005 06:31 Edited at: 19th Mar 2005 22:53
Hi there, I realised the other day that I use vectors in nearly all my projects yet as far as i knew DBC didnt have a vector system.
So i have spent last last few hours writing one for you !
Its not a dll so everyone can use it without the Enhancment pack and it currently has the following features.

SetVector2(Num,x#,y#) - Sets vector 'Num' to the x and y values given

SetVector3(Num,x#,y#,z#) - Sets vector 'Num' to the x, y and z values given

You can also set the (x,y) / (x,y,z) values induvidualy

AddVector2(Result,VecA,VecB) - Vector 'result' stores the values of vectors 'VecA' and 'VecB' added together

AddVector3(Result,VecA,VecB) - Vector 'result' stores the values of vectors 'VecA' and 'VecB' added together

There is also a subtract for both 2D and 3D vectors

ScaleVector2(Result,Source,Value) - Vector 'result' stores the values of vector 'Source' Multiplied by 'Value'

ScaleVector3(Result,Source,Value) - Vector 'result' stores the values of vector 'Source' Multiplied by 'Value'

There is also a divide command using the same syntax

LengthVector2(VecNum) - Returns the length of vector 'VecNum'

LengthVector3(VecNum) - Returns the length of vector 'VecNum'

NormalizeVector2(Result,VecNum) - Normlizes the Vector 'VecNum' and stores the result in vector 'Result'

NormalizeVector3(Result,VecNum) - Normlizes the Vector 'VecNum' and stores the result in vector 'Result'

You can also retrive values from the vectors and perform the dot product on 2vectors


This I thought was a good start and while I will expand it, I think I will release it all Open source later tonight along with a couple of demos.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 18th Mar 2005 07:11
Ok folks, Here is the First simple demo, the next one will show easy inertia aswell.
The should be easy enough to follow, but if there are any questions just ask.
I really hope this will system will be useful to someone, im suprised by how i used to get by without using vectors now that i do use them.

Please post your thought, comments and suggestions.

Attachments

Login to view attachments
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 18th Mar 2005 07:45
A much nicer demo showing how sliding inertia is achieved in 4 lines of aditional code.
Enjoy !

Attachments

Login to view attachments
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Mar 2005 09:48
Firstly, getting errors because it reckons theres some parameter mismatches. Fix this by adding a .0 to the end of numbers in the function calls that don't already contain the decimal point. Secondly, DBC doesn't like dimension arrays initialized in functions, it makes them only local to the function they are created in. Apart from that, the system looks very interesting.


"Lets migrate like bricks" - Me
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 18th Mar 2005 09:57 Edited at: 18th Mar 2005 09:58
Thanks man, ill get that sorted right away!
<edit> just wondering will setting the arrays made in the function to global sort out this problem, just as its much nice to use functions if possible, else ill use a array
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 18th Mar 2005 10:02
For some reason on both I'm getting a "No such array dimension initialized" error.

Crazy Donut Productions
Current Project: A Redneck game
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Mar 2005 10:05
Quote: "<edit> just wondering will setting the arrays made in the function to global sort out this problem, just as its much nice to use functions if possible, else ill use a array"

Unfortunatly DBC doesn't support globals. The only way to make a dimension array 'global' is to initialise it outside of a function.


"Lets migrate like bricks" - Me
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 18th Mar 2005 10:19
Ok sorted the initalize funtion problem, not sure which calls needed the '.0' after them so if you could post them up i can sort that too.
Here is the new file though
[img]
`This replaces the 'setupvectorsystem()' command

`you use this to setup X 2d vectors for your project
Dim Vector2#(X,2)

`And this sets up X 3D vectors
Dim Vector3#(X,3)
[/img]
Hope it works now !

Attachments

Login to view attachments
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Mar 2005 22:49 Edited at: 18th Mar 2005 22:50
Here is that code fixed for DBC:




"Lets migrate like bricks" - Me
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 19th Mar 2005 06:54
Having only used DBC I'm not quite sure what vectors are all about, I see you've used them for sliding inertia, are they used mostly for calculating physics?

Crazy Donut Productions
Current Project: A Redneck game
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 19th Mar 2005 12:47 Edited at: 23rd Mar 2005 12:54
Vectors have MASSIVE uses.

Now that these commands are available in DBC, Philip's Vector Tutorial would be helpfull for some to understand what they're for

http://www.kentaree-studios.com/tutorials/vectors/

Have a read - It's really worth it

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 19th Mar 2005 20:07 Edited at: 19th Mar 2005 22:51
Thanks Benjamin ! ill use that as a grounding for further updates.

@Bear Crazy: Jess is absolutly right, and Philips tutorial is very good, however if you have any questions, just ask them here... also searching the DBpro board for vector answers to vector questions is a good idea, as the DBpro'ers have been using them for so long that they have covered alot of basic problems.

@All: im looking into a few more functions such as cross product but that will be quite difficult (some of this im learning as i go) also im planning on putting spaces back in the function names so that tutorial code can just be copied and pasted and work !...This is as i just relised that although DBP has the functions as reserved words DBC has not.


<EDIT> Good old Philip ! he has covered cross product, so ill have it done quite soon !

<EDIT> Cross product is done !

<EDIT> I have just added 4 new commands that i have used alot over time.

ReflectVector3(vector,normal)
This is used to reflect a vector off an object, given that you know the normal of the face of the object.
I used this to help make a phsyics engine a while ago, the tech demo saw 200 balls moving in a room, if they collided with another ball or a wall then sparkys collision dll would give me the normal of the surface hit, and using that i could reflect the balls motion so it bounced off the wall.


GetAngleVector3(VecA,VecB)
This retrieves the angle between vector 'VecA' and vector 'VecB'

Vector3ToCamera(vec)
This sets a vector to point in the direction of the camera

Vector3ToObject(vec,obj)
This sets a vector to point in the same direct as an object, i used this to set the direction of bullets as they left a gun.
I store the bullets speed in a vector, so when the bullet is made i set its vector to the direction of the player's gun, and then scale the vector to set the speed of the bullet.


<EDIT>
The 'SquaredLengthVector' commands have been added for anyone who needs them.

The updated vector functions are in the attachment.

Attachments

Login to view attachments
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 23rd Mar 2005 06:32
This is great stuff, I'm reading through chapter 3 of Phillip's tutorial right now (somebody should give him five bucks). You have my undying gratitude, Jess and Baggers.

Crazy Donut Productions
Current Project: A Redneck game
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 23rd Mar 2005 17:34
Nice, this could be quite useful

Desktop: AMD Athlon XP2800+,Radeon 9800 128MB, 1GB DDR RAM
Laptop: AMD Athlon 64M 3000+,Mobility Radeon 9700 128MB, 512MB DDR RAM
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Mar 2005 18:37
Good job, now do one for quaternions!

"eureka" - Archimedes
Los
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Location:
Posted: 23rd Mar 2005 22:09
really good, glad you've got the brain to go about making these... yecters.. ?

kid

**Officialy has a mental illness.
" Ahh to finish something! My boy, have you ever accomplished anything? "
Dmitry K
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 24th Mar 2005 05:38
Hi Baggers
My old project DBC_3DMaths could help you. See attachment.

Specs: P4 2.4GHz, DIMM 256 266Mhz, 60GB HD 7200rpm ATA-133, GeForce 4 MX440, CD-RW+DVD, WinXP

Attachments

Login to view attachments
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 24th Mar 2005 07:50 Edited at: 24th Mar 2005 15:38
Thanks everyone...oh im just looking into quaternions for you to see what they entail!

@Dmitry: wow nice work...they catmullrom and bcc stuff could be really useful thanks...obviously ill credit you if i use them.
<looks through again> Ok people if you need more advanced stuff, dmitry's code is probably the way to go for now as i still have alot to learn...matrices especially !...at least i can use this to help me learn!

<EDIT> Going to be away for the next few days camping, so no updates here for a while. Have fun

Login to post a reply

Server time is: 2025-05-31 05:27:36
Your offset time is: 2025-05-31 05:27:36