My problem is this --

Blitz3D Forums/Blitz3D Programming/My problem is this --

Jack(Posted 2005) [#1]
Here is what I need to get done.

Somehow I need to be able to configure some verts to exacting spots on a terrain - which is a mesh - not a standard terain.

I have been doing this in Milkshape and it works just fine except that it takes FOREVER on a large mesh.On top of which there are places I want a really smooth curve and this is VERY hard to do moving vertices by hand in MS.

I'm guessing that if I knew more math I could write my own code in BB to do the job but I am lacking that skill.

So I have 4 questions.

1.What is the best way to choose the number of the closest vert to a spot on which I clicked the mouse?
2.How would I get the numbers of the surrounding verts so that I could move them in code?
3.Is there some code or maths somewhere to get me started on this type project?
4.Who wants to comment on the difficulty of doing this in Blitz.

Hope this makes some kind of sense...............


big10p(Posted 2005) [#2]
You can use PickedTiangle() and then TriangleVertex() to access a specific vert attached to the triangle you've picked. You will probably then have to find the distance from the picked point to each vert, using Pythag. The shortest distance is then the vert you want.

BTW, this may be of some interest:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1008

As for creating smooth curves, you could always write a mesh terrain generator that uses a heightmap, just like blitz terrains do.

To solve the problem using math, I'm sure someone else here has already done this kind of thing and will come along and give the details, shortly. :)


Jack(Posted 2005) [#3]
Thanks for the reply.
Downloaded the link and will start to try to understand what it is doing.


big10p(Posted 2005) [#4]
OK, I should have said that the demo doesn't actually use the PickedTriangle/TriangleVertex method I mentioned. :)
Rather, it works by attaching a 3D point 'handle' to each vert - I just thought this method might be more useful if you're writing a mesh editor.


Jack(Posted 2005) [#5]
big10p -- Thanks for writing and posting this code.

This looks like it may be a big step forward for me.I need to move the vertices in specified directions and the code was easy enough to modify to get a start on that.Since I will start with a flat surface I guess that should be easy to get in place of the sphere.Problaby will improve on any camera distortion too I guess?

Next item would be to give choices as to how big I want a circle to be in diameter and then have each vertex moved an amount to form a nice curve.Either vertical or horizontal.

Would appreciate any ideas and help you could provide.
You certainly have been a big help.Thanks.


Jack(Posted 2005) [#6]
Still looking for some more input.


big10p(Posted 2005) [#7]
Got a bit sidetracked - the motherboard in my dev machine decided to give up after months of threatening it, and my HD died in sympathy. :(

Since I will start with a flat surface I guess that should be easy to get in place of the sphere.

Well, as a start, here's a function to create a square, flat terrain mesh. :P
Function create_mesh_terrain(size%, scale#=1.0)

	mesh = CreateMesh()
	surf = CreateSurface(mesh)
	
	For z = 0 To -size Step -1
		For x = 0 To size
			AddVertex(surf,x,0,z)
		Next
	Next
	
	For z = 0 To size-1
		n = z*(size+1)
		For x = 0 To size-1
			AddTriangle(surf,n,n+1,n+size+1)		
			AddTriangle(surf,n+1,n+size+2,n+size+1)		
			n = n + 1
		Next
	Next
	
	PositionMesh mesh,-(size/2.0),0,size/2.0
	ScaleMesh mesh,scale,1,scale
	UpdateNormals mesh
	
	Return mesh
	
End Function

Unfortunately, I don't know the maths off the top of my head for creating curves - I'd have to think about that, once I've got the PC working again. TBH, I thought someone who has already done this kind of thing would have dropped in by now. Oh, well.

Problaby will improve on any camera distortion too I guess?

Sorry, you've lost me there.


Next item would be to give choices as to how big I want a circle to be in diameter and then have each vertex moved an amount to form a nice curve.Either vertical or horizontal.

What do you mean by 'vertical' and 'horizontal' curves? I was thinking you just wanted to grab a vert and pull it straight up, affecting all verts in a certain radius of it - or have I mis-understood what you want?

BTW, have you tried Wings 3D to do this? It let's you pull vertices about and affect all other verts in a certain radius, using 'magnets'.


Jack(Posted 2005) [#8]
big10p:
Thanks for the info.

You are correct.I want to pull verts up or down to make my hills,gullies,etc.That is 75% of the deal and I have used wings (don't really love it however) .Also,I would like the function to be available inside my final build.(happy to give credit).

As the other 25% I would also like to be able to move the verts on the horizontal plane.The reason is that I want very defined edges between the various textures.I have not found a way to have this anything but blocky with the squares of terrains.Currently I do this in milkshape but it just takes forever and is real difficult to get nice smooth curves,but it can be done.

My comment on the camera was in reference to your remark in your archive code of not always getting the tiny verts to show in the right spot.I had no trouble in that regard however.


Stevie G(Posted 2005) [#9]
Jack,

A long time ago I wrote a patchwork landscape demo in the code archives - you may want to take a look at that. The random landscape is created by extruding heights based on cos/sin functions within a specified radius.

However, for a much better effect you want to look at bezier patches. With these you can get a nice undulating landscape using relatively few control points.

I have done this successfully but only interpolate on the Y axis. I kept the x/z step values uniform for simlicity. E-mail me if you want to see some code.

Stevie


Jack(Posted 2005) [#10]
Thanks Stevie G.
Appreciate it.
Bezier patches but never thought it possible to use in Blitz.
I got a copy of the code but how do I get your e-mail?
Doesn't show in your profile.


Stevie G(Posted 2005) [#11]
stevie@...


Jack(Posted 2005) [#12]
Thanks Stevie.

Looks real good but does make me realize how little I know.

I have gone through a number of runs changing values etc.

You don't seem to be using the data statements but I assume that will work.I would be able to create a file,I would think,that would import locations based upon "pick" I made with your other code.Then I guess locations & sizes of height variations could be given
chosen values.(somehow).

That sure solves the vertical stuff.If I have a reasonable grasp on things.

I'll work on that and then hope to tackle the X direction changes after that.

No way I could have moved along like this without your help<Thanks.

By the way - I will look forward to any further input.