GameView: removed unused ancient camera code.
Terrain: nicer handling of negative map coordinates (mainly for Atlas brush previews that fall over the edge). Misc: reverted seconds->microseconds. This was SVN commit r2866.
This commit is contained in:
parent
04650efe7a
commit
29d6f420fd
@ -331,9 +331,6 @@ void CGameView::Update(float DeltaTime)
|
||||
m_Camera.m_Orientation.Translate( m_CameraDelta * ( 1.0f - delta ) );
|
||||
m_CameraDelta *= delta;
|
||||
|
||||
#define CAMERASTYLE 2 // 0 = old style, 1 = relatively new style, 2 = newest style
|
||||
|
||||
// #if CAMERASTYLE == 2
|
||||
|
||||
// This could be rewritten much more reliably, so it doesn't e.g. accidentally tilt
|
||||
// the camera, assuming we know exactly what limits the camera should have.
|
||||
@ -543,122 +540,6 @@ void CGameView::Update(float DeltaTime)
|
||||
m_ZoomDelta *= zoom_proportion;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Just commented out to make it more obvious it's not in use.
|
||||
|
||||
#elif CAMERASTYLE == 1
|
||||
|
||||
// Remember previous mouse position, to calculate changes
|
||||
static mouse_last_x = 0;
|
||||
static mouse_last_y = 0;
|
||||
|
||||
// Miscellaneous vectors
|
||||
CVector3D forwards = m_Camera.m_Orientation.GetIn();
|
||||
CVector3D upwards (0.0f, 1.0f, 0.0f);
|
||||
CVector3D rightwards = upwards.Cross(forwards);
|
||||
|
||||
// Click and drag to look around
|
||||
if (mouse_buttons[0])
|
||||
{
|
||||
// Untranslate the camera, so it rotates around the correct point
|
||||
CVector3D position = m_Camera.m_Orientation.GetTranslation();
|
||||
m_Camera.m_Orientation.Translate(position*-1);
|
||||
|
||||
// Sideways rotation
|
||||
m_Camera.m_Orientation.RotateY(m_ViewRotateSpeed*(float)(g_mouse_x-mouse_last_x));
|
||||
|
||||
// Up/down rotation
|
||||
CQuaternion temp;
|
||||
temp.FromAxisAngle(rightwards, m_ViewRotateSpeed*(float)(g_mouse_y-mouse_last_y));
|
||||
m_Camera.m_Orientation.Rotate(temp);
|
||||
|
||||
// Retranslate back to the right position
|
||||
m_Camera.m_Orientation.Translate(position);
|
||||
}
|
||||
mouse_last_x = g_mouse_x;
|
||||
mouse_last_y = g_mouse_y;
|
||||
|
||||
// Calculate the necessary vectors for movement
|
||||
|
||||
rightwards.Normalize();
|
||||
CVector3D forwards_horizontal = upwards.Cross(rightwards);
|
||||
forwards_horizontal.Normalize();
|
||||
|
||||
// Move when desirable
|
||||
|
||||
if (g_mouse_x >= g_xres-2)
|
||||
m_Camera.m_Orientation.Translate(rightwards);
|
||||
else if (g_mouse_x <= 3)
|
||||
m_Camera.m_Orientation.Translate(-rightwards);
|
||||
|
||||
if (g_mouse_y >= g_yres-2)
|
||||
m_Camera.m_Orientation.Translate(forwards_horizontal);
|
||||
else if (g_mouse_y <= 3)
|
||||
m_Camera.m_Orientation.Translate(-forwards_horizontal);
|
||||
|
||||
// Smoothed height-changing (move a certain percentage towards the desired height every frame)
|
||||
|
||||
static float height_delta = 0.0f;
|
||||
|
||||
if (mouse_buttons[SDL_BUTTON_WHEELUP])
|
||||
height_delta -= 4.0f;
|
||||
else if (mouse_buttons[SDL_BUTTON_WHEELDOWN])
|
||||
height_delta += 4.0f;
|
||||
|
||||
const float height_speed = 0.2f;
|
||||
m_Camera.m_Orientation.Translate(0.0f, height_delta*height_speed, 0.0f);
|
||||
height_delta *= (1.0f - height_speed);
|
||||
|
||||
#else // CAMERASTYLE == 0
|
||||
|
||||
const float dx = m_ViewScrollSpeed * DeltaTime;
|
||||
const CVector3D Right(dx,0, dx);
|
||||
const CVector3D Up (dx,0,-dx);
|
||||
|
||||
if (g_mouse_x >= g_xres-2)
|
||||
m_Camera.m_Orientation.Translate(Right);
|
||||
if (g_mouse_x <= 3)
|
||||
m_Camera.m_Orientation.Translate(Right*-1);
|
||||
|
||||
if (g_mouse_y >= g_yres-2)
|
||||
m_Camera.m_Orientation.Translate(Up);
|
||||
if (g_mouse_y <= 3)
|
||||
m_Camera.m_Orientation.Translate(Up*-1);
|
||||
|
||||
|
||||
// janwas: grr, plotted the zoom vector on paper twice, but it appears
|
||||
// to be completely wrong. sticking with the FOV hack for now.
|
||||
// if anyone sees what's wrong, or knows how to correctly implement zoom,
|
||||
// please put this code out of its misery :)
|
||||
|
||||
// RC - added ScEd style zoom in and out (actually moving camera, rather than fudging fov)
|
||||
|
||||
float dir=0;
|
||||
if (mouse_buttons[SDL_BUTTON_WHEELUP]) dir=-1;
|
||||
else if (mouse_buttons[SDL_BUTTON_WHEELDOWN]) dir=1;
|
||||
|
||||
float factor=dir*dir;
|
||||
if (factor) {
|
||||
if (dir<0) factor=-factor;
|
||||
CVector3D forward=m_Camera.m_Orientation.GetIn();
|
||||
|
||||
// check we're not going to zoom into the terrain, or too far out into space
|
||||
float h=m_Camera.m_Orientation.GetTranslation().Y+forward.Y*factor*m_Camera.Zoom;
|
||||
float minh=65536*HEIGHT_SCALE*1.05f;
|
||||
|
||||
if (h<minh || h>1500) {
|
||||
// yup, we will; don't move anywhere (do clamped move instead, at some point)
|
||||
} else {
|
||||
// do a full move
|
||||
m_Camera.Zoom-=(factor)*0.1f;
|
||||
if (m_Camera.Zoom<0.01f) m_Camera.Zoom=0.01f;
|
||||
m_Camera.m_Orientation.Translate(forward*(factor*m_Camera.Zoom));
|
||||
}
|
||||
}
|
||||
#endif // CAMERASTYLE
|
||||
*/
|
||||
|
||||
m_Camera.UpdateFrustum ();
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ int CMapReader::UnpackTerrain()
|
||||
// unpack map size
|
||||
unpacker.UnpackRaw(&m_MapSize, sizeof(m_MapSize));
|
||||
|
||||
// unpack heightmap [600s]
|
||||
// unpack heightmap [600us]
|
||||
u32 verticesPerSide = m_MapSize*PATCH_SIZE+1;
|
||||
m_Heightmap.resize(SQR(verticesPerSide));
|
||||
unpacker.UnpackRaw(&m_Heightmap[0], SQR(verticesPerSide)*sizeof(u16));
|
||||
|
@ -72,9 +72,13 @@ bool CTerrain::Initialize(u32 size,const u16* data)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CalcPosition: calculate the world space position of the vertex at (i,j)
|
||||
void CTerrain::CalcPosition(u32 i,u32 j,CVector3D& pos)
|
||||
void CTerrain::CalcPosition(i32 i, i32 j, CVector3D& pos)
|
||||
{
|
||||
u16 height=m_Heightmap[j*m_MapSize + i];
|
||||
u16 height;
|
||||
if ((u32)i < m_MapSize && (u32)j < m_MapSize) // will reject negative coordinates
|
||||
height = m_Heightmap[j*m_MapSize + i];
|
||||
else
|
||||
height = 0;
|
||||
pos.X = float(i)*CELL_SIZE;
|
||||
pos.Y = float(height)*HEIGHT_SCALE;
|
||||
pos.Z = float(j)*CELL_SIZE;
|
||||
@ -83,15 +87,10 @@ void CTerrain::CalcPosition(u32 i,u32 j,CVector3D& pos)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CalcFromPosition: calculate the vertex underneath the world space position
|
||||
void CTerrain::CalcFromPosition(CVector3D& pos, u32& i, u32& j)
|
||||
void CTerrain::CalcFromPosition(const CVector3D& pos, i32& i, i32& j)
|
||||
{
|
||||
float x = pos.X / CELL_SIZE;
|
||||
float z = pos.Z / CELL_SIZE;
|
||||
|
||||
debug_assert(x >= 0 && z >= 0);
|
||||
|
||||
i = (u32)x;
|
||||
j = (u32)z;
|
||||
i = pos.X / CELL_SIZE;
|
||||
j = pos.Z / CELL_SIZE;
|
||||
}
|
||||
|
||||
|
||||
@ -145,10 +144,10 @@ void CTerrain::CalcNormal(u32 i,u32 j,CVector3D& normal)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GetPatch: return the patch at (x,z) in patch space, or null if the patch is
|
||||
// out of bounds
|
||||
CPatch* CTerrain::GetPatch(int32_t x,int32_t z)
|
||||
CPatch* CTerrain::GetPatch(i32 x, i32 z)
|
||||
{
|
||||
if (x<0 || x>=int32_t(m_MapSizePatches)) return 0;
|
||||
if (z<0 || z>=int32_t(m_MapSizePatches)) return 0;
|
||||
if (x<0 || x>=i32(m_MapSizePatches)) return 0;
|
||||
if (z<0 || z>=i32(m_MapSizePatches)) return 0;
|
||||
return &m_Patches[(z*m_MapSizePatches)+x];
|
||||
}
|
||||
|
||||
@ -156,10 +155,10 @@ CPatch* CTerrain::GetPatch(int32_t x,int32_t z)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GetPatch: return the tile at (x,z) in tile space, or null if the tile is out
|
||||
// of bounds
|
||||
CMiniPatch* CTerrain::GetTile(int32_t x,int32_t z)
|
||||
CMiniPatch* CTerrain::GetTile(i32 x, i32 z)
|
||||
{
|
||||
if (x<0 || x>=int32_t(m_MapSize)-1) return 0;
|
||||
if (z<0 || z>=int32_t(m_MapSize)-1) return 0;
|
||||
if (x<0 || x>=i32(m_MapSize)-1) return 0;
|
||||
if (z<0 || z>=i32(m_MapSize)-1) return 0;
|
||||
|
||||
CPatch* patch=GetPatch(x/PATCH_SIZE,z/PATCH_SIZE);
|
||||
return &patch->m_MiniPatches[z%PATCH_SIZE][x%PATCH_SIZE];
|
||||
@ -179,18 +178,20 @@ float CTerrain::getExactGroundLevel( float x, float y ) const
|
||||
{
|
||||
xi = 0; xf = 0.0f;
|
||||
}
|
||||
if( xi >= (int)m_MapSize )
|
||||
else if (xi >= (int)m_MapSize)
|
||||
{
|
||||
xi = m_MapSize - 1; xf = 1.0f;
|
||||
}
|
||||
|
||||
if (yi < 0)
|
||||
{
|
||||
yi = 0; yf = 0.0f;
|
||||
}
|
||||
if( yi >= (int)m_MapSize )
|
||||
else if (yi >= (int)m_MapSize)
|
||||
{
|
||||
yi = m_MapSize - 1; yf = 1.0f;
|
||||
}
|
||||
|
||||
/*
|
||||
debug_assert( isOnMap( x, y ) );
|
||||
|
||||
@ -202,7 +203,9 @@ float CTerrain::getExactGroundLevel( float x, float y ) const
|
||||
float h01 = m_Heightmap[yi*m_MapSize + xi + m_MapSize];
|
||||
float h10 = m_Heightmap[yi*m_MapSize + xi + 1];
|
||||
float h11 = m_Heightmap[yi*m_MapSize + xi + m_MapSize + 1];
|
||||
return( HEIGHT_SCALE * ( ( 1 - yf ) * ( ( 1 - xf ) * h00 + xf * h10 ) + yf * ( ( 1 - xf ) * h01 + xf * h11 ) ) );
|
||||
return (HEIGHT_SCALE * (
|
||||
(1 - yf) * ((1 - xf) * h00 + xf * h10)
|
||||
+ yf * ((1 - xf) * h01 + xf * h11)));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -51,15 +51,15 @@ public:
|
||||
|
||||
// get patch at given coordinates, expressed in patch-space; return 0 if
|
||||
// coordinates represent patch off the edge of the map
|
||||
CPatch* GetPatch(int32_t x,int32_t z);
|
||||
CPatch* GetPatch(i32 x, i32 z);
|
||||
// get tile at given coordinates, expressed in tile-space; return 0 if
|
||||
// coordinates represent tile off the edge of the map
|
||||
CMiniPatch* GetTile(int32_t x,int32_t z);
|
||||
CMiniPatch* GetTile(i32 x, i32 z);
|
||||
|
||||
// calculate the position of a given vertex
|
||||
void CalcPosition(u32 i,u32 j, CVector3D& pos);
|
||||
void CalcPosition(i32 i, i32 j, CVector3D& pos);
|
||||
// calculate the vertex under a given position (rounding down coordinates)
|
||||
void CalcFromPosition(CVector3D& pos, u32& i, u32& j);
|
||||
void CalcFromPosition(const CVector3D& pos, i32& i, i32& j);
|
||||
// calculate the normal at a given vertex
|
||||
void CalcNormal(u32 i, u32 j, CVector3D& normal);
|
||||
|
||||
|
@ -222,7 +222,7 @@ const size_t DBG_FILE_LEN = 100;
|
||||
// retrieved and stored.
|
||||
// sym_name and file must hold at least the number of chars above;
|
||||
// file is the base name only, not path (see rationale in wdbg_sym).
|
||||
// the PDB implementation is rather slow (~500s).
|
||||
// the PDB implementation is rather slow (~500us).
|
||||
extern int debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file, int* line);
|
||||
|
||||
// write a complete stack trace (including values of local variables) into
|
||||
|
@ -31,7 +31,7 @@ void Brush::GetBottomRight(int& x, int& y) const
|
||||
if (m_W % 2) c.X += CELL_SIZE/2.f;
|
||||
if (m_H % 2) c.Z += CELL_SIZE/2.f;
|
||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
|
||||
u32 cx, cy;
|
||||
i32 cx, cy;
|
||||
terrain->CalcFromPosition(c, cx, cy);
|
||||
|
||||
x = cx - (m_W-1)/2;
|
||||
@ -66,6 +66,7 @@ void Brush::Render()
|
||||
CVector3D pos;
|
||||
terrain->CalcPosition(x0+dx, y0+dy, pos);
|
||||
glVertex3f(pos.X, pos.Y, pos.Z);
|
||||
//debug_printf("%f %f %f\n", pos.X, pos.Y, pos.Z);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user