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 new (animated) models from a scratch with dbc

Author
Message
HomerS
17
Years of Service
User Offline
Joined: 8th Apr 2007
Location:
Posted: 4th May 2013 01:53
Hi All,

Try to make an model with limbs in dbc. In my example I made en simplistic person. Just to try out how to use limbs and how they work. I can let the arm rotate, but the problem is that the xyz is in the middle of the object box. Is it possible to move the xyz point in this box, so that the arm rotates like a real arm? It looks like an handicap wright now.

the robot arm (one of the basic examples of dbc) is also using the middels of the blocks rotating and not the edges.

If there is a way, please let me know.




Toedeledoki
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th May 2013 22:36 Edited at: 4th May 2013 22:39
Hi,

Here's an old entry of mine from the DBC challenges. This was when I was first starting out with DBC. Looking at the code now, I can see what needs improving! There's a function to create a robot of sorts. The robot is constructed with simple DBC objects. If you look at the code, it should show you how to change the pivot point for rotation.



Enjoy your day.
HomerS
17
Years of Service
User Offline
Joined: 8th Apr 2007
Location:
Posted: 5th May 2013 21:57
Hellowww Latch,

That looks amazing, I see you use spheres to rotate the arm, verry clever.

I also like the clock as an texture. Didn't know that we can get images for texture under the 3d world.

Greetings!

Toedeledoki
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th May 2013 22:34
Quote: "I see you use spheres to rotate the arm"

Yeah, that can hide the joint, but you have to be careful with polygon count.

Here's a general approach to change the pivot (rotation point):

Let's say you make a leg. We'll just use a long box as the upper leg. General, the upper leg would rotate at the hips, so it's pivot point would be at it's top Y (assuming Y is up and the box is long in the y direction).

So let's make a long box of 20 units on the Y and 4 units in the X and Z directions:

Quote: "make object box 1,4,20,4"



If we rotate that, it's going to spin around it's center. Legs shouldn't do that! What we want to do, is shift it's pivot to the top of the leg. That means bring it down to (0,0,0). We know that the leg is 20 units in the Y direction and that it's pivot right now is at in the center (0,0,0). If that's it's center, then there are +10 units above and -10 units below. This one is pretty easy because all we need to do is subtract the the top value from the Current Pivot (which is 0)



That is the concept. So in practice, we will offset the ROOT limb from it's current position. the ROOT limb is the object's limb number 0. Our box is object 1, so it's root limb is limb 1,0. We just need to offset that in the Y direction with our new value:



Ok, so far, but that won't do anything until we get the new mesh data resulting from the offset.



Now we have the new mesh data that includes the offset. We can delete the old object, and recreat it using this new mesh data that has the offset:



If you rotate the object now, you'll see it's pivot has changed



Once you have your offset meshes, you would add these as limbs to the object you are building. In the example above, we recreated the leg object for demonstration purposes. There's no need to recreate the object when you are just adding meshes as limbs.

Enjoy your day.
HomerS
17
Years of Service
User Offline
Joined: 8th Apr 2007
Location:
Posted: 6th May 2013 00:13
complex to find out. but it is cool to do it that way.

Toedeledoki
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th May 2013 06:35
The explanation sounds more difficult than it really is. Here's the code condensed:



Enjoy your day.
HomerS
17
Years of Service
User Offline
Joined: 8th Apr 2007
Location:
Posted: 6th May 2013 15:09
yes, it is easy but it is hard to find it out, when you don't know this.



Toedeledoki
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th May 2013 18:04
Yeah, it's not obvious and it's not really talked about in the help files. If it helps, this is a general description of what's going on:

Each 3d object has at least 2 sets of coordinates.
1. It's own local coordinates
2. It's world coordinates

The world coordinates are where DBC tells you a specific object's local coordinates are located relative to the DBC 3D world that has a center of (0,0,0). So when you get back a value from object position x(number) you are getting the world's X position of that objects pivot point. Locally, the pivot point is still (0,0,0).

The local coordinates represent the point that the vertices of an object will all rotate around relative to itself. So to the object, this is always (0,0,0) but it's vertices will be offset from that point some distance away. A sphere with a radius of 10 will generally have all of it's points 10 units away from it's pivot point.

Sometimes, you don't want the vertices of an object to be positioned so that the local pivot is dead center. Mathematically, you would translate those vertices some distance away from that local pivot. The way to do that in DBC is by offsetting the root limb from it's local pivot. It's similar to how you would offset a limb from another limb, but because you are offsetting it from itself, you are in essence translating the vertices without using matrix math.

Now, you actually don't have to use the limb offset commands to offset the root limb 0. I do that for my own understanding of what is actually happening - the root or local vertices are being moved.

You can get the same results by positioning an object anywhere and then making a mesh out of it. As soon as you make a mesh out of an object, the mesh will always have it's local pivot at the World Coordinates of (0,0,0). So if you made a sphere and position it at say 100,0,0 then made a mesh out of it. If you create an object out of that mesh, when you rotate that object around the Z axis, it will seem to orbit around with a radius of 100 units from the center.

So summing it up:
When you move an object or offset it's limb 0 position and make a mesh out of it, the mesh you create will have a local center offset by the distance you moved or placed the original object or limb.

The same rules apply for rotating the object or limb 0.

Enjoy your day.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 9th May 2013 23:54 Edited at: 9th May 2013 23:55
To add to what Latch has said, this is a bit of code that Latch posted (I don't know what thread it came from) that I used to learn how to create animated models using DBC code.



This basically sets up all the limbs and keyframes for the animation (as you would do in a 3D modelling package) which allows you to use the object animation commands.

one of these days I'll come up with a better signature

Login to post a reply

Server time is: 2024-04-20 05:58:29
Your offset time is: 2024-04-20 05:58:29