This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i know how to pick a trianlge fine and can identify which triangle and where exactly the ray hits but i have a new situation. I want to pick a triangle as usual but then get the quad that triangle belongs to. So i get a square. ------- |\#|\ | |*\| \| ------- |\ |\ | | \| \| ------- * is the point i pick with the ray. I need to find the triangle # also to store so i can pait them both with a new texture. Eventually i will change this but i hope i can do it this way for now.

##### Share on other sites
I don't think it's anything related to math. Rather the underlying data structure.
For example, I hold my triangles in an array (actually, only vertices, but that's the same), so I know, that the two triangles are next to each other. All I have to know is if the triangle has odd/even index in the array. Since you know one of your triangles, it seems no prob.

Or did I misunderstand your question?

##### Share on other sites
You basically want to find a triangle sharing an edge with the triangle you pick up so that you can combine them into a quad. The problem is, the triangle sharing wich edge? There are way too many possible solutions to be able to help without a more broad view of the problem you are trying to solve.

Do you triangulate the mesh yourself from a quad representation? Does it matter that the quad be planar and if yes, what will you do when all you can find is a triangle that would result in a non-planar quad... Do you have to support polygon soup?

##### Share on other sites
sorry the everything is in direct x mesh files. I use the dx intersect function to get which index the triangle is.

And they can be as twisted as they want i just want to paint the whole square not just one triangle with a new texture.

##### Share on other sites
Quote:
 Original post by TAlchemistsorry the everything is in direct x mesh files.[...]And they can be as twisted as they want i just want to paint the whole square not just one triangle with a new texture.

If you assume each triangle has exactly one twin-triangle (if not, this task would be unsolvable), then it's not so twisted ;)

You got a structure, that you know something about, and then willingly pack it into a mesh (.x) file, that you know less about. It's like casting a derived class to a base one - you loose some info.

We obviously don't have the whole picture here, but I'll risk an oppinion anyway - drop X-files, as you need more complicated and specialized functionality.

##### Share on other sites
Quote:
 Original post by TAlchemistsorry the everything is in direct x mesh files. I use the dx intersect function to get which index the triangle is. And they can be as twisted as they want i just want to paint the whole square not just one triangle with a new texture.

So this is for a 3d paint program?

If yes, unless you have very good reasons not to use the usual approach, I suggest you to simply have your artists UVmap their objects and from there work your way from the intersection point to the correct UV in the correct texture (if more than one texture on a mesh).

Another very generic solution if you really want to have one quad = one texture would be to simply assign half a texture to a triangle on any basis you wish (for example on the first hit). This is going to be extremely wasteful however.

##### Share on other sites
The map is a regualr field of quads that was made into triangles then exported into a direct x file. They are uniform and mathcing each other in each quad.

The reason is to allow the player to go into the world and hit a button when standing in a triangle to claim the quad he is standing in. It then gets a texture of bare earth and he can then work the soil and farm. I am simulating a farming game to test ai, scripting, changing the world, and basic game mechanics.

So i want a player to be able to select his location as a ray down to the ground to choose the triangle he is on < done > then get the matching triangle in that quad to create a new object that will overdraw the regualr terrain so he can farm it. You get as many quads to farm as you have levels in Farming Skill if you care to know.

This will allow me to build a farm field, then add structures like houses, barns, grain bins, and eventually hire workers < ai testing > to tend the fields/harvest/plant and allow random events <scripts> and monster/animal attacks.

so it could be like this
-------
|\#|\ |
|*\| \|
-------
|\ |\ |
| \| \|
-------

or

-------
|\#| /|
|*\|/ |
-------
|\ |\ |
| \| \|
-------

but still matched pairs.

##### Share on other sites
If all quads lie on a simple plane, there's no need to use .x mesh at all. Manual ray-casting is a piece of cake then.
But if it's a regular height-field, then it's somewhat complex (I know, as I was writing it myself for my heightfield) and you probably would want to avoid coding it.

Let's assume you are holding the heightfield data in a 2D array (and in the mesh). You pick a triangle. If all those quads are regular, you could quite easily find out, which of the picked-triangle's vertices is the Bottom-Left one (as in your drawings). Based on XZ coords of the vertex, you can get the proper index in the 2D array. From the array, you simply get the whole quad.

I'm doing something similar, to find terrain normal in a given point.

(*I'm still against using X-files in this case.*)

##### Share on other sites
well i am using it for now and am working on getting a satisfactory heightmapped version working but will leave it be for now. The meshes are just easy to load with default code, are self contained, and simple to use.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633328
• Total Posts
3011379
• ### Who's Online (See full list)

There are no registered users currently online

×