(Note: You can use this code for any purpose whatsoever without giving me so much as a nod.)
I'm extremely new, both to Blitz3D and to Tokamak, but when I asked if Tokamak could be used to simulate spherical gravity rather than vertical, the good Mr. Sweeny gave me the following advice:
-Get the directionvector from the center To the actual Object.
-Normalize the vector And call
-TOKRB_SetForce
Let me see how far I can go before I get stuck...
I'm starting with this tutorial: http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=bot__builder103252004031037.html
-Changed the model name to point to my own creation. "Down" gravity works normally. :)
-Turned off gravity by setting the Y value to 0. Simple enough. I quickly figured out how to change the direction spacebar pushes them by modifying the values, and how to make Blitz choose random numbers within a range as the values.
Okay, let's see here... Guess I should probably write a function for this.
Direction Vector... hmmm. The first step for li'l ol' me is to figure out what a vector is. And since the Blitz forum search engine AND the playerfactory forum both return absolutely no results, ever, no matter what search terms I enter, I suppose I'd better consult my old college buddy professor Google for advice...
http://www.netcomuk.co.uk/~jenolive/vect3.html
Um... wait, what?
http://www.gamedev.net/reference/articles/article813.asp
Ah! Okay, that makes more sense!
Okay, so to "get the direction vector," I need to know the coordinates of the center of the world (Guess I'll just use the values 0,0,0. Later on, I can add an entity to represent the center of gravity, I guess...) and the x,y,z coordinates of each Entity.
Let's see... I'll use that nifty little "for i=1 To ENTS" trick to do it once for each particle object...
That normalizes the verctors... I think. I hope I didn't have to declare those variables before assinging a value... well, if I did, it'll let me know when I try to run it. ;)
Whoops, forgot some )'s!
Okay... now I can just call the Tokamak command like you said to, right?
Where do I get the values for gravity and mass...?
I guess I can arbitrarily define the gravity as a global value someplace up near the top of my program. Later on, I can turn that into a gravity entity with adjustible gravity pull. In the meantime, I'll use the original y value from TOKSIM_CreateSimulator, negative ten.
Hmmm... I see a SetMass command in the Blitz-integrated Tokamak help Command Reference, but no GetMass. I guess I'll randomly try GetMass(rb(1)) and see if it works...
Nope! Blitz's code colorizer doesn't seem to recognize GetMass as a command! I've come this far without help, but now I'm totally stuck.
Please kindly take it from here, if you could, Sweenie or other Tokamak experts. How do I get the mass of a Tokamak entity?
Also, if anyone has any slick optimizations for the above function, or if I'm doing it all wrong and the above won't work, please post now! :D
I'm extremely new, both to Blitz3D and to Tokamak, but when I asked if Tokamak could be used to simulate spherical gravity rather than vertical, the good Mr. Sweeny gave me the following advice:
-Get the directionvector from the center To the actual Object.
-Normalize the vector And call
-TOKRB_SetForce
Let me see how far I can go before I get stuck...
I'm starting with this tutorial: http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=bot__builder103252004031037.html
-Changed the model name to point to my own creation. "Down" gravity works normally. :)
-Turned off gravity by setting the Y value to 0. Simple enough. I quickly figured out how to change the direction spacebar pushes them by modifying the values, and how to make Blitz choose random numbers within a range as the values.
Okay, let's see here... Guess I should probably write a function for this.
Function SphereGravity() End Function
Direction Vector... hmmm. The first step for li'l ol' me is to figure out what a vector is. And since the Blitz forum search engine AND the playerfactory forum both return absolutely no results, ever, no matter what search terms I enter, I suppose I'd better consult my old college buddy professor Google for advice...
http://www.netcomuk.co.uk/~jenolive/vect3.html
Um... wait, what?
http://www.gamedev.net/reference/articles/article813.asp
Ah! Okay, that makes more sense!
Okay, so to "get the direction vector," I need to know the coordinates of the center of the world (Guess I'll just use the values 0,0,0. Later on, I can add an entity to represent the center of gravity, I guess...) and the x,y,z coordinates of each Entity.
Let's see... I'll use that nifty little "for i=1 To ENTS" trick to do it once for each particle object...
Function SphereGravity() For i=1 To ENTS vx#= 0-(TOKRB_Getx(rb(i)) vy#= 0-(TOKRB_Gety(rb(i)) vz#= 0-(TOKRB_Getz(rb(i)) End Function
That normalizes the verctors... I think. I hope I didn't have to declare those variables before assinging a value... well, if I did, it'll let me know when I try to run it. ;)
Whoops, forgot some )'s!
Function SphereGravity() vx#= 0-(TOKRB_GetX(rb(i))) vy#= 0-(TOKRB_GetY(rb(i))) vz#= 0-(TOKRB_GetZ(rb(i))) End Function
Okay... now I can just call the Tokamak command like you said to, right?
Function SphereGravity() vx#= 0-(TOKRB_GetX(rb(i))) vy#= 0-(TOKRB_GetY(rb(i))) vz#= 0-(TOKRB_GetZ(rb(i))) TOKRB_SetForce (rb(i),vx#*Grav*Mass,vy#*Grav*Mass,vz#*Grav*Mass) End Function
Where do I get the values for gravity and mass...?
I guess I can arbitrarily define the gravity as a global value someplace up near the top of my program. Later on, I can turn that into a gravity entity with adjustible gravity pull. In the meantime, I'll use the original y value from TOKSIM_CreateSimulator, negative ten.
Hmmm... I see a SetMass command in the Blitz-integrated Tokamak help Command Reference, but no GetMass. I guess I'll randomly try GetMass(rb(1)) and see if it works...
Nope! Blitz's code colorizer doesn't seem to recognize GetMass as a command! I've come this far without help, but now I'm totally stuck.
Global worldgravity=-10 Function SphereGravity() vx#= 0-(TOKRB_GetX(rb(i))) vy#= 0-(TOKRB_GetY(rb(i))) vz#= 0-(TOKRB_GetZ(rb(i))) TOKRB_SetForce (rb(i),vx#*(WorldGravity)*Mass,vy#*(WorldGravity)*Mass,vz#*(WorldGravity)*Mass) End Function
Please kindly take it from here, if you could, Sweenie or other Tokamak experts. How do I get the mass of a Tokamak entity?
Also, if anyone has any slick optimizations for the above function, or if I'm doing it all wrong and the above won't work, please post now! :D