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.

Author
Message
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Sep 2010 01:44 Edited at: 11th Nov 2010 20:13
I need to figure out a way of converting the world position at: X#, Y#, Z# using this code:

Edit: Worked out all the code. Now I just have one problem left. (@ Last Post)

Thanks
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 11th Sep 2010 07:20
First of all you need to know how a texture is applied to the sphere object which is essential in the case.I found something in internet :
http://www.vterrain.org/Textures/spherical.html

It can give more light to you.I'm not sure which is gonna be the best way for texturing a sphere in dbpro.I think it should be cubic way, because of the look of textured sphere with reggular image the poles looks horrible as you know.Maybe number of triangles like the picture in the link should correspond to how many columns/rows you give to the sphere object.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 11th Sep 2010 17:17 Edited at: 11th Sep 2010 17:18
Quote: "I need to figure out a way of converting the world position at: X#, Y#, Z# using this code:

` Get Point On Object
+ Code Snippet

Object = Pick Object(MouseX(), MouseY(), 1, 1)

X# = Camera Position X() + Get Pick Vector X()
Y# = Camera Position Y() + Get Pick Vector Y()
Z# = Camera Position Z() + Get Pick Vector Z()



to an image position."

you need to figure out which poly of the object is picked,
then you need to calculate barycentric coords for that point on poly which is under the cursor,
using that barycentric coords and the texture uv coords of the poly's vertices you can calculate the exact uv coordinates of the point which is under the cursor,
when you know that uv coords you can find out which pixel on the image coresponds to that uv coords,
and thats it!

Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 11th Sep 2010 17:30
I haven't implemented anything, but I'd imagine it would be something a bit like this:

Use Pick Screen to get a vector from the screen through the mouse. Using this vector, create a ray using Sparky's DLL, using SC_IntersectObject. When you have an object and an intersection coordinate, you have to somehow convert that to UV coordinates on the object's texture. Then, you simply paint the texture at those coordinates.

"everyone forgets a semi-colon sometimes." - Phaelax
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 12th Sep 2010 02:18
How can I pick a vertex?

This was my first attempt but I found that it doesn't pick a vertex correctly when I rotate the object.


I think I can use the U, V coords to determine a point on the image.

Thanks
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 12th Sep 2010 21:56 Edited at: 12th Sep 2010 23:27
I noticed:

Quote: "UV coordinates are applied per face, not per vertex."


This means I can use the pick vertex code above.

This means I have to:

- Pick a face
- Get the UV coord of the three vertexes that make up the face
- Calculate a face UV coord from the pick object raycast (X#, Y#, Z#)

I am trying to figure out how to pick a face:


How do you test if X#, Y#, Z# (Pick Object Vector) is within the three vertexes: (X1#, Y1#, Z1#, X2#, Y2#, Z2#, X3#, Y3#, Z3#)?

How would you get the face UV? I thought of using distances from each point and the UV from each point to determine the UV of the pick vector (X#, Y#, Z#)

Any help would be appreciated.

Thanks
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 13th Sep 2010 01:34 Edited at: 13th Sep 2010 01:42
Quote: ""UV coordinates are applied per face, not per vertex.""

that's not true, face doesn't have uv coords, vertices does

To pick a face:
sparky collision dll has this command:
SC_getFACEhit

when you know whick face is picked, you can find out barycentri coords with this function (u# and v# are barycentric coords)



you will also need this:


DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 13th Sep 2010 02:25
@Brendy boy - Wooow Lots of math. Thanks a ton. I should see if this works.

Quote: "u# and v# are barycentric coords"
Didn't know that. Look up barycentric coords on wikipedia and I still couldn't draw that conclusion.

Could u explain how to use your function? Also can't this:
be used to determine which face is picked?

Thanks
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 13th Sep 2010 02:50
Quote: "Also can't this:
be used to determine which face is picked?"

no

the function i gave you can or you can use sparky's dll.
if you use mine here's what you should know:
you need to check every poly against a line/vector that is projected from the screen to the scene (hint: pick screen command)
the starting point of that line you need to put in orig_v
the direction of that line you need to put in dir_v
v0_v, v1_v, v2_v are 3d coords of poly's vertices
if ichecked poly is picked function returns 1 else 0.
If poly is picked u# and v# will contain barycentric coords, but you have to declare them as global.

When you manage to find out which poly is picked and when you will have the barycentric coords post here i i'll tell what to do with them.

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 13th Sep 2010 03:18
@Brendy boy -

I don't think I used your function correctly. I don't think the direction is the object's angle. Is it the end point? If so how would I find the end point. I know the start point is X#, Y#, Z#. (FYI: X#, Y#, Z# - Pick Object Coords)



How I am calc. pick object coords:



Thanks for your help. ^^
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 13th Sep 2010 14:51 Edited at: 13th Sep 2010 14:58
Quote: "I don't think the direction is the object's angle."

it isn't

you get direction when you subtract starting point from ending point.
to get starting point do this:


to get ending point do this:


to get direction:


now to get which poly is picked (if you dont want to use sparky's) do this:
NOTE: the following method works only if object has indexdata, if it doesn't the following code won't work


DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 13th Sep 2010 23:55
@Brendy boy - Thanks again for your help. Forgot about pick screen. I used that at one time for determining normals.

Your function seems to always return 1.

"return FALSE" Is commented out:



Thanks
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Sep 2010 00:17
Quote: "Your function seems to always return 1.

"return FALSE" Is commented out:"

replace `return FALSE with return 0 and then it should work

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 20:21
I couldn't get it working. The function looks like it was converted from Dark GDK or C++ and I don't know if it is working correctly.

Check out the code:


If this turns out to be to much of a hassle then can you show me an example with SC_getFACEhit?

