uint32_t vsTextureInternal::SafeAddColour(uint32_t acolour, uint32_t bcolour) { int ra = (acolour & 0x000000FF); int ga = (acolour & 0x0000FF00) >> 8; int ba = (acolour & 0x00FF0000) >> 16; int aa = (acolour & 0xFF000000) >> 24; int rb = (bcolour & 0x000000FF); int gb = (bcolour & 0x0000FF00) >> 8; int bb = (bcolour & 0x00FF0000) >> 16; int ab = (bcolour & 0xFF000000) >> 24; int r = vsMin( ra + rb, 0xFF ); int g = vsMin( ga + gb, 0xFF ); int b = vsMin( ba + bb, 0xFF ); int a = vsMin( aa + ab, 0xFF ); uint32_t result = (r & 0x000000FF) | ((g << 8) & 0x0000FF00) | ((b << 16) & 0x00FF0000) | ((a << 24) & 0xFF000000); return result; }
void vsFile::StoreBytes( vsStore *s, size_t bytes ) { if ( m_mode == MODE_Write ) { PHYSFS_write( m_file, s->GetReadHead(), 1, vsMin(bytes, s->BytesLeftForReading()) ); } else { PHYSFS_sint64 n = PHYSFS_read( m_file, s->GetWriteHead(), 1, vsMin(bytes, s->BytesLeftForWriting()) ); s->AdvanceWriteHead((size_t)n); } }
void vsDisplayList::GetBoundingCircle(vsVector2D ¢er, float &radius) { if ( m_instanceParent ) { m_instanceParent->GetBoundingCircle(center, radius); } else { vsVector3D min(1000000.0f,1000000.0f,1000000.f); vsVector3D max(-1000000.0f, -1000000.0f,-1000000.f); vsTransform2D currentTransform; Rewind(); op *o = PopOp(); while(o) { if ( o->type == OpCode_VertexArray ) { vsVector3D pos; int count = o->data.GetUInt(); float *shuttle = (float *) o->data.p; for ( int i = 0; i < count; i++ ) { pos.Set(shuttle[0],shuttle[1],shuttle[2]); max.x = vsMax( max.x, pos.x ); max.y = vsMax( max.y, pos.y ); max.z = vsMax( max.z, pos.z ); min.x = vsMin( min.x, pos.x ); min.y = vsMin( min.y, pos.y ); min.z = vsMin( min.z, pos.z ); shuttle += 3; } } o = PopOp(); } center = 0.5f * (max + min); radius = (max-min).Length() * 0.5f; } }
float vsVector2D::ApproximateLength() const { const float factor = (1.0f + 1.0f/(4.0f-2.0f*SQRT_TWO))/2.0f; float ax = vsFabs(x); float ay = vsFabs(y); return factor * vsMin((1.0f / SQRT_TWO)*(ax+ay), vsMax(ax, ay)); }