Devide a Triangle

Blitz3D Forums/Blitz3D Programming/Devide a Triangle

Abomination(Posted 2004) [#1]
Okay... I want to devide a triangle in to 3 seperate ones.
I create 3 vertices:
LD=AddVertex(SURF,0,A,0)
RD=AddVertex(SURF,2,B,0)
UP=AddVertex(SURF,1,C,1)
(where A,B,and C are unknown)
I calculate a point in the middle:
x=1 : z=1 : y=((a+b)/2)+c)/2
Mid= AddVertex(SURF,x,y,z)
Now I create 3 triangles each with their own set of 3 vertices, using these 4 points.
That works, except for an anoying shadow that is darkest in the middle of the 3 triangles.
Is this because of an error in my calculation, or a side-effect or something?
I can't seem to figure this out, so some help is much appreciated...


big10p(Posted 2004) [#2]
Are you calculating your normals correctly?


Tom(Posted 2004) [#3]
Your midpoint should be an average of all 3 verts:

midx = (vx1+vx2+vx3) / 3
midy = (vy1+vy2+vy3) / 3
midz = (vz1+vz2+vz3) / 3

Delete the mesh, and recreate the old 3 verts (v1,v2,v3) and the new midpoint vert (v4) using midx,midy,midz

Then create the new tris using this vert order:

tri1 v1,v2,v4
tri2 v2,v3,v4
tri3 v3,v1,v4


Tom


Shambler(Posted 2004) [#4]
You then will need to either set the normal of this 4th point you created or use UpdateNormals() on the mesh.


Abomination(Posted 2004) [#5]
Well, I did all that...
I can't imagin it to be anything else than a calculation-error in my code,But after calculating the triangles in a grid and then deviding them, the only thing I do with them is scaling the Z-vectors down by multiplying them with 0.015625.
The Pic below shows ( more or less)what I'm talking about.
[edit:] replaced the pic.


[edit:]
after recreating the mesh I use UpdateNormals().

I was also wondering (if I would calculate the normals by hand :) wether I could Use the normals of the origial triangle and impose them on the newones somehow, since the 3 of them ar all in the same plane anyway...


Shambler(Posted 2004) [#6]
Take the normals of the 3 points and average them. Use this value for the normal of your 4th point.


Abomination(Posted 2004) [#7]
Well... I'm about to give up on this.
I've tried to make my own code to update the normals,(using Shamblers suggestion of calculating the 4th normal) but now it seems as if the original triangle (simmulated by the 3 replacements) is too bright, too dark, or the shade dont fade correctly?
(by the way: none of the triangles share any vertices with each other)
I'm new to this "Normals" thing so perhaps I should prize myself lucky to get any picture at all.
Anyway...

[edit: removed some pics.]

result with my own code to update the normals.



Abomination(Posted 2004) [#8]
[edit: removed a bunch of B.S. here. I just hope that nobody has read it before I wiped it ;)]
I will try (another) alternative aproach.
If it works, I will let You know.
I still would like to know why UpdateNormals()did not do the trick though.


AbbaRue(Posted 2004) [#9]
I don't understand why you are using different shades of gray there.
But I would think, if you used a texture on the new formed surface, the texture would take care of itself.
I think your problem is with the UV values of your texture.
Are you setting the UV values for the mesh?
What I see looks like something I was getting because I didn't have the UV set right.
I had a grass texture made of random shades of green, and when I used it on my mesh
all I got was a green smear, something like the gray images you show us.
I then set the UV for the mesh and got a nice random grass field look.


Abomination(Posted 2004) [#10]
Thanks for the remarks AbbaRue; but I use a pure white texture here.(for testing this phenomena)The different shades of gray are supposed to be shadows. Updatenormals()results in the upper picture and my own code in the lower.
What I was expecting to see, was smooth fading indications of difference in height. Not these diamond-shaped structures.
I want to use the extra triangles for transitions of different textures.

[edit:]
more pics ;p

original triangles...


Devided triangles...



Abomination(Posted 2004) [#11]
Huray!
I solved it.
Lets say A=top of triangle, B=leftdown and C=RightDown
The x- and z-vectors are fixed, so I calculate the y-vector of the vertice in the middle like this:
Dy=(((By+Cy)/2)+Ay)/2
This way the uv-coordinates of the middle vertice lay exactly in the middle of the texture.
But I calculated its normal like this:
Dn=(An+Bn+Cn)/3.0 (because Shambler told me to ;) HA!
Now I do:
Dn=(((Bn+Cn)/2)+An)/2
Problem fixed!