Archived

This topic is now archived and is closed to further replies.

help, my demo has bad-earthquake syndrome

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok finally, i have 3rd person camera up and running (kind of), and now when i walk across my terrain, i experience a rather yucky earthquake... here''s how everything is being calculated: Get Height at current point and set the model''s height to that number (so that the model is standing on the terrain) g_3DModel.Position.y=(Height(g_HeightMap,g_3DModel.Position.x/SCALE,g_3DModel.Position.z/SCALE)*(SCALE*HEIGHT_RATIO))+35; right now, Scale is 10, height Ratio is 1.2, and 35 is half the height of the model (i think) anyways, everything works fine, until i start walking, in which the camera shakes up and down vigurously as if a dog was fighting for a peice of my bare ass... how do games have a 3rd person camera be so smooth? here is how i calculate the third person camera... void CCamera::SetThirdPerson(float xpos,float yrot,float zpos) { m_vPosition.x=400 * sin((yrot-90) * M_PI / 180) + xpos; m_vPosition.z=400 * cos((yrot-90) * M_PI / 180) + zpos; } xpos is passed with model''s x position, y rot is passed with model''s direction (in degrees), and zpos is passed with model''s z position.. i dont know why i had to add the -90 in there, because the 3rd person camera tutorial i read just says (yrot) instead of (yrot-90), but without it, the camera will only be on the side of the model, instead of behind it...

Share this post


Link to post
Share on other sites
those are radians, degrees converted to radian is

radian = (pie / 180) * the number in degrees that you want to convert

thats not my problem

my problem is that as you walk forward, you pass the bumps on the terrain, so the height is constantly changing and it looks like there''s an earthquake cuz the height is changing as you move foward..

i need either a better way of clinging to the terrain, or, some kind of smooth transition...

i have no clue where to start

Share this post


Link to post
Share on other sites
It looks like you are just extracting the nearest height value from the height map. What you need to do is pick the nearest 4 and interpolate the value from them so that you smoothly change height reguardless of which direction you travel.

Share this post


Link to post
Share on other sites
an example perhaps, Extrarius?

sorry, im kind of new at buildling my own engine, i''ve never had to program movement before (ive mostly used engine throughout my game development career, where movement functions are already defined and you just plug and play)

Share this post


Link to post
Share on other sites
fireking, feel free to download our latest source package, it has an example of how to do this...

http://mtrp.juntadigital.com

you want the testclient_src.zip package, and what you''re looking for is in a function called GetHeightAt() in terrainrenderer.cpp.

What you''re doing is a 2d lerp between the 4 points

Share this post


Link to post
Share on other sites
what are your sectors for (define them)? this example you''ve given me might have too much overhead for me to apply to my demo, because you got a whole crap load going on there

Share this post


Link to post
Share on other sites
pls disregard my post if you catched it fireking, i was tired and i think it might be wrong.. just don''t got enough caffine in me to think about that right now.

Share this post


Link to post
Share on other sites
for what its worth, here''s what ive tried from what you said, doesnt do much other than let me walk under water regardless of the terrain, lol...


void ClingToTerrain(BYTE *pHeightMap)
{
CVector3 PositionScaled;
PositionScaled=Position/SCALE;
float pos1x=Closest(Position.x-STEP_SIZE,STEP_SIZE)-1;
pos1x=pos1x/SCALE;
float pos1z=Closest(Position.z-STEP_SIZE,STEP_SIZE)-1;
pos1z=pos1z/SCALE;
float pos2x=Closest(Position.x+STEP_SIZE,STEP_SIZE)-1;
pos2x=pos2x/SCALE;
float pos2z=Closest(Position.z-STEP_SIZE,STEP_SIZE)-1;
pos2z=pos2z/SCALE;
float pos3x=Closest(Position.x+STEP_SIZE,STEP_SIZE)-1;
pos3x=pos3x/SCALE;
float pos3z=Closest(Position.z+STEP_SIZE,STEP_SIZE)-1;
pos3z=pos3z/SCALE;
float pos4x=Closest(Position.x-STEP_SIZE,STEP_SIZE)-1;
pos4x=pos4x/SCALE;
float pos4z=Closest(Position.z+STEP_SIZE,STEP_SIZE)-1;
pos4z=pos4z/SCALE;
float height1=Height(pHeightMap,pos1x,pos1z);
float height2=Height(pHeightMap,pos2x,pos2z);
float height3=Height(pHeightMap,pos3x,pos3z);
float height4=Height(pHeightMap,pos4x,pos4z);
float dist1=1/NewDistance(CVector3(pos1x,height1,pos1z),PositionScaled);
float dist2=1/NewDistance(CVector3(pos2x,height2,pos2z),PositionScaled);
float dist3=1/NewDistance(CVector3(pos3x,height3,pos3z),PositionScaled);
float dist4=1/NewDistance(CVector3(pos4x,height4,pos4z),PositionScaled);
int h=(height1*dist1)+(height2*dist2)+(height3*dist3)+(height4*dist4);
Position.y=(float)25+((h*SCALE)*HEIGHT_RATIO);
}


Closest is a function that finds the closest number to a set range stepping by parameter 2, for instance, going from 1 to 1024 stepping by 16, the function would return 49 for an input of 52

height returns the height value (0 - 255) from the terrain at the given point

NewDistance finds the real distance between to vectors, i did 1/NewDistance() to get the number between 0 and 1

Share this post


Link to post
Share on other sites
This doesn''t answer your question, but I think you should know:

