Opened 14 years ago

Closed 14 years ago

#554 closed defect (fixed)

camera should be always inside the terrain

Reported by: Sergey Owned by: Sergey
Priority: Nice to Have Milestone: Alpha 1
Component: Core engine Keywords: camera terrain screen
Cc: Jay Weisskopf Patch:

Description

When camera is being moved either by mouse or by keyboard it can be placed outside the terrain, so that the user will see only a black ambient. The right camera handling should never move its position outside the terrain.

Attachments (1)

cameraConstraints.diff (6.7 KB ) - added by Sergey 14 years ago.
previous diff was broken

Download all attachments as: .zip

Change History (10)

comment:1 by Sergey, 14 years ago

I'm doing the task. Additional description you may find starting from http://www.wildfiregames.com/forum/index.php?s=&showtopic=13292&view=findpost&p=209678 that post

comment:2 by Jay Weisskopf, 14 years ago

Cc: Jay Weisskopf added

comment:3 by Jay Weisskopf, 14 years ago

Keywords: review added

comment:4 by Philip Taylor, 14 years ago

Keywords: review removed

Thanks, this'd be a good thing to get fixed.

With this patch, the movement at the edge of the screen seems to be a bit jerky. If I try a map like Arcadia and push the camera towards an edge then it wobbles backwards and forwards a bit; if I slide along the edge then sometimes it jumps a long way back into the map, particularly around rivers and mountains. I can also get it stuck outside the margin when scrolling off the side of a hill.

I guess this might be inevitable when using the camera's pivot point, since that jumps around a lot when scrolling over height variations, so perhaps it's better to avoid using that. Maybe use just the position of the camera itself, or a point that's a constant m->ViewZoomDefault in front of the camera, and restrict that to the map area (plus margin), to get something that hopefully looks alright and avoids this jerkiness. (Testing might show this isn't a better idea, though. But there must be something that works alright.)

The camera movement stops very suddenly at the edge - clamping of m->PosX etc should probably be done with ClampSmoothly instead.

GetEdgeNearestPoint and the new argument on GetFocus don't seem to be used anywhere.

comment:5 by Sergey, 14 years ago

ok, I'll try m->ViewZoomDefault.

Speaking of the camera position itself doesn't seem to me a good idea since I don't really know where camera looks. Strictly, it can be outside the terrain, but it's ray will hit the terrain (it's more obvious when camera is slanted with a sharp angle to the terrain's plane).

When you say "I can also get it stuck outside the margin when scrolling off the side of a hill." do you mean that you can't move the camera at all (only by mini map), or it just gets fixed by the one axis without wobbling any more, but you can move it by another axis?

I can't understand how the camera can jump "a long way back into the map", until you are speaking about quite short distances (not a half or quarter map). Implementing margins seemed to be the only way to prevent camera go outside. First I tried to use original edge points (that's why you see GetEdgeNearestPoint), but if the pivot hits outside, the vector returned by CCamera::GetFocus is somehow broken (you can't decide anything by that vector). The second thing I implemented was the new parameter to CCamera::GetFocus method (bool *is_on_map) which goes false when pivot is outside the terrain. That didn't give me anything good too, since I wasn't sure where actually the pivot intersects the terrain. So, after the long way, I came up to the idea of using margins. The thing is that the margin should be big enough to be sure that pivot will be always inside.

I tried Arcadia (it was the first map I tried my code on). If the camera is in its initial state and you move it north, then to the east, where the river is located, you'll see that pivot skirts the river. Moving the camera further to the east along the edge leads you to the hill where it goes norther and holds its z position paying no attention on moving by x position until you move it a bit souther when it will continue skirting the edges.

Strictly, using the camera behavior implemented by me is not smooth (camera is jerky), but understandable, because it jerks only when landscape changes. Take the next map, where the terrain at the edges are fixed height ("Bad lands" if I can recall the name correctly) you'll see that there is no wobbling at all.

So, you want me to check and try to implement the behavior so that it is never wobbles?

comment:6 by Sergey, 14 years ago

GetEdgeNearestPoint and the new argument on GetFocus don't seem to be used anywhere.

I thought it should be interesting by some point, but it's not used in my patch, as you have already mentioned. I can delete that stuff if you want.

by Sergey, 14 years ago

Attachment: cameraConstraints.diff added

previous diff was broken

comment:7 by Sergey, 14 years ago

Philip, thank you a lot for your help. Changing 752 line in GameView.cpp from targetCam->GetFocus() to targetCam.m_Orientation.GetTranslation() + targetCam.m_Orientation.GetIn() * m->ViewZoomDefault; solved the wobbling problem.

Please, check it now.

comment:8 by Philip Taylor, 14 years ago

Thanks! Looks much better now, I think. The only thing I'd like to change is to use ClampSmoothly so that it doesn't stop so suddenly at the edges - all the rest of the camera movement is intended to be smoothed, and I'd prefer to be consistent here. So I've made that change, and rearranged the code so it gets called at the right time (the smoothing means it needs to be done before the Pos.Update() calls), and it looks like it still works. Also I removed the unused functions (better to avoid adding complexity until it's really needed) and made the code style a bit more consistent with the surrounding code.

comment:9 by philip, 14 years ago

Resolution: fixed
Status: newclosed

(In [8070]) Fix #554 (camera should be always inside the terrain), based on patch from markelov

Note: See TracTickets for help on using tickets.