help, my demo has bad-earthquake syndrome

Started by
18 comments, last by fireking 20 years, 5 months ago
haha, i''ve been actually trying to implement what you said, hmmm...
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Advertisement
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
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
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.
2 + 2 = 5 for extremely large values of 2
just a tip learn to use radians instead of converting from degrees to radians.

It makes your code clearer to read. After a while you will realise how silly using degrees is.
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]
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...
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
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)

die or be died...i think
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,
die or be died...i think
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...
die or be died...i think
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

This topic is closed to new replies.

Advertisement