Thanks for your help!
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Sep 2010 21:04 Edited at: 14th Sep 2010 21:07
the code is OK, but it can't be used with dbpro primitives because they have different indexdata structure. Load an object exported from some 3d application and it should work.

And: don't use return_val inside intersect_triangle function, just call exitfunction 0 command, it will be faster

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 21:09 Edited at: 14th Sep 2010 21:10
Tried loading from the media of dbp.


It still doesn't work.

Edit:
Result always = 0 and u/v = 0.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Sep 2010 21:16
at the end of the function it needs to be endfunction 1, not endfunction returnVal

paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 14th Sep 2010 21:26 Edited at: 14th Sep 2010 21:32
Have a look at an old wip of mine and let me know if its of any use to you.If so ill dig out the code and post it up for you.
http://forum.thegamecreators.com/?m=forum_view&t=170444&b=8
My code takes into account the various limbs of an object and wether they are built up of vertex list data or face/triangle list data,took a while to figure all this out and i only managed it with the help of others on here,but only too glad to pass all this on if you need it.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 21:38
@paul5147 - That would be greatly appreciated. ^^ The Object Painter I am making is extended into my image manipulation lib. I am making a full on decal/image editor for shaders and materials. I hope to get an example up asap once I figure out how to paint objects. I will add credit where credit is due. ^^ Thanks
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 19th Sep 2010 19:35
Sorry for the delay had a few things on but heres the basic code,i have stripped quite a bit out of this to try and make it simple to understand,the full version allows you to select from the texture you want to apply to the model as well by exporting the file as a .x model with the new texture data included then reloading the model so DBPro takes the new data into account.I cant find a way to make add the new texture data directly into the object any other way,if you want the rest of the code then let me know.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 20th Sep 2010 05:50 Edited at: 20th Sep 2010 05:52
@paul5147:

Wow. I got to say nice job. Generous code contribution for the TGC community. Thanks.

I just needed to get the object position to image position.

The only thing I can't figure out is:
It doesn't show the image position of the red cube. Do you know how to get the image pixel x, y position?

I'll take a deeper look at the code when I have the time.

Thanks again.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 20th Sep 2010 22:00 Edited at: 20th Sep 2010 22:03
This is the part of the code which deals with positioning the marker (red cube) on the surface of any hit object.

The varibles cx#,cy#,cz# hold the position of the cube or you could just use `object position x()` etc after this loop to retrieve it later.
Trying to convert that to the position on an image thats being used to texture an object is not quite that simple though,because of the way that the uv co-ordinates can be manipulated and stretched around an abjects vertices.A quick but not always accurate way to do it is to add up the 3 sets of uv co-ordinates that the hit polygon has , then devide by 3 and then multiply the image size x and y by the results,but its not guaranteed to give you the results you need especially if the uv`s have been stretched to greater than the normal 0.0 to 1.0 range.
If you can share some code of what your trying to achieve , working or not , then chances are i may have a snippet that does exactly what you want all ready.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 21st Sep 2010 00:46
@paul5147 - Ok.

Here is what I am trying to do:
- Pick Object to get X, Y, Z
- Convert to UV Coords
- Convert UV Coords to Image X, Y

I don't really need much more then that.

Here is what I am going to do with the painting code:
I have code for painting using brushes. I am working on code for painting decals and images using the brushes. I also have a bunch of functions for making a beveled edge. I have heightmap and working on a normal map function. All this together will be a part of my material editor. The material editor is for an even bigger project.

Thanks for your help.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 21st Sep 2010 04:43
@Brendy boy or @Everyone - How do you convert the UV to the image X, Y?

Thanks
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 21st Sep 2010 22:21
image_x=int(u#*image_width)
image_y=int((1.0-v#)*image_height)

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 21st Sep 2010 22:22
@Brendy boy - Easier then I thought it was. Thanks!
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Nov 2010 00:57 Edited at: 11th Nov 2010 01:00
I have been spending wayyy to much time on this problem. I have a polygon (triangle) with three vertexes. Each vertex has a UV and XYZ Position. I have the pick vector XYZ and I need to calculate the UV from the pick vector.

I worked out the problem a bit and only found the UV distance from Vertex_1's UV. I don't know how to break up the UV into U and V.

Been like a month working on this problem. Searched what seems like all of google for the answer and used whatever math I knew.

Any help is appreciated.

Thanks

DigitalFury
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Nov 2010 13:38
RUSSIA has just released something that does this I think:
http://forum.thegamecreators.com/?m=forum_view&t=177555&b=8

Might be worth asking...?

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Nov 2010 20:11 Edited at: 14th Nov 2010 05:47
@baxslash - Already found that. Read the threads and it seems like green gandalf was told to remove the answer. I could ask. I am going to try working on it a bit more. I think I found a way to simplify the problem.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 11th Nov 2010 23:08 Edited at: 11th Nov 2010 23:09
Here you go:
you will need sparky's collision dll



DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Nov 2010 23:20
@Brendy boy - Thanks. I tried it and it is only showing a black screen with text. I think it is suppose to show a box: "make object box 1,canvas_size,canvas_size,1"

Also, I don't want to use sparky's collision dll anyways or all the calculations to barycentric coordinates. I found a really easy and fast way to get UV coords using some basic math. My point to UV converstion is only like 5-10 lines of code. I also want to solve this one myself and then figure out which one is faster.

Thanks for the code. It will be interesting to take it apart and figure it all out.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Nov 2010 23:21
@Everyone - Anyone know the answer to my triangle problem? I heard that barycentric interpolation is what I am looking for but that is to complicated anyways. It would be faster just to use some basic math.

Login to post a reply

Server time is: 2026-07-23 13:43:20
Your offset time is: 2026-07-23 13:43:20