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 / Make object Spring function - Help

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Sep 2008 17:00
Hello

I am working on a function that will make a spring, and it was coming on nicely, until I tried putting some mass into the spring.

On the pic attached, you will see lots of cubes. They form different circles moving upwards, only, each circle is rotated the same way as the others, but I need those circles to rotate according to the angle the spring node is positioned at. I`m terrible at explaining, just download the code and you will see for your self.

The code is in the zip file in the attachment.

Please help!

TheComet

Suicide is away of telling God, You can’t fire me I quit !!!!!

Attachments

Login to view attachments
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Sep 2008 08:42 Edited at: 12th Sep 2008 08:45
Hello,

It was a bit hard to go throught your code because it was basically unformatted and uncommented but from what I could glean, it seems you are creating a point (a node I think your calling it) around a center radius of the spring that marks a sprialing position upwards. At this node, you are positing cubes around another radius. Is that about right?

For my own sake, so I could better speak on what you are trying to do, I put together a quick spring algorithm. It's just circle math with a uniformly increasing y value. At each node, I place a cube. The cubes are rotated based on the angle from the main radius that is used to calculate their positions:



The idea for your code should be similar. Find the angle that is used to place the node from the center of the spring. (Is that a#? It was hard to tell.) This is the conjugate y angle (0-y) that your cubes should be rotated towards. Here's a variation of my code that uses turn and pitch to create rings that make up the spring:



Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Oct 2008 18:42 Edited at: 25th Oct 2008 18:44
Hey,

Sorry Latch, I didn`t come back to you, I just forgot about this and didn`t get to thank you.

Anyway, your program worked perfectly, and it`s heading to what I need. There is a lot of turning, pitching and moving in there, but I only positioned objects there to show where the points must be.

My point is, that I need to define these points without creating and moving objects, so using only sine and cosine and other maths. And the positions should be stored in a file or in a dimension.

Is that possible? Because it sure overcomes my limits of maths...

TheComet

Suicide is away of telling God, You can’t fire me I quit !!!!!
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Oct 2008 20:17 Edited at: 25th Oct 2008 20:19
Quote: "My point is, that I need to define these points without creating and moving objects, so using only sine and cosine and other maths. And the positions should be stored in a file or in a dimension.

Is that possible? Because it sure overcomes my limits of maths..."


It sure is possible! Check out the pictures springs I made using triangles and altering a few parameters. I thought you were trying to build your spring from objects but building it from points isn't much different. The math is really the same. The difference is in making your own faces (triangles). The attached picture shows springs that use the same math we've been using in this thread. The difference is, I made faces based on the original calculated positions from this:



It's best to use memblocks for flexibility and speed, but just like you created those functions for building shapes (pyramids and so forth) you can use the native triangles - the process is exactly the same except if you use a memblock, you'll have to calculate UV.

