Quat "Height" maths question:

Blitz3D Forums/Blitz3D Programming/Quat "Height" maths question:

Damien Sturdy(Posted 2005) [#1]
Hey peeps, Me again...

I need a hand figuring this out. I've made a program to create a mesh terrain, but that meant having to use Linepick to get height values, so what ive done to speed things up (my current routine takes around a third of the time as a linepick), is create an array the size of the terrain which contains the vertex height at each point.

I need to use this array to find the height in between those locations, i have it half working, but its not as expected.

[code
1---2
¦---.¦
3---4
[/code]

I know the height of positions 1,2,3 and 4. How can i figure out the height at the location of that spot?

I have a interpolate function (val1,val2,float#[0-1]) which works perfectly.

So what im doing currently is interpolating the two X and then the Y values and returning the result, but it seems to be out quite some bit in the centre (centre=0.25 instead of 0.5?) but the height at each actual array location is correct.

I'm close, i can smell it.

So, can anyone help?


[edit]

ARGH DAMN IT. we need an Edit for the topic title...


RGR(Posted 2005) [#2]
;


Damien Sturdy(Posted 2005) [#3]
Thanks mate, they help, but its more than required..... I'll have to test it but i doubt it will be any quicker....

The information i have for instance is:

the height at (0,0),(0,1),(1,0),(1,1),

a float between 0-1 that shows where about left/right on the square i am
a float between 0-1 that shows where about forward/backward on the square i am...

I'm very very close, and im sure its something very simple

So if im near the top right corner, my values might be:

xfloat#=0.9
yfloat#=0.9


I recon ive sussed it in my head, i dont have my code here to check. I'll post that later too... :D


Stevie G(Posted 2005) [#4]
Cygnus .. not sure what Caffs version does as haven't tried it ..

May be quicker for you but ..

Assume u is the 0-1 for the x axis and v is the 0-1 for the z axis.

I do this ...

h1#=height(tx,tz)+( height(tx+1,tz)-height(tx,tz))*u 
h2#=height(tx,tz+1)+( height(tx+1,tz+1)- height(tx,tz+1))*u 
Return h1+(h2-h1) * v 


May help you .


Damien Sturdy(Posted 2005) [#5]
Stevie G, i beleive that is it.. let me use some paper and calc.exe for a few mins....


RGR(Posted 2005) [#6]
;


Damien Sturdy(Posted 2005) [#7]
"RaGR" im using it for a replacement TerrainY for my own terrain System, so it was the example... I'm affraid im not too good at describing the problem.

StevieG's code is almost exactly the same as what i figured already, only, its likely even quicker and more accurate, I cant get it to work correctly in VB, but, i cant' remember what VB's float thing is! heh.

Thanks for both of your help, Problem sorted... Hopefully :D

[edit]

Yeah! works! Thanks Steve, and RaGR, i need that snippet of yours in a side-project of mine :) thanks both!!!!


RGR(Posted 2005) [#8]
;


Damien Sturdy(Posted 2005) [#9]
Lol, I see no reason why i cant use either of the above, StevieG's seems to do exactly what i'm after, ive not actually been able to test yours as i was at work without blitz, i converted steves to VB but never had time to do yours...


Looking at the above though they should give the same results. Give me a bit and i will test them both.

If they work, you have a little function to replace your super large one :D


Damien Sturdy(Posted 2005) [#10]
Yeah, they both work, Yours is slow because its working everything out, stevies code is using the information i already have. (i have to tell your code how high a point is, so thats where its more useful later when i dont know that its always the same...)

again, cheers for your help!


Stevie G(Posted 2005) [#11]
... they both produce the same end result .. even if RaGR was using a custom terrain it will be uniform in scale on the x/z axis so storing each height and interpolating should be much faster for thousands of particles.


John Blackledge(Posted 2005) [#12]
(Hoping nobody will notice I'm hijacking this thread...) Adding to the functionality above, can anyone tell me how to work out the 'slope' (angle) of the tri
along the x axis and z axis?, so as to lay a sprite 'flat' on a possibly sloping tri?


Damien Sturdy(Posted 2005) [#13]
hmm, could use the AllignToVector command? Other than that, *looks at RaGR and Stevie*


big10p(Posted 2005) [#14]
Just average the normals of the tri's three vertices, I think. This will give you a normal/vector to align your decal sprite to.

Note that triangles that share verts have smoothed normals so this may not give you the exact result you want. If so, look in the archives for a function by sswift that calculates the true surface normal of a tri.


Stevie G(Posted 2005) [#15]
Yeah, I would store the surface normals of each quad ( as per big10p ) and then align to vector on the y axis will do the job.


RGR(Posted 2005) [#16]
;


Damien Sturdy(Posted 2005) [#17]
Not sure how to take that, but Ive been programming in blitz for quite some time, and I usually do sus these things out for myself. The occasional bit of help is good, thats what this place is great for... So, the last few days ive had some new ideas and i'm trying them out. These are the simple formula that I will learn and use in a future project.

Sometimes, you just need to see something and then you just get it. Not like I'm the annoying newbie who never listens and always goes "heh that dont work. It dont, please help!!!"..

I admitted that your code did the job, and it did it well, but i also knew for my purpose that it could be done alot quicker.

I really do apreciate any help i'm given around here, and i love to take bits of code like yours and see how it works, what does what. Pretty neat.

What exactly have I done to bug you? I mean, what was so bad you felt the need to remove your posts?


RGR(Posted 2005) [#18]
;


Damien Sturdy(Posted 2005) [#19]
Sorry for waisting your time, I havent actually had more than 10 mins time to program since i'm at work right now.
One last thing, i did see why you did that, hence the two pieces of code. Im just horrible at explaining things!


You are right though, and in fact, i should close this window now and actually do something. (just Realised how much i've posted....)


RGR(Posted 2005) [#20]
;