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 Professional Discussion / Finding the exact location of an object vertex

Author
Message
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 30th Aug 2015 04:23 Edited at: 30th Aug 2015 04:24
How would I find the exact location of a vertex in an object? I am working on a model editor that has vertex manipulation and I need to place balls on each vertices of the object that you can then drag to move the vertices.

I have already worked out how to place the balls at the vertices, but my problem is when I scale the object, I can't get the new position of the vertices. I somehow need to work out the object position, the vertex position and the objects scale into 1 code.

I've been trying to do this for a few days now!

Any help would be great!

www.liambradburymusic.com - professional music for your games.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Aug 2015 14:28
Hi there.
You can make a mesh with the actual scale and reset actual mesh. Here is an example. It uses a counter to position a reference object to see in what vertex we are.



Cheers.

I'm not a grumpy grandpa
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 30th Aug 2015 16:22
If you know the scale of your object, your vertices' "actual" (post-scale) positions would be (vertexPosX * xScale, vertexPosY * yScale, vertexPosZ * zScale).
This doesn't take rotation into account though; if you need to support that the easiest would be to transform your vertex coordinates by the object's world matrix (this includes the scale factor as well so you wouldn't need to deal with that separatedly then). If you have a multi-limb object each limb's world matrix is usually relative to that of its parent limb, such that matWorld = matWorld[limb] * matWorld[limb.parentLimb] * matWorld[limb.parentLimb.parentLimb] * ... and so on until you reach the root limb.

LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 30th Aug 2015 17:16
thanks guys I'll give both suggestions a try

www.liambradburymusic.com - professional music for your games.
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 31st Aug 2015 02:50
@ chafari

Your example works perfectly, but the problem I'm having now is that I can't reset the scale value back to 0 like you do in your example, I am using a sliding bar that shows the scale of the object, the value doesn't reset.

www.liambradburymusic.com - professional music for your games.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Aug 2015 12:03
Quote: " I can't reset the scale value back"


It is difficult to know without some code .It might depend on the design of your sliding bar. In the example I showed you here, we are into the main loop, so all positive data, will increase the object scale unless we reset the value to zero.

Here is an example that works with two different variables. Use the mouse .



Cheers.

I'm not a grumpy grandpa
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 31st Aug 2015 13:44
In addition, there is a plugin available which provides more vertex expressions and commands than is available. However, there is no quick easy solution for your problem if limbs and objects can rotate, as was mentioned.


Plugin

Hotline
15
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 31st Aug 2015 14:48
Transform the vertex position into your model's space like Rudolpho suggested it.Thats the easiest (and probably the most common) solution

[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Aug 2015 18:56
@Chris Tate
Nice plugig

@Hotline
Quote: "Thats the easiest (and probably the most common)"


All objects are made of vertex . When we scale the object, we transfomr somehow the vertex to a new position. If we want to manipulate vertex, then we need Vertexdata commands . With vertexdata comands, we can see where the object has all vertex, but no matter what we do to the object...scale , move or rotate it ...vertex will be in same position unless we make a MESH of the object once we have transformed in any way and change the MESH again to update the object .

Cheers.

I'm not a grumpy grandpa
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 31st Aug 2015 19:01
Thanks guys, you've helped a lot! I've got it to work now.

www.liambradburymusic.com - professional music for your games.
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 31st Aug 2015 19:17 Edited at: 31st Aug 2015 19:22
I found an interesting solution to this problem, I found that instead of using "scale object", I just created my own scale function by moving the vertices and that seems to work.

To change the Y scale of a plain object I used


doing it this way doesn't scale the vertexdata like scale object was doing, which makes it easier to find the position of the vertex.

Both ways work fine though!

www.liambradburymusic.com - professional music for your games.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Aug 2015 19:45
Quote: "Both ways work fine though!"


Yeah ! we can instead of of scaling object, move vertex matching an image background. We can even move a block of vertex .

Example:



Cheers.

I'm not a grumpy grandpa
Hotline
15
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 31st Aug 2015 23:38
Quote: "All objects are made of vertex . When we scale the object, we transfomr somehow the vertex to a new position. If we want to manipulate vertex, then we need Vertexdata commands . With vertexdata comands, we can see where the object has all vertex, but no matter what we do to the object...scale , move or rotate it ...vertex will be in same position unless we make a MESH of the object once we have transformed in any way and change the MESH again to update the object ."


The original question was this : How to find the position of a vertex in a scaled mesh.

I just told him the easiest, cheapest, fastest, professional way of doing this, thus transforming a vector in different spaces rather than create mesh duplicates each time the mesh's vertices are translated.

[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Sep 2015 00:26
@Hotline
I know you are waiting for some feedback from me.

Quote: "The original question was this : How to find the position of a vertex in a scaled mesh. "


No, it wasn't !! it was ...How would I find the exact location of a vertex in an object?

Quote: "I just told him the easiest, cheapest, fastest, professional way of doing this"


No necessary to be so arrogant . The MAKE MESH FROM OBJECT , and CHANGE MESH is exactly for that...for vertex animation .

I'm old but not stupid !!

@Hotline Believe me, I like most of your codes, and I have your Transform gizmo plugin, but for this purpose we can use Vertexdata Commands. I can't understand way you copy and paste my whole coment, as saying that I only speak nonsense .

I'm trying to give him some solution to his problem . I hope you do not mind my comments . Sorry if there has been some misunderstanding or if I wrote something that could hurt you .

I'm not a grumpy grandpa
Hotline
15
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 1st Sep 2015 01:19 Edited at: 1st Sep 2015 01:26
i didn't say everything was nonsense idk where did you get that...

Quote: "No, it wasn't !! it was ...How would I find the exact location of a vertex in an object?"

No... he mentioned that he already find a solution for that , he just wanted to know how to take scale into account... Rudolpho's and my suggestion automatically handles that

Quote: "I'm old but not stupid !!"

I didn't say that either

Quote: "but for this purpose we can use Vertexdata Commands."


No... for this purpose we can use linear algebra :
1 .Transform the vertex position into world space , put a ball at that position...
2. If you moved the ball , transform the ball's new position to the object's local space and move the vertex to that position

but if you like creating copies of the same mesh in memory each time a vertex is moved and then release the copy , i'm cool with that.

I didn't wanted to be rude , and i deeply regret having hurt you.
Cheers

[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 1st Sep 2015 20:23
sorry guys, got 1 more question.

how would I scale an object by using vertexdata?

I have this at the moment, this is to scale the X value. The problem with this is that it just moves the vertices left or right, it doesn't actually scale the object.




I know that it should be get vertexdata position x(x) * (changex#/2) but that scales it by a massive amount which I can't get under control.

Any ideas?

www.liambradburymusic.com - professional music for your games.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 1st Sep 2015 21:46
If the object centered on its local origin, just multiply the vertices x, y and z position by the x, y and z scale.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Sep 2015 22:23 Edited at: 1st Sep 2015 22:25
Quote: "I know that it should be get vertexdata position x(x) * (changex#/2) but that scales it by a massive amount which I can't get under control."


Why divide by 2? If you are just scaling, e.g. doubling the size then just use scalex# = 2 in get vertexdata position x(x) * scalex#. That assumes the object is centred at zero as WickedX points out.

Sounds like the problem is the way you've calculated changex# (as well as dividing by 2 which is wrong). How have you calculated it?



Powered by Free Banners
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 2nd Sep 2015 00:47 Edited at: 2nd Sep 2015 00:51
the object isn't centred at zero, it can be anywhere the user places it, saying that though I can't even get it to work when I place it at 0. Also I am not using a scale percentage, I'm using a sliding bar (0-2000) that represents the overall size of the object to increase the X scale.

I'm still struggling with this, can't seem to get it to work at all. Whenever I try using the get vertexdata position x(x) * scalex# approach, the object seems to scale exponentially

www.liambradburymusic.com - professional music for your games.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 2nd Sep 2015 01:11
I'm taking about the object local coords. We're it's placed in world space will not matter. This method is cumulative, if you double the object scale you can't change it back by giving the function a scale value on 1. You need to use a negative scale factor.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Sep 2015 01:14
Quote: "Whenever I try using the get vertexdata position x(x) * scalex# approach, the object seems to scale exponentially"

Because that's what you are telling it to do (if I understood you correctly).
If you multiply the position by a value 0..2000 you'll make it between 0 and 2000 times larger. For whatever reason the DBPro scaling functions use percentages, such that 100 is "full" scale, but when doing it manually 1 is full scale, if that may be what you missed?

Other than that, if you save the result of that calculation to your vertex data, then the next time you call get vertexdata position it will return the position you calculated the last time, not the original position, so this will also cause exponential changes over time.

LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 2nd Sep 2015 01:33 Edited at: 2nd Sep 2015 01:35
This is an extract of the code I've got so far. From what you guys are saying I think I need to re-design my scaling function to percentages instead of the actual size.

This is what I have at the moment.



www.liambradburymusic.com - professional music for your games.
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 2nd Sep 2015 02:33 Edited at: 2nd Sep 2015 02:35
ok I've finally got it to work.

Thank you so much for you help guys, I'll give a shout out to you all on the softwares forum page when I release the next update (which is here! http://forum.thegamecreators.com/?m=forum_view&t=215127&b=5)

Here's the working code, I'll just take this and import it into my actual code.



www.liambradburymusic.com - professional music for your games.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 2nd Sep 2015 02:35 Edited at: 2nd Sep 2015 02:36
At work now, hard to concentrate. In last post I meant to say fraction not negative. Will look at code latter.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 2nd Sep 2015 09:20
Never mind that last post. Nice application. Wish you the best.
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 3rd Sep 2015 01:54
just out of interest, if the object local co-ordinates weren't at 0, how would you reset them to 0? I just had a quick look at the commands list and there's no way of doing that unless there is a plugin somewhere

www.liambradburymusic.com - professional music for your games.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Sep 2015 03:40
You would need to find the vertex extend and calculate where the center is then move the vertices around the origin.
LiamBradbury
12
Years of Service
User Offline
Joined: 28th Apr 2011
Location: Manchester, UK
Posted: 3rd Sep 2015 05:45
it would be so much easier if there was a "set local co-ordinates to object orientation" command

www.liambradburymusic.com - professional music for your games.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 4th Sep 2015 09:40
To be honest. I would go with Rudolpho’s suggestion. There is a function in the plugin Chris Tate provided a link to, that can be used to copy an objects world matrix into a matrix4 structure. Set a vector3 structure with each vertex position and transform it using Transform Coords Vector3. This will give you the position for the vertex markers. I believe, the objects local origin should not matter. Now you can scale the object without actually changing the vertices. The plugin also has a Set Matrix4 Element function, should you have to set the scale factors yourself, as Rudolpho stated.

Login to post a reply

Server time is: 2024-03-28 20:51:37
Your offset time is: 2024-03-28 20:51:37