コード例 #1
0
ファイル: Texture.cpp プロジェクト: AWilco/xbmc
void CBaseTexture::ClampToEdge()
{
  unsigned int imagePitch = GetPitch(m_imageWidth);
  unsigned int imageRows = GetRows(m_imageHeight);
  unsigned int texturePitch = GetPitch(m_textureWidth);
  unsigned int textureRows = GetRows(m_textureHeight);
  if (imagePitch < texturePitch)
  {
    unsigned int blockSize = GetBlockSize();
    unsigned char *src = m_pixels + imagePitch - blockSize;
    unsigned char *dst = m_pixels;
    for (unsigned int y = 0; y < imageRows; y++)
    {
      for (unsigned int x = imagePitch; x < texturePitch; x += blockSize)
        memcpy(dst + x, src, blockSize);
      dst += texturePitch;
    }
  }

  if (imageRows < textureRows)
  {
    unsigned char *dst = m_pixels + imageRows * texturePitch;
    for (unsigned int y = imageRows; y < textureRows; y++)
    {
      memcpy(dst, dst - texturePitch, texturePitch);
      dst += texturePitch;
    }
  }
}
コード例 #2
0
ファイル: Texture.cpp プロジェクト: AWilco/xbmc
void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
{
  m_imageWidth = width;
  m_imageHeight = height;
  m_format = format;
  m_orientation = 0;

  m_textureWidth = m_imageWidth;
  m_textureHeight = m_imageHeight;

  if (m_format & XB_FMT_DXT_MASK)
    while (GetPitch() < g_Windowing.GetMinDXTPitch())
      m_textureWidth += GetBlockSize();

  if (!g_Windowing.SupportsNPOT((m_format & XB_FMT_DXT_MASK) != 0))
  {
    m_textureWidth = PadPow2(m_textureWidth);
    m_textureHeight = PadPow2(m_textureHeight);
  }
  if (m_format & XB_FMT_DXT_MASK)
  { // DXT textures must be a multiple of 4 in width and height
    m_textureWidth = ((m_textureWidth + 3) / 4) * 4;
    m_textureHeight = ((m_textureHeight + 3) / 4) * 4;
  }

  // check for max texture size
  #define CLAMP(x, y) { if (x > y) x = y; }
  CLAMP(m_textureWidth, g_Windowing.GetMaxTextureSize());
  CLAMP(m_textureHeight, g_Windowing.GetMaxTextureSize());
  CLAMP(m_imageWidth, m_textureWidth);
  CLAMP(m_imageHeight, m_textureHeight);

  delete[] m_pixels;
  m_pixels = new unsigned char[GetPitch() * GetRows()];
}
コード例 #3
0
ファイル: Texture.cpp プロジェクト: 69thelememt/xbmc
void CBaseTexture::Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU)
{
  if (pixels == NULL)
    return;

  if (format & XB_FMT_DXT_MASK)
    return;

  Allocate(width, height, format);

  unsigned int srcPitch = pitch ? pitch : GetPitch(width);
  unsigned int srcRows = GetRows(height);
  unsigned int dstPitch = GetPitch(m_textureWidth);
  unsigned int dstRows = GetRows(m_textureHeight);

  if (srcPitch == dstPitch)
    memcpy(m_pixels, pixels, srcPitch * std::min(srcRows, dstRows));
  else
  {
    const unsigned char *src = pixels;
    unsigned char* dst = m_pixels;
    for (unsigned int y = 0; y < srcRows && y < dstRows; y++)
    {
      memcpy(dst, src, std::min(srcPitch, dstPitch));
      src += srcPitch;
      dst += dstPitch;
    }
  }
  ClampToEdge();

  if (loadToGPU)
    LoadToGPU();
}
コード例 #4
0
ファイル: Texture.cpp プロジェクト: Montellese/xbmc
void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
{
  m_imageWidth = m_originalWidth = width;
  m_imageHeight = m_originalHeight = height;
  m_format = format;
  m_orientation = 0;

  m_textureWidth = m_imageWidth;
  m_textureHeight = m_imageHeight;

  if (m_format & XB_FMT_DXT_MASK)
    while (GetPitch() < CServiceBroker::GetRenderSystem().GetMinDXTPitch())
      m_textureWidth += GetBlockSize();

  if (!CServiceBroker::GetRenderSystem().SupportsNPOT((m_format & XB_FMT_DXT_MASK) != 0))
  {
    m_textureWidth = PadPow2(m_textureWidth);
    m_textureHeight = PadPow2(m_textureHeight);
  }
  if (m_format & XB_FMT_DXT_MASK)
  { // DXT textures must be a multiple of 4 in width and height
    m_textureWidth = ((m_textureWidth + 3) / 4) * 4;
    m_textureHeight = ((m_textureHeight + 3) / 4) * 4;
  }
  else
  {
    // align all textures so that they have an even width
    // in some circumstances when we downsize a thumbnail
    // which has an uneven number of pixels in width
    // we crash in CPicture::ScaleImage in ffmpegs swscale
    // because it tries to access beyond the source memory
    // (happens on osx and ios)
    // UPDATE: don't just update to be on an even width;
    // ffmpegs swscale relies on a 16-byte stride on some systems
    // so the textureWidth needs to be a multiple of 16. see ffmpeg
    // swscale headers for more info.
    m_textureWidth = ((m_textureWidth + 15) / 16) * 16;
  }

  // check for max texture size
  #define CLAMP(x, y) { if (x > y) x = y; }
  CLAMP(m_textureWidth, CServiceBroker::GetRenderSystem().GetMaxTextureSize());
  CLAMP(m_textureHeight, CServiceBroker::GetRenderSystem().GetMaxTextureSize());
  CLAMP(m_imageWidth, m_textureWidth);
  CLAMP(m_imageHeight, m_textureHeight);

  _aligned_free(m_pixels);
  m_pixels = NULL;
  if (GetPitch() * GetRows() > 0)
  {
    size_t size = GetPitch() * GetRows();
    m_pixels = (unsigned char*) _aligned_malloc(size, 32);

    if (m_pixels == nullptr)
    {
      CLog::Log(LOGERROR, "%s - Could not allocate %zu bytes. Out of memory.", __FUNCTION__, size);
    }
  }
}
コード例 #5
0
ファイル: Player.cpp プロジェクト: Kortak/MCServer
Vector3d cPlayer::GetThrowStartPos(void) const
{
	Vector3d res = GetEyePosition();
	
	// Adjust the position to be just outside the player's bounding box:
	res.x += 0.16 * cos(GetPitch());
	res.y += -0.1;
	res.z += 0.16 * sin(GetPitch());
	
	return res;
}
コード例 #6
0
ファイル: SSE2Surface32.cpp プロジェクト: jetlive/skiaming
void CSSE2Surface32Intrinsic::OnCreated()
{
	ASSERT(GetBitDepth() == 32);
	ASSERT((GetPitch() & 0xF) == 0);
	ASSERT(GetVisibleWidth() && GetVisibleHeight());
	ASSERT(sizeof(RGBQUAD) == 4);

	int width = GetVisibleWidth();
    m_qwpl  = GetPitch()/8; // qwords Per Line
    m_width = (width+3)/4; // 4 pixels at a time
}
コード例 #7
0
ファイル: Texture.cpp プロジェクト: davilla/mrmc
void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
{
  m_imageWidth = m_originalWidth = width;
  m_imageHeight = m_originalHeight = height;
  m_format = format;
  m_orientation = 0;

  m_textureWidth = m_imageWidth;
  m_textureHeight = m_imageHeight;

  if (m_format & XB_FMT_DXT_MASK)
    while (GetPitch() < g_Windowing.GetMinDXTPitch())
      m_textureWidth += GetBlockSize();

  if (!g_Windowing.SupportsNPOT((m_format & XB_FMT_DXT_MASK) != 0))
  {
    m_textureWidth = PadPow2(m_textureWidth);
    m_textureHeight = PadPow2(m_textureHeight);
  }
  if (m_format & XB_FMT_DXT_MASK)
  { // DXT textures must be a multiple of 4 in width and height
    m_textureWidth = ((m_textureWidth + 3) / 4) * 4;
    m_textureHeight = ((m_textureHeight + 3) / 4) * 4;
  }
  else
  {
    // align all textures so that they have an even width
    // in some circumstances when we downsize a thumbnail
    // which has an uneven number of pixels in width
    // we crash in CPicture::ScaleImage in ffmpegs swscale
    // because it tries to access beyond the source memory
    // (happens on osx and ios)
    // UPDATE: don't just update to be on an even width;
    // ffmpegs swscale relies on a 16-byte stride on some systems
    // so the textureWidth needs to be a multiple of 16. see ffmpeg
    // swscale headers for more info.
    m_textureWidth = ((m_textureWidth + 15) / 16) * 16;
  }

  // check for max texture size
  #define CLAMP(x, y) { if (x > y) x = y; }
  CLAMP(m_textureWidth, g_Windowing.GetMaxTextureSize());
  CLAMP(m_textureHeight, g_Windowing.GetMaxTextureSize());
  CLAMP(m_imageWidth, m_textureWidth);
  CLAMP(m_imageHeight, m_textureHeight);

  delete[] m_pixels;
  m_pixels = NULL;
  if (GetPitch() * GetRows() > 0)
  {
    m_pixels = new unsigned char[GetPitch() * GetRows()];
  }
}
コード例 #8
0
ファイル: BMaxObject.cpp プロジェクト: zhangleio/NPLRuntime
	Matrix4* BMaxObject::GetRenderMatrix(Matrix4& mxWorld, int nRenderNumber /*= 0*/)
	{
		mxWorld.identity();

		// order of rotation: roll * pitch * yaw , where roll is applied first. 
		bool bIsIdentity = true;

		float fScaling = GetScaling();
		if (fScaling != 1.f)
		{
			Matrix4 matScale;
			ParaMatrixScaling((Matrix4*)&matScale, fScaling, fScaling, fScaling);
			mxWorld = (bIsIdentity) ? matScale : matScale.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		float fYaw = GetYaw();
		if (fYaw != 0.f)
		{
			Matrix4 matYaw;
			ParaMatrixRotationY((Matrix4*)&matYaw, fYaw);
			mxWorld = (bIsIdentity) ? matYaw : matYaw.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		if (GetPitch() != 0.f)
		{
			Matrix4 matPitch;
			ParaMatrixRotationX(&matPitch, GetPitch());
			mxWorld = (bIsIdentity) ? matPitch : matPitch.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		if (GetRoll() != 0.f)
		{
			Matrix4 matRoll;
			ParaMatrixRotationZ(&matRoll, GetRoll());
			mxWorld = (bIsIdentity) ? matRoll : matRoll.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		// world translation
		Vector3 vPos = GetRenderOffset();
		mxWorld._41 += vPos.x;
		mxWorld._42 += vPos.y;
		mxWorld._43 += vPos.z;

		return &mxWorld;
	}
コード例 #9
0
ファイル: ImageEx.cpp プロジェクト: 9crk/EasyClient
bool CImageEx::SetGray()
{
	int nWidth = GetWidth();
	int nHeight = GetHeight();

	BYTE* pArray = (BYTE*)GetBits();
	int nPitch = GetPitch();
	int nBitCount = GetBPP() / 8;

	for (int i = 0; i < nHeight; i++) 
	{
		for (int j = 0; j < nWidth; j++) 
		{
			int grayVal = (BYTE)(((*(pArray + nPitch * i + j * nBitCount) * 306)
				+ (*(pArray + nPitch * i + j * nBitCount + 1) * 601)
				+ (*(pArray + nPitch * i + j * nBitCount + 2) * 117) + 512 ) >> 10);	// ¼ÆËã»Ò¶ÈÖµ

			*(pArray + nPitch * i + j * nBitCount) = grayVal;							// ¸³»Ò¶ÈÖµ
			*(pArray + nPitch * i + j * nBitCount + 1) = grayVal;
			*(pArray + nPitch * i + j * nBitCount + 2) = grayVal;
		}
	}

	return true;
}
コード例 #10
0
ファイル: sdllayer.cpp プロジェクト: timtashpulatov/emu80
void DrawScreenSpec()
{
int i,j,k;
unsigned char * pbPixels=E_BeginPaint();
int pitch=GetPitch();
unsigned char bt, cl, color;
pbPixels+=(44*pitch+16);
unsigned char * pbPix;
for (i=0;i<256;i++)
  {
  pbPix=pbPixels;
  for (j=0;j<48;j++)
    {
    bt=mempage0[0x9000+(j<<8)+i];
    cl=color_mem[(j<<8)+i];
    for (k=0;k<8;k++)
      {
      color=(bt&0x80)?cl:0;
      bt<<=1;
      *(pbPix+pitch)=color;
      *(pbPix+pitch+1)=color;
      *(pbPix++)=color;
      *(pbPix++)=color;
      }
    }
  pbPixels+=pitch;
  pbPixels+=pitch;
  }
E_EndPaint();
}
コード例 #11
0
void dCustomHinge::SubmitConstraintsFrictionAndLimit(const dMatrix& matrix0, const dMatrix& matrix1, dFloat timestep)
{
	dFloat angle = GetPitch();
	if (angle < m_minAngle) {
		dFloat relAngle = m_minAngle - angle;
		NewtonUserJointAddAngularRow(m_joint, relAngle, &matrix1.m_front[0]);
		NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
		NewtonUserJointSetRowMinimumFriction(m_joint, -m_friction);
//		m_lastRowWasUsed = true;
	} else if (angle > m_maxAngle) {
		dFloat relAngle = m_maxAngle - angle;
		NewtonUserJointAddAngularRow(m_joint, relAngle, &matrix1.m_front[0]);
		NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
		NewtonUserJointSetRowMaximumFriction(m_joint, m_friction);
//		m_lastRowWasUsed = true;
	} else {
		// friction but not limits
		dFloat alpha = m_jointOmega / timestep;
		NewtonUserJointAddAngularRow(m_joint, 0, &matrix1.m_front[0]);
		NewtonUserJointSetRowAcceleration(m_joint, -alpha);
		NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
		NewtonUserJointSetRowMinimumFriction(m_joint, -m_friction);
		NewtonUserJointSetRowMaximumFriction(m_joint, m_friction);
//		m_lastRowWasUsed = true;
	}
}
コード例 #12
0
ファイル: Player.cpp プロジェクト: Noraaron1/MCServer
bool cPlayer::SaveToDisk()
{
    cFile::CreateFolder(FILE_IO_PREFIX + AString("players"));

    // create the JSON data
    Json::Value JSON_PlayerPosition;
    JSON_PlayerPosition.append(Json::Value(GetPosX()));
    JSON_PlayerPosition.append(Json::Value(GetPosY()));
    JSON_PlayerPosition.append(Json::Value(GetPosZ()));

    Json::Value JSON_PlayerRotation;
    JSON_PlayerRotation.append(Json::Value(GetRotation()));
    JSON_PlayerRotation.append(Json::Value(GetPitch()));
    JSON_PlayerRotation.append(Json::Value(GetRoll()));

    Json::Value JSON_Inventory;
    m_Inventory.SaveToJson(JSON_Inventory);

    Json::Value root;
    root["position"]       = JSON_PlayerPosition;
    root["rotation"]       = JSON_PlayerRotation;
    root["inventory"]      = JSON_Inventory;
    root["health"]         = m_Health;
    root["xpTotal"]        = m_LifetimeTotalXp;
    root["xpCurrent"]      = m_CurrentXp;
    root["air"]            = m_AirLevel;
    root["food"]           = m_FoodLevel;
    root["foodSaturation"] = m_FoodSaturationLevel;
    root["foodTickTimer"]  = m_FoodTickTimer;
    root["foodExhaustion"] = m_FoodExhaustionLevel;
    root["world"] = GetWorld()->GetName();

    if (m_GameMode == GetWorld()->GetGameMode())
    {
        root["gamemode"] = (int) eGameMode_NotSet;
    }
    else
    {
        root["gamemode"] = (int) m_GameMode;
    }

    Json::StyledWriter writer;
    std::string JsonData = writer.write(root);

    AString SourceFile;
    Printf(SourceFile, "players/%s.json", m_PlayerName.c_str() );

    cFile f;
    if (!f.Open(SourceFile, cFile::fmWrite))
    {
        LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", m_PlayerName.c_str(), SourceFile.c_str());
        return false;
    }
    if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
    {
        LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile.c_str());
        return false;
    }
    return true;
}
コード例 #13
0
ファイル: HangingEntity.cpp プロジェクト: ChriPiv/MCServer
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
	int Dir = 0;

	// The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
	switch (m_BlockFace)
	{
		case BLOCK_FACE_ZP: break;  // Initialised to zero
		case BLOCK_FACE_ZM: Dir = 2; break;
		case BLOCK_FACE_XM: Dir = 1; break;
		case BLOCK_FACE_XP: Dir = 3; break;
		default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return;
	}

	if ((Dir == 0) || (Dir == 2))  // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180
	{
		SetYaw((Dir * 90) - 180);
	}
	else
	{
		SetYaw(Dir * 90);
	}

	a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch());
	a_ClientHandle.SendEntityMetadata(*this);
}
コード例 #14
0
ファイル: Surface.cpp プロジェクト: stavrossk/OpenXcom
/**
 * Recreates the surface with a new size.
 * Old contents will not be altered, and may be
 * cropped to fit the new size.
 * @param width Width in pixels.
 * @param height Height in pixels.
 */
void Surface::resize(int width, int height)
{
	// Set up new surface
	Uint8 bpp = _surface->format->BitsPerPixel;
	int pitch = GetPitch(bpp, width);
	void *alignedBuffer = NewAligned(bpp, width, height);
	SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(alignedBuffer, width, height, bpp, pitch, 0, 0, 0, 0);
	
	if (surface == 0)
	{
		throw Exception(SDL_GetError());
	}

	// Copy old contents
	SDL_SetColorKey(surface, SDL_SRCCOLORKEY, 0);
	SDL_SetColors(surface, getPalette(), 0, 255);
	SDL_BlitSurface(_surface, 0, surface, 0);

	// Delete old surface
	DeleteAligned(_alignedBuffer);
	SDL_FreeSurface(_surface);
	_alignedBuffer = alignedBuffer;
	_surface = surface;

	_clear.w = getWidth();
	_clear.h = getHeight();
}
コード例 #15
0
	float Source::GetPitch() const
	{
	    #ifdef HAS_AUDIO_SOURCE
		return impl->GetPitch();
		#else
		throw System::PunkException(L"Audio source is not available");
		#endif
	}
コード例 #16
0
CBaseTexture::CBaseTexture(const CBaseTexture &copy)
{
  m_imageWidth = copy.m_imageWidth;
  m_imageHeight = copy.m_imageHeight;
  m_textureWidth = copy.m_textureWidth;
  m_textureHeight = copy.m_textureHeight;
  m_format = copy.m_format;
  m_orientation = copy.m_orientation;
  m_hasAlpha = copy.m_hasAlpha;
  m_pixels = NULL;
  m_loadedToGPU = false;
  if (copy.m_pixels)
  {
    m_pixels = new unsigned char[GetPitch() * GetRows()];
    memcpy(m_pixels, copy.m_pixels, GetPitch() * GetRows());
  }
}
コード例 #17
0
ファイル: Texture.cpp プロジェクト: schererANGEL/xbmc
void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
{
  m_imageWidth = m_originalWidth = width;
  m_imageHeight = m_originalHeight = height;
  m_format = format;
  m_orientation = 0;

  m_textureWidth = m_imageWidth;
  m_textureHeight = m_imageHeight;

  if (m_format & XB_FMT_DXT_MASK)
    while (GetPitch() < g_Windowing.GetMinDXTPitch())
      m_textureWidth += GetBlockSize();

#if !defined(TARGET_RASPBERRY_PI)
  if (!g_Windowing.SupportsNPOT((m_format & XB_FMT_DXT_MASK) != 0))
  {
    m_textureWidth = PadPow2(m_textureWidth);
    m_textureHeight = PadPow2(m_textureHeight);
  }
#endif
  if (m_format & XB_FMT_DXT_MASK)
  { // DXT textures must be a multiple of 4 in width and height
    m_textureWidth = ((m_textureWidth + 3) / 4) * 4;
    m_textureHeight = ((m_textureHeight + 3) / 4) * 4;
  }
  else
  {
    // align all textures so that they have an even width
    // in some circumstances when we downsize a thumbnail
    // which has an uneven number of pixels in width
    // we crash in CPicture::ScaleImage in ffmpegs swscale
    // because it tries to access beyond the source memory
    // (happens on osx and ios)
    m_textureWidth = ((m_textureWidth + 1) / 2) * 2;
  }

  // check for max texture size
  #define CLAMP(x, y) { if (x > y) x = y; }
  CLAMP(m_textureWidth, g_Windowing.GetMaxTextureSize());
  CLAMP(m_textureHeight, g_Windowing.GetMaxTextureSize());
  CLAMP(m_imageWidth, m_textureWidth);
  CLAMP(m_imageHeight, m_textureHeight);
  delete[] m_pixels;
  m_pixels = new unsigned char[GetPitch() * GetRows()];
}
コード例 #18
0
ファイル: Player.cpp プロジェクト: Kortak/MCServer
void cPlayer::TossItems(const cItems & a_Items)
{
	m_Stats.AddValue(statItemsDropped, a_Items.Size());

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
コード例 #19
0
//-----------------------------------------------------------------------------
// Purpose: Pitches the camera forward axis toward the camera's down axis a
//			given number of degrees.
//-----------------------------------------------------------------------------
void CCamera::Pitch(float fDegrees)
{
	if (fDegrees != 0)
	{
		float fPitch = GetPitch();
		fPitch += fDegrees;
		SetPitch(fPitch);
	}
}
コード例 #20
0
bool CCameraInputHelper::UpdateTargetInterpolation()
{
	if(!m_bInterpolationTargetActive || HasForceDirection())
		return false;

	//check timeout just in case
	m_fInterpolationTargetTimeout -= gEnv->pTimer->GetFrameTime();
	if(m_fInterpolationTargetTimeout < 0.0f)
	{
		m_bInterpolationTargetActive = false;
		return true;
	}

	//work in 0 .. 2pi range
	float targetYaw = m_fInterpolationTargetYaw + gf_PI;
	float curYaw = GetYaw() + gf_PI;

	//compute yaw delta
	float yawDelta = targetYaw - curYaw;
	if(yawDelta > gf_PI)
		yawDelta = -(gf_PI2 - yawDelta);
	else if(yawDelta < -gf_PI)
		yawDelta = gf_PI2 + yawDelta;

	//compute pitch delta
	float pitchDelta = m_fInterpolationTargetPitch - GetPitch();

	//termination
	float absYawDelta = fabsf(yawDelta);
	float absPitchDelta = fabsf(pitchDelta);
	if(absYawDelta < m_fInterpolationTargetMaxError && absPitchDelta < m_fInterpolationTargetMaxError)
	{
		m_bInterpolationTargetActive = false;
		return true;
	}

	//compute safe rotation speed
	float interpolationSpeed = m_fInterpolationTargetSpeed * gEnv->pTimer->GetFrameTime();
	if(absYawDelta < INTERPOLATION_SLOWDOWN_DIST && absYawDelta > INTERPOLATION_TARGET_MAX_ERROR)
		interpolationSpeed *= max(0.02f, absYawDelta / INTERPOLATION_SLOWDOWN_DIST);
	else if(absPitchDelta < INTERPOLATION_SLOWDOWN_DIST && absPitchDelta > INTERPOLATION_TARGET_MAX_ERROR)
		interpolationSpeed *= max(0.02f, absPitchDelta / INTERPOLATION_SLOWDOWN_DIST);
	//scale yaw and pitch delta
	if(absYawDelta > interpolationSpeed)
		yawDelta = ((yawDelta < 0.0f)?-1.0f:1.0f) * interpolationSpeed;
	if(absPitchDelta > interpolationSpeed)
		pitchDelta = ((pitchDelta < 0.0f)?-1.0f:1.0f) * interpolationSpeed * INTERPOLATION_PITCH_REL_SPEED;

	//set deltas
	if(absYawDelta >= INTERPOLATION_TARGET_MAX_ERROR)
		SetYawDelta(yawDelta);
	if(absPitchDelta >= INTERPOLATION_TARGET_MAX_ERROR)
		SetPitchDelta(pitchDelta);

	return true;
}
コード例 #21
0
ファイル: Player.cpp プロジェクト: crexalbo/MCServer
void cPlayer::TossPickup(const cItem & a_Item)
{
	cItems Drops;
	Drops.push_back(a_Item);

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
コード例 #22
0
ファイル: TextureDX.cpp プロジェクト: AWilco/xbmc
void CDXTexture::LoadToGPU()
{
  if (!m_pixels)
  {
    // nothing to load - probably same image (no change)
    return;
  }

  if (m_texture.Get() == NULL)
  {
    CreateTextureObject();
    if (m_texture.Get() == NULL)
    {
      CLog::Log(LOGDEBUG, "CDXTexture::CDXTexture: Error creating new texture for size %d x %d", m_textureWidth, m_textureHeight);
      return;
    }
  }

  D3DLOCKED_RECT lr;
  if (m_texture.LockRect( 0, &lr, NULL, D3DLOCK_DISCARD ))
  {
    unsigned char *dst = (unsigned char *)lr.pBits;
    unsigned char *src = m_pixels;
    unsigned int dstPitch = lr.Pitch;
    unsigned int srcPitch = GetPitch();
    unsigned int minPitch = std::min(srcPitch, dstPitch);

    unsigned int rows = GetRows();
    if (srcPitch == dstPitch)
    {
      memcpy(dst, src, srcPitch * rows);
    }
    else
    {
      for (unsigned int y = 0; y < rows; y++)
      {
        memcpy(dst, src, minPitch);
        src += srcPitch;
        dst += dstPitch;
      }
    }
  }
  else
  {
    CLog::Log(LOGERROR, __FUNCTION__" - failed to lock texture");
  }
  m_texture.UnlockRect(0);

  delete [] m_pixels;
  m_pixels = NULL;

  m_loadedToGPU = true;
}
コード例 #23
0
void CCameraInputHelper::SnapToPlayerDir()
{
	//get target direction (player dir)
	Vec3 dir = m_pHero->GetEntity()->GetForwardDir();
	SSpherical sph;
	CartesianToSpherical(dir, sph);
	//snap camera direction (in nav mode) to player direction
	//the camera direction is 90 degrees off and flipped compared to entity space
	sph.m_fYaw -= gf_PI * 0.5f;
	sph.m_fYaw *= -1.0f;
	SetInterpolationTarget(sph.m_fYaw, GetPitch());
}
コード例 #24
0
ファイル: Player.cpp プロジェクト: Noraaron1/MCServer
void cPlayer::TossItem(
    bool a_bDraggingItem,
    char a_Amount /* = 1 */,
    short a_CreateType /* = 0 */,
    short a_CreateHealth /* = 0 */
)
{
    cItems Drops;
    if (a_CreateType != 0)
    {
        // Just create item without touching the inventory (used in creative mode)
        Drops.push_back(cItem(a_CreateType, a_Amount, a_CreateHealth));
    }
    else
    {
        // Drop an item from the inventory:
        if (a_bDraggingItem)
        {
            cItem & Item = GetDraggingItem();
            if (!Item.IsEmpty())
            {
                char OriginalItemAmount = Item.m_ItemCount;
                Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount);
                Drops.push_back(Item);
                if (OriginalItemAmount > a_Amount)
                {
                    Item.m_ItemCount = OriginalItemAmount - (char)a_Amount;
                }
                else
                {
                    Item.Empty();
                }
            }
        }
        else
        {
            // Else drop equipped item
            cItem DroppedItem(GetInventory().GetEquippedItem());
            if (!DroppedItem.IsEmpty())
            {
                if (GetInventory().RemoveOneEquippedItem())
                {
                    DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
                    Drops.push_back(DroppedItem);
                }
            }
        }
    }
    double vX = 0, vY = 0, vZ = 0;
    EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY);
    vY = -vY * 2 + 1.f;
    m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
コード例 #25
0
ファイル: sdllayer.cpp プロジェクト: timtashpulatov/emu80
void DrawScreenOrion()
{
int i,j,k;
unsigned char * pbPixels=E_BeginPaint();
int pitch=GetPitch();
unsigned char bt, bt2, color;
pbPixels+=(44*pitch+16);
unsigned char * pbPix;
for (i=0;i<256;i++)
  {
  pbPix=pbPixels;
  for (j=0;j<48;j++)
    {
    bt=mempage0[scr_beg+j*256+i];
    bt2=mempage1[scr_beg+j*256+i];
    for (k=0;k<8;k++)
      {
      switch (or_color_mode)
        {
        case 0:
          color=(bt&0x80)?2:0;
          bt<<=1;
          break;
        case 1:
          color=(bt&0x80)?14:11;
          bt<<=1;
          break;
        case 2:
        case 3:
          color=0;
        case 4:
        case 5:
          color=or_color4_table[((bt&0x80)>>7)|((bt2&0x80)>>6)];
          bt<<=1;
          bt2<<=1;
          break;
        case 6:
        case 7:
          color=(bt&0x80)?(bt2&0x0f):((bt2&0xf0)>>4);
          bt<<=1;
        }
      *(pbPix+pitch)=color;
      *(pbPix+pitch+1)=color;
      *(pbPix++)=color;
      *(pbPix++)=color;
      }
    }
  pbPixels+=pitch;
  pbPixels+=pitch;
  }
E_EndPaint();
}
コード例 #26
0
ファイル: Texture.cpp プロジェクト: AWilco/xbmc
void CBaseTexture::Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU)
{
  if (pixels == NULL)
    return;

  if (format & XB_FMT_DXT_MASK && !g_Windowing.SupportsDXT())
  { // compressed format that we don't support
    Allocate(width, height, XB_FMT_A8R8G8B8);
    CDDSImage::Decompress(m_pixels, std::min(width, m_textureWidth), std::min(height, m_textureHeight), GetPitch(m_textureWidth), pixels, format);
  }
  else
  {
    Allocate(width, height, format);

    unsigned int srcPitch = pitch ? pitch : GetPitch(width);
    unsigned int srcRows = GetRows(height);
    unsigned int dstPitch = GetPitch(m_textureWidth);
    unsigned int dstRows = GetRows(m_textureHeight);

    if (srcPitch == dstPitch)
      memcpy(m_pixels, pixels, srcPitch * std::min(srcRows, dstRows));
    else
    {
      const unsigned char *src = pixels;
      unsigned char* dst = m_pixels;
      for (unsigned int y = 0; y < srcRows && y < dstRows; y++)
      {
        memcpy(dst, src, std::min(srcPitch, dstPitch));
        src += srcPitch;
        dst += dstPitch;
      }
    }
  }
  ClampToEdge();

  if (loadToGPU)
    LoadToGPU();
}
コード例 #27
0
ファイル: Player.cpp プロジェクト: cedeel/MCServer
void cPlayer::TossItems(const cItems & a_Items)
{
	if (IsGameModeSpectator())  // Players can't toss items in spectator
	{
		return;
	}
	
	m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size());

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true);  // 'true' because created by player
}
コード例 #28
0
ファイル: Texture.cpp プロジェクト: vod777/xbmc
void CBaseTexture::LoadFromImage(ImageInfo &image, bool autoRotate)
{
  m_hasAlpha = NULL != image.alpha;

  Allocate(image.width, image.height, XB_FMT_A8R8G8B8);
  if (autoRotate && image.exifInfo.Orientation)
    m_orientation = image.exifInfo.Orientation - 1;
  m_originalWidth = image.originalwidth;
  m_originalHeight = image.originalheight;

  unsigned int dstPitch = GetPitch();
  unsigned int srcPitch = ((image.width + 1)* 3 / 4) * 4; // bitmap row length is aligned to 4 bytes

  unsigned char *dst = m_pixels;
  unsigned char *src = image.texture + (m_imageHeight - 1) * srcPitch;

  for (unsigned int y = 0; y < m_imageHeight; y++)
  {
    unsigned char *dst2 = dst;
    unsigned char *src2 = src;
    for (unsigned int x = 0; x < m_imageWidth; x++, dst2 += 4, src2 += 3)
    {
      dst2[0] = src2[0];
      dst2[1] = src2[1];
      dst2[2] = src2[2];
      dst2[3] = 0xff;
    }
    src -= srcPitch;
    dst += dstPitch;
  }

  if(image.alpha)
  {
    dst = m_pixels + 3;
    src = image.alpha + (m_imageHeight - 1) * m_imageWidth;

    for (unsigned int y = 0; y < m_imageHeight; y++)
    {
      unsigned char *dst2 = dst;
      unsigned char *src2 = src;

      for (unsigned int x = 0; x < m_imageWidth; x++,  dst2+=4, src2++)
        *dst2 = *src2;
      src -= m_imageWidth;
      dst += dstPitch;
    }
  }
  ClampToEdge();
}
コード例 #29
0
/**
 * {@inheritDoc}
 */
void ADIS16448_IMU::UpdateTable() {
  auto table = GetTable();
  if (table) {
    table->PutNumber("Value", GetAngle());
    table->PutNumber("Pitch", GetPitch());
    table->PutNumber("Roll", GetRoll());
    table->PutNumber("Yaw", GetYaw());
    table->PutNumber("AccelX", GetAccelX());
    table->PutNumber("AccelY", GetAccelY());
    table->PutNumber("AccelZ", GetAccelZ());
    table->PutNumber("AngleX", GetAngleX());
    table->PutNumber("AngleY", GetAngleY());
    table->PutNumber("AngleZ", GetAngleZ());
  }
}
コード例 #30
0
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
	super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
	m_PickupState(psNoPickup),
	m_DamageCoeff(2),
	m_IsCritical(false)
{
	SetSpeed(a_Speed);
	SetMass(0.1);
	SetRotationFromSpeed();
	SetPitchFromSpeed();
	LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
		m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
		GetRotation(), GetPitch()
	);
}