Anyway, the idea is this: you find the x,y and z position of the main point that the rest of the vertices will be placed in relation to (we'll call this the node - I kinda like that now).

For this example will just build two triangles (and end up with a four sided polygon) at each node. That means we need 3 points for each triangle.

The spring should have a certain face height. That will be the top to bottom of the polygon. The face width is the distance from one node to the next. So triangle 1 could look like



I'll leave triangle 2 up to you. Remember it will form a parallelogram. When these triangles are all drawn, you will have your spring using the same math (except for a little bit of addition and subtraction for the points) you already know.

Now, taking this basic premise to the next level, you could build a torrus as the spring shape similarly starting from the node. The math is bit more complex but the principal is the same. An easier shape might be a cube.

If you look back into the DBC Challenges, I have some explanation on making a fish mesh. The idea is to make a grid and bend it towards -z. Then mirror that grid on the opposite side to create a hollow body. That same method could be applied here again using the node as a starting point.

Because you are finding the nodes first, they will be arranged in a general spring shape. As you build edges and faces and connect them relative to the nodes, you will create the spring in solid form.

Enjoy your day.

Attachments

Login to view attachments
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2008 19:45 Edited at: 27th Oct 2008 19:55
Hey, Latch!

Those pictures look great! I have been playing around a little lately, and I have it working. Now comes the really hard part. You mentioned a parallelogram. This only occurs when you have a circle increasing upwards, and the circles are vertically placed on the nodes:



But To make the spring look professional, I think it might look better if you have the rotated along the Z axis according to the increase of the height:



Could you help me out here?

BTW, I asked two teachers this question, and they said that they didn`t know and this question is usually asked at university... But the third teacher said I should send him the maths.

So, lets see what happens.


Also, that is a good idea with the torus. I will add that to the new version of the DBC object functions.

So, thanks in advance, TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Oct 2008 22:04 Edited at: 3rd Nov 2008 21:30
Don't forget, a spring's incline isn't straight like a square, it's curved. If you line up a series of squares, they only incline linearly unless you leave gaps. The parallelogram allows for a change in upward angle. If you look at the bottom spring of the picture I attached in the previous post, that spring is made up of squares. It uses a skewed radius so that the spring expands, otherwise it would just be a circle.

Here's a variation of the spring code from the above post that alligns all the cubes as squares (tops and bottoms) - i didn't change any of the comments.



As far as the rest of the math, I'm trying to work out a simple way that is just a variation of the math so far.

[EDIT]
The simplest way seems to be to use torrus math. It's a combination of what we've been talking about, and using a torrus to sprial upward. The premise is the same: the nodes represent the upward spiral, the position where each circle of the torrus is drawn. Within each node iteration, is where the circle, or slice of the torrus is drawn. Also within the node iteration is the value to increase to add to the y values of the torrus slices so each slice is a little higher per node. In the end, you connect the points of all of the slices with triangles (faces). the node is just a place holder to help find where the next slice will be. In this case, it's just the y angle increment over the number of nodes. Inside each node iteration is a z angle increment representing the points on the outside of the torrus for each slice.

If you look up the math for a torrus, and you apply it based on the previous examples, you're done with finding the points that make up the spring. The hardest part is connecting the triangles.

Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Dec 2008 14:09 Edited at: 2nd Dec 2008 14:10
I had a nice meeting with my teacher, and he explained and helped me with the function. The only thing I need to know is this:

Does anyone know how to calculate the length of the sprial?

What I am doing is I am making a tunnel spiraling upwards, by defining points around small circles that I drag upwards along a big spriral. I will then connect those points with triangles, and a tunnel will form.

Anyway, I need the length of the spiral to calculate at what angle the spiral is spiraling apwards, so I can tip the small circles.

@Latch

I have made a torrus. I will post a screen shot this week end, I am on the school computers right now and don`t have time.

Thanks, TheComet

Peachy, and the Chaos of the Gems

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Dec 2008 11:58
Quote: "Does anyone know how to calculate the length of the sprial?"


Anyone? There must be someone that knows how to calculate the length of a spiral... Please help!

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Dec 2008 15:11 Edited at: 8th Dec 2008 15:15
Off of the top of my head if you are using nodes to find the center of the torrus spring that each slice (circle) is drawn around, then the length is the sum of the distance between nodes. This is the length down the center. The inside length of the spiral will be less and the outside length will be more. Use any same position on each circle and find the distance between those positions to find any length along a specific path (outside, inside, top, bottom, etc.). Though I think you would be most interested in the center length.

And in this example based on an above post, I know I'm making 10 loops and each loop has 30 nodes. I also know my cubes are 20 units so for a super quick, rough estimate, I could say the length = 10*30*20 which is 6000. This is pretty close to the calculated length using the distance between nodes:



Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Dec 2008 15:36
Ah, cool Latch! I will be sure to try it out!

Thanks, I will give you some feedback.

TheComet

Peachy, and the Chaos of the Gems

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Dec 2008 13:03 Edited at: 13th Dec 2008 13:11
Hey Latch!

For the length of the spring, I used this:



Here are some pics of my latest springs:

2 node spring (flat)



3 node spring (triangle)



8 node spring



As you see, the random texture I used textures all of the triangles individually, but I want the texture to texture the hole spring as one object...

Could someone help me out with re-UV mapping the object?

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Dec 2008 23:26
It's a clever formula. It looks like it uses the circumference of a circle and multiplies that times the node steps. In your recreation of the formula, you should be careful of two things:

finishy#-starty#

Unless you are compensating for the height increment between nodes, you will end up with a highly inflated length result. If you take the top y and subtract out the bottom y in the casee of 100 top and 0 bottom, you will be left with a value of 100. Unless the spring is tightly coiled and there are no spaces in between coils this will work, but you have to account for the empty space in between coils which are not part of the length which could result in a value of say 50 or 25 vs 100. That is why the non-altered formula uses height / stepheight . It's not the total height you are after but the percentage of height resulting from the height step and the angle increment. Remember, you're not dealing with a complete cylinder you are dealing with a spiral. If you were to unwrap a cylinder, you would have a rectangle. And the area of the rectangle would be the outside surface area of the cylinder. The spiral unwrapped would be a diagonal line and it's approximate length could be calculated using the height and the width of the unwrapped cyclinder rectangle:

length=sqrt(wd^2+ht^2)

This is very different than the area:

area=wd * ht

If we plug in some fake numbers:


So that's why I caution you in using finishy#-starty#. But maybe you already compensated for the height increment and I just made a wordy post for fun!

radius#

If the radius is always the same this is fine. But you may want to account for a change in radius (like if you made a funneling spring or a clock spring that spirals wider from the center) you'll have to adjust the radius in the calculation and sum the results.

Quote: "Could someone help me out with re-UV mapping the object?"

Pay attention to the order of vertices that you make your triangles out of.

Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Dec 2008 09:13
Quote: "Pay attention to the order of vertices that you make your triangles out of."


Well, I have no idea how to uv map an object... I searched the forum and there is nothing helpful...

Does anyone care to write a quick, simple example of uv mapping an object?

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Dec 2008 00:06 Edited at: 20th Dec 2008 00:36
Using the triangle object in DBC, it depends on your layout of triangles and the order of vertices. You can shift the position of the texture using a combination of scale object texture and scroll object texture.

The formula you'd use to calculate the UVs could vary from shape to shape. The thing to keep in mind is the texture UVs are a percentage position of the texture that you want attached to a particular vertex. If you had a 50 x 50 grid running in the x and z direction and wanted a single texture across it without repeats you find the UVs by finding the percentage that the vertex represents in relation to the object as a whole:

u=x/total grid x size
v=z/total grid z size

Enjoy your day.

Login to post a reply

Server time is: 2025-06-07 20:37:04
Your offset time is: 2025-06-07 20:37:04