Vertice Aligning:

Blitz3D Forums/Blitz3D Programming/Vertice Aligning:

Damien Sturdy(Posted 2004) [#1]
Hey you guys...

I have a problem...


I have a triangle with two of the three vertices below a certain level, (y<10)

What i need to do is move the two vertices under the minimum value UP so they sit at that value.

Its not as simple as just raising the vertexY because this deforms the mesh, the vertices must follow the edge of the triange.


I realy dont know of any better way to explain it! heh...

Can anyone help here? it would help me out greatly...


Cheers!!!


big10p(Posted 2004) [#2]
This seems to work - assuming I understand what you're asking for. :)

	Graphics3D 800,600,32
	SetBuffer BackBuffer()

	piv = CreatePivot()
	cam = CreateCamera(piv)
	PositionEntity cam,0,0,-15
	
	light = CreateLight()

	min_y# = .5 ; Minimum Y level all verts must reach.
	
	;Single triangle mesh (v1 & v2 are 'bad' verts i.e. are below min_y).
	mesh = CreateMesh()
	surf = CreateSurface(mesh)
	v0 = AddVertex(surf,0,min_y+3,10)
	v1 = AddVertex(surf,7,-5,-3)
	v2 = AddVertex(surf,-2,-8,0)
	AddTriangle(surf,v0,v1,v2)
	EntityFX mesh,16
	UpdateNormals mesh
		
	; Plane to show min_y level.
	level = CreateCube()
	ScaleMesh level,10,.01,10
	EntityColor level,0,0,200
	EntityAlpha level,.5
	PositionEntity level,0,min_y,0
	
	; Main loop
	While Not KeyHit(1)

		If KeyHit(57)
			; Update the 2 'bad' verts (v1 & v2) to reach min_y.
			min_y_dist# = VertexY(surf,v0)-min_y
			
			;v1
			xv# = VertexX(surf,v1)-VertexX(surf,v0)
			yv# = VertexY(surf,v1)-VertexY(surf,v0)
			zv# = VertexZ(surf,v1)-VertexZ(surf,v0)
			y_dist# = VertexY(surf,v0)-VertexY(surf,v1)
			side# = 1.0/y_dist
			ratio# = min_y_dist*side
			VertexCoords surf,v1,VertexX(surf,v0)+xv*ratio,VertexY(surf,v0)+yv*ratio,VertexZ(surf,v0)+zv*ratio
		
			;v2
			xv# = VertexX(surf,v2)-VertexX(surf,v0)
			yv# = VertexY(surf,v2)-VertexY(surf,v0)
			zv# = VertexZ(surf,v2)-VertexZ(surf,v0)
			y_dist# = VertexY(surf,v0)-VertexY(surf,v2)
			side# = 1.0/y_dist
			ratio# = min_y_dist*side
			VertexCoords surf,v2,VertexX(surf,v0)+xv*ratio,VertexY(surf,v0)+yv*ratio,VertexZ(surf,v0)+zv*ratio		
		EndIf

		TurnEntity piv,0,1,0

		RenderWorld
		
		Text 10,10,"Press SPACE to correct verts below minimum Y"
		
		Flip(1)
	Wend

	End



Damien Sturdy(Posted 2004) [#3]
thats it EXACTLY! Cheers :D


big10p(Posted 2004) [#4]
No worries. Doing that has actually given me an idea of how to achieve a mesh effect I've seen done in a game and wondered how they did it. Hmmm, I might give it a go. :)


Damien Sturdy(Posted 2004) [#5]
nice! I was going to use it to create a REAL mirror in blitz.. in theory it works, but practically, it failed bigtime. Until i learn more, i cant do it.

What it was going to do:
All entire triangles below Min_y are removed
all triangles with at least one vertice above Min_y are cropped to min_y (which is where your above function came into it)... Then, when this is complete, create a copy of the mesh below min_y which is flipped in the Y direction.. a plane is then placed at min_y and is returned from the function.
the mirrored mesh is child to the plane


Problem now is:

some triangles share vertices... which means it ends up distorting rather than working proberly.. Shame

Dont suppose you have an idea on a fix for that?


Cheers again mate


big10p(Posted 2004) [#6]
I think the only way around this is to build the mirror mesh using separate tris. This will up the vert count somewhat but I really can't see another way around the prob, ATM. Especially when clipping tris that only have a single vert below the minimum Y as you then have to build a quad. e.g.

;       |-------/
;       |      /
;       |     /
;       |    /
; ------|---/------- min Y
;       |  /
;       | /
;       |/


This is something I'd need to do for the mesh effect I mentioned, also - and then there's the UVs to consider :/

Not sure how fast all this would end up being but I think it's worth a go just for experimental reasons. :)


Damien Sturdy(Posted 2004) [#7]
i sorted the single vert thing,, the problem is that two triangles sometimes share the same vert.... i am already building a seperate mesh....

Difficult one, heh? it will be worth it if/when sorted out!

cheers again