You should store PI/180 as a separate constant, as it will be used fairly often (come to think of it, your compiler probably does this for you). Also, sin (deg-90) is the same as cos (deg), and the other way around.

Share this post


Link to post
Share on other sites
If your terrain is regular then you should be able to find the three points of the triangle that your character (or camera) is efectively standing on, using those three points and trig you can efectively calculate the exact height of the terrain, I came up with this way of doing it for my game, if it is slower than interpolation between 4 points it's not by much and the results are more dependable and look nicer. It's done by finding the triangle that your standing on, then you efectively draw a line from one vertex to the opposite side depending on where in the triangle the character is, and then you can find the height on this line based on a ratio to distance. It's kinda hard to explain in text form here without drawing it. If you want actual code on this I can send it to you, write me at tenkingdomsproject@hotmail.com
~alfiare

PS you can also get auround jumpy rotation by setting a rotation amount goal and then dividing the rotational amount that you want to move each frame by something (I use 7) then subtracting the amount that you moved from the goal. EX for one frame (amount to turn goal for next frame)=(amount to turn current) - (amount to turn current)/(some constant ex:7) this will make the camera speed up when you try to turn fast and slowdown when it's getting near it's goal.

[edited by - alfiare on November 11, 2003 7:51:26 AM]

[edited by - alfiare on November 11, 2003 7:52:04 AM]

Share this post


Link to post
Share on other sites
well im not writing the engine yet, this is just a demo to see if i can even do the things im going to eventually write, so it doesnt matter if i use radians or degrees right now (and currently, degrees are easier for me to understand)

thanks to the guy that explain the -90 thing

also, @the guy that suggested the constant 7 thing and triangle thing, i wanted to avoid that, i wanna do the interpolation method (because i believe it will be smoother and faster than your method), but im still stuck on how to do it...

Share this post


Link to post
Share on other sites
quote:
Original post by alfiare
If your terrain is regular then you should be able to find the three points of the triangle that your character (or camera) is efectively standing on, using those three points and trig you can efectively calculate the exact height of the terrain, I came up with this way of doing it for my game, if it is slower than interpolation between 4 points it''s not by much and the results are more dependable and look nicer. It''s done by finding the triangle that your standing on, then you efectively draw a line from one vertex to the opposite side depending on where in the triangle the character is, and then you can find the height on this line based on a ratio to distance. It''s kinda hard to explain in text form here without drawing it. If you want actual code on this I can send it to you, write me at tenkingdomsproject@hotmail.com
~alfiare

PS you can also get auround jumpy rotation by setting a rotation amount goal and then dividing the rotational amount that you want to move each frame by something (I use 7) then subtracting the amount that you moved from the goal. EX for one frame (amount to turn goal for next frame)=(amount to turn current) - (amount to turn current)/(some constant ex:7) this will make the camera speed up when you try to turn fast and slowdown when it''s getting near it''s goal.

[edited by - alfiare on November 11, 2003 7:51:26 AM]

[edited by - alfiare on November 11, 2003 7:52:04 AM]


is D3DXVec2Lerp() any good here? assuming that your rotation is a 2d vec (angle, elevation)

Share this post


Link to post
Share on other sites
quote:
Original post by fireking
what are your sectors for (define them)? this example you''ve given me might have too much overhead for me to apply to my demo, because you got a whole crap load going on there


the idea with the sectors is that it allows me to model the *entire* surface of mars, without running myself ourt of ram.

the local objects are always only in sector (1,1) in that 3x3 array. (the client is only told about objects in its own sector)
all physics (including getHeightAt) is done on that sector, so ignore it...

->h[x][z].h is the height at a point x,z in the grid.

yeah there is a good amount of stuff happening there,

Share this post


Link to post
Share on other sites
you can simplify the code for your closest thing down a little possibly, working on the basis that (int)x is rounded down and (int)x+1 is the equivalent of rounded up.

maybe...

Share this post


Link to post
Share on other sites
quote:
Original post by Qatal
quote:
Original post by alfiare
If your terrain is regular then you should be able to find the three points of the triangle that your character (or camera) is efectively standing on, using those three points and trig you can efectively calculate the exact height of the terrain, I came up with this way of doing it for my game, if it is slower than interpolation between 4 points it''s not by much and the results are more dependable and look nicer. It''s done by finding the triangle that your standing on, then you efectively draw a line from one vertex to the opposite side depending on where in the triangle the character is, and then you can find the height on this line based on a ratio to distance. It''s kinda hard to explain in text form here without drawing it. If you want actual code on this I can send it to you, write me at tenkingdomsproject@hotmail.com
~alfiare

PS you can also get auround jumpy rotation by setting a rotation amount goal and then dividing the rotational amount that you want to move each frame by something (I use 7) then subtracting the amount that you moved from the goal. EX for one frame (amount to turn goal for next frame)=(amount to turn current) - (amount to turn current)/(some constant ex:7) this will make the camera speed up when you try to turn fast and slowdown when it''s getting near it''s goal.

[edited by - alfiare on November 11, 2003 7:51:26 AM]

[edited by - alfiare on November 11, 2003 7:52:04 AM]


is D3DXVec2Lerp() any good here? assuming that your rotation is a 2d vec (angle, elevation)




You could still use that but you don''t really need to, since you''re determining the amount of rotation using the constant anyway, or maybe I don''t understand how you want to use it...
~alfiare

Share this post


Link to post
Share on other sites