static int dtmfgen_process(struct dtmfgen_state *s, int16_t * buf, unsigned count) { int i; for (i = 0; i < count; i++) { if (s->count == 0) { unsigned idx; const char *p = strchr(dtmf_trans, *s->p); if (!p || !*p) break; s->p++; dbg("dtmfgen: %c...\n", *p); idx = p - dtmf_trans; s->phase_low = s->phase_high = 0; s->phinc_low = dtmf_phinc_low[idx / 4]; s->phinc_high = dtmf_phinc_high[idx % 4]; s->count = s->duration; } else if (s->count == s->pause_duration) { s->phase_low = s->phase_high = 0; s->phinc_low = s->phinc_high = 0; } buf[i] = (m_sin(s->phase_low) + m_sin(s->phase_high)); s->phase_low += s->phinc_low; s->phase_high += s->phinc_high; s->count--; } return i; }
inline static VALUE f_complex_polar(VALUE klass, VALUE x, VALUE y) { assert(!k_complex_p(x)); assert(!k_complex_p(y)); return nucomp_s_canonicalize_internal(klass, f_mul(x, m_cos(y)), f_mul(x, m_sin(y))); }
float Turret::elevation (float dx, float dy, float dz) { float angle = -m_atan (dx, dy); float newX; newX = (dx * m_cos (angle)) - (dy * m_sin (angle)); return m_atan (-dz, newX) - (M_PI / 2); }
void Player::getCameraTransform(float camDist, TMat3F *transform) { #define MinCamDist 0.01 if(camDist < MinCamDist) { *transform = getEyeTransform(); transform->p.z += m_sin (bounce * 2) / 120; } else { int node = chaseNode; TMat3F nmat = image.shape->getTransform(node); nmat.set(EulerF(viewPitch, 0, 0), nmat.p); nmat.p.x = nmat.p.y = 0; m_mul(nmat, getTransform(), transform); transform->p.z += m_sin (bounce * 2) / 120; // Point3F dir; // transform->getRow(1, &dir); // float oldDist = dir.lenf(); validateEyePoint (transform, camDist); // if (newDist > oldDist) // cg.psc->setCamDist(newDist); } }
static VALUE f_complex_polar(VALUE klass, VALUE x, VALUE y) { assert(!k_complex_p(x)); assert(!k_complex_p(y)); if (f_zero_p(x) || f_zero_p(y)) { if (canonicalization) return x; return nucomp_s_new_internal(klass, x, RFLOAT_0); } if (RB_FLOAT_TYPE_P(y)) { const double arg = RFLOAT_VALUE(y); if (arg == M_PI) { x = f_negate(x); if (canonicalization) return x; y = RFLOAT_0; } else if (arg == M_PI_2) { y = x; x = RFLOAT_0; } else if (arg == M_PI_2+M_PI) { y = f_negate(x); x = RFLOAT_0; } else if (RB_FLOAT_TYPE_P(x)) { const double abs = RFLOAT_VALUE(x); const double real = abs * cos(arg), imag = abs * sin(arg); x = DBL2NUM(real); if (canonicalization && imag == 0.0) return x; y = DBL2NUM(imag); } else { x = f_mul(x, DBL2NUM(cos(arg))); y = f_mul(y, DBL2NUM(sin(arg))); if (canonicalization && f_zero_p(y)) return x; } return nucomp_s_new_internal(klass, x, y); } return nucomp_s_canonicalize_internal(klass, f_mul(x, m_cos(y)), f_mul(x, m_sin(y))); }
int fsk_modulate(struct fsk_modulator *f, int16_t * buf, unsigned count) { unsigned int phinc = f->phinc; unsigned int phase = f->phase; unsigned int bit_count = f->bit_count; unsigned int bit_rate = f->bit_rate; int i; for (i = 0; i < count; i++) { buf[i] = m_sin(phase); bit_count += bit_rate; if (bit_count >= SAMPLE_RATE) { unsigned bit = modem_get_bits(f->modem, 1); //dbg("%d: getbit()...\n", bit_count); bit_count -= SAMPLE_RATE; phinc = bit ? f->phinc1 : f->phinc0; } phase += phinc; } f->phase = phase % COSTAB_SIZE; f->phinc = phinc; f->bit_count = bit_count; return count; }
void SimPlanet::load() { unload(); if ((textureTag != 0) && (!manager->isServer())) { ResourceManager &rm = *SimResource::get(manager); const char *filename = SimTagDictionary::getString(manager, textureTag); // load the texture hTexture = rm.load(filename); AssertWarn((bool)hTexture, avar("Error reading bitmap file \"%s\"", filename)); // don't want to assert fatal because we don't want to bring down // the mission editor if ((bool)hTexture) { planet.texture = (GFXBitmap *)hTexture; addToSet(SimRenderSetId); inRenderSet = true; } } else planet.texture = NULL; // calculate planet position in world coordinates // add 90 to azimuth so that zero is at up Y axis if (incidence > 89.0f) incidence = 89.0f; if (incidence < -89.0f) incidence = -89.0f; const float az = azimuth + 90.0f; const float c = planet.distance*m_cos(DEGRAD*incidence); planet.position = Point3F(c*m_cos(DEGRAD*az), c*m_sin(DEGRAD*az), planet.distance*m_sin(DEGRAD*incidence)); // initialize light if any Point3F direction = planet.position; direction.normalize(); direction *= -1.0f; if (castShadows) { // set static data items shadowDirection = direction; shadows = true; } light.setAim(direction); //light.setType(TS::Light::LightDirectional); light.setType(TS::Light::LightDirectionalWrap); light.setIntensity(intensity.red, intensity.green, intensity.blue); if (intensity.red > 0.0f || intensity.green > 0.0f || intensity.blue > 0.0f || ambient.red > 0.0f || ambient.green > 0.0f || ambient.blue > 0.0f) { addToSet(SimLightSetId); inLightSet = true; lensFlare.setColor(intensity); } planet.lensFlare = useLensFlare ? &lensFlare : NULL; // initialize static texture coordinates textCoord[0].x = 0.0f; textCoord[0].y = 0.0f; textCoord[1].x = 1.0f; textCoord[1].y = 0.0f; textCoord[2].x = 1.0f; textCoord[2].y = 1.0f; textCoord[3].x = 0.0f; textCoord[3].y = 1.0f; setMaskBits(Modified); }
void LensFlare::render(TSRenderContext &rc) { if (!renderDetail) { renderCount = 0; return; } GFXSurface *gfxSurface = rc.getSurface(); if(!visible || !flares.size() || !(gfxSurface->getCaps() & GFX_DEVCAP_SUPPORTS_CONST_ALPHA)) { renderCount = 0; return; } renderCount++; if (obscured && renderCount%15 != 1) // if something was in the way last time we checked LOS, and it isn't time // to check LOS again, bail out early return; TS::PointArray *pointArray = rc.getPointArray(); pointArray->reset(); pointArray->useIntensities(false); pointArray->useTextures(textCoord); pointArray->useTextures(true); pointArray->setVisibility( TS::ClipMask ); pointArray->useHazes(false); gfxSurface->setHazeSource(GFX_HAZE_NONE); gfxSurface->setShadeSource(GFX_SHADE_NONE); gfxSurface->setTransparency(FALSE); gfxSurface->setTexturePerspective(FALSE); gfxSurface->setFillMode(GFX_FILL_TEXTURE); gfxSurface->setTransparency(TRUE); gfxSurface->setAlphaSource(GFX_ALPHA_TEXTURE); TS::VertexIndexPair V[4]; // if it was in the screen, go ahead and draw the lens flare. TSCamera *camera = rc.getCamera(); RectI const &screenVp = camera->getScreenViewport(); const Point2F vpSize(screenVp.lowerR.x - screenVp.upperL.x, screenVp.upperL.y + screenVp.lowerR.y); // preserve relative size of the textures, they should be // 1:1 on a 640x480 viewport Point2F vpScale(vpSize.x/640.0f, vpSize.y/480.0f); float scrSize = min(vpSize.x, vpSize.y); Point2F sunP(sunPosProjected.x, sunPosProjected.y); Point2F delta((screenVp.upperL.x + screenVp.lowerR.x) >> 1, (screenVp.upperL.y + screenVp.lowerR.y) >> 1); // find vector of the flare delta -= sunP; float deltaLen = delta.len(); float deltaFrac = 2.0f*deltaLen / scrSize; float constAlpha = .5f*(1.0f - deltaFrac); if (constAlpha <= 0.0f) { if (renderCount == 1) renderCount = 0; return; } if (root && renderCount%15 == 1) { // do a LOS query, see if anything is in the way SimCollisionInfo collision; SimContainerQuery query; query.id = 0; query.type = SimContainerQuery::DefaultDetail; query.mask = -1; Vector3F v = sunPosWorld - camera->getTCW().p; v.normalizef(); v *= 2.0f; query.box.fMin = camera->getTCW().p + v; query.box.fMax = sunPosWorld; if (root->findLOS(query, &collision, SimCollisionImageQuery::High)) { obscured = true; return; } } obscured = false; gfxSurface->setConstantAlpha(constAlpha); // generate rotated box info float angle; if (delta.x == 0.0f && delta.y == 0.0f) angle = 0.0f; else angle = m_atan(delta.x, delta.y) - M_PI/2.0f; float c = m_cos(angle), s = m_sin(angle); float a = c*(-1.0f) - s*(-1.0f), b = s*(-1.0f) + c*(-1.0f); Point2F rotPoints[4]; rotPoints[0].x = a; rotPoints[0].y = b; rotPoints[1].x = -b; rotPoints[1].y = a; rotPoints[2].x = -a; rotPoints[2].y = -b; rotPoints[3].x = b; rotPoints[3].y = -a; for (int i = 0; i < flares.size(); i++) { const FlareInfo &flare = flares[i]; Point2F flarePos = delta; flarePos *= flare.dist; flarePos += sunP; const GFXBitmap *bitmap = hMaterialList->getMaterial(flare.textureIndex).getTextureMap(); gfxSurface->setTextureMap(bitmap); Point2F dimension(bitmap->width*vpScale.x, bitmap->height*vpScale.y); const float scale = 0.5*(flare.minScale + (1.0f - deltaFrac)*flare.scaleRange); for (int j = 0; j < 4; j++) { Point3F drawPoint; if (flare.rotate) drawPoint.set(rotPoints[j].x*dimension.x, rotPoints[j].y*dimension.y, 0); else drawPoint.set(boxPoints[j][0]*dimension.x, boxPoints[j][1]*dimension.y, 0); drawPoint *= scale; drawPoint += Point3F(flarePos.x, flarePos.y, 1.0); V[j].fVertexIndex = pointArray->addProjectedPoint(drawPoint); V[j].fTextureIndex = j; } pointArray->drawProjectedPoly(4, V, 0); } gfxSurface->setTransparency(FALSE); if(deltaFrac < .3) { pointArray->useTextures(false); gfxSurface->setAlphaSource(GFX_ALPHA_CONSTANT); gfxSurface->setFillMode(GFX_FILL_CONSTANT); gfxSurface->setConstantAlpha(3.3 * (.3 - deltaFrac)); gfxSurface->setFillColor(&color); V[0].fVertexIndex = pointArray->addProjectedPoint(Point3F(screenVp.upperL.x, screenVp.upperL.y, 1.0)); V[1].fVertexIndex = pointArray->addProjectedPoint(Point3F(screenVp.lowerR.x, screenVp.upperL.y, 1.0)); V[2].fVertexIndex = pointArray->addProjectedPoint(Point3F(screenVp.lowerR.x, screenVp.lowerR.y, 1.0)); V[3].fVertexIndex = pointArray->addProjectedPoint(Point3F(screenVp.upperL.x, screenVp.lowerR.y, 1.0)); pointArray->drawProjectedPoly(4, V, 0); } gfxSurface->setAlphaSource(GFX_ALPHA_NONE); }
int fsk_demodulate(struct fsk_demodulator *f, int16_t * buf, unsigned count) { const unsigned len = f->filter_len; const unsigned shift = f->shift; const unsigned phinc0 = f->phinc0; const unsigned phinc1 = f->phinc1; unsigned idx = f->hist_index; #ifdef FAST_FSK unsigned ph0 = f->phase0; unsigned ph1 = f->phase1; #endif int32_t x0, y0, x1, y1, diff_energy; unsigned bit; unsigned int i; for (i = 0; i < count; i++) { #ifdef FAST_FSK int16_t sample = f->history[idx % len]; f->x0 -= sample * m_cos(ph0 - phinc0 * len); f->y0 -= sample * m_sin(ph0 - phinc0 * len); f->x1 -= sample * m_cos(ph1 - phinc1 * len); f->y1 -= sample * m_sin(ph1 - phinc1 * len); sample = buf[i] >> shift; f->x0 += sample * m_cos(ph0); f->y0 += sample * m_sin(ph0); f->x1 += sample * m_cos(ph1); f->y1 += sample * m_sin(ph1); f->history[idx % len] = sample; idx++; x0 = f->x0; y0 = f->y0; x1 = f->x1; y1 = f->y1; ph0 += phinc0; ph1 += phinc1; #else unsigned ph0, ph1; unsigned j; f->history[idx % len] = buf[i] >> shift; idx++; ph0 = ph1 = 0; x0 = y0 = x1 = y1 = 0; for (j = 0; j < len; j++) { unsigned n = (idx + j) % len; x0 += m_cos(ph0) * f->history[n]; y0 += m_sin(ph0) * f->history[n]; x1 += m_cos(ph1) * f->history[n]; y1 += m_sin(ph1) * f->history[n]; ph0 += phinc0; ph1 += phinc1; } #endif x0 >>= COSTAB_SHIFT; y0 >>= COSTAB_SHIFT; x1 >>= COSTAB_SHIFT; y1 >>= COSTAB_SHIFT; diff_energy = x1 * x1 + y1 * y1 - x0 * x0 - y0 * y0; #ifdef CHECK_SIGNAL #define FSK_THRESHOLD 100000 if (m_abs(diff_energy) < FSK_THRESHOLD) { no_signal_count++; /* no signal */ ; dbg(); } else no_signal_count = 0; #endif bit = (diff_energy > 0); f->bit_count += f->bit_rate; if (f->bit != bit) { /* 1: send bits: num = bit_count*bit_rate/SAMPLE_RATE */ if (f->bit_count > SAMPLE_RATE / 2) { modem_put_bits(f->modem, f->bit, 1); } f->bit = bit; f->bit_count = 0; } else if (f->bit_count >= SAMPLE_RATE) { modem_put_bits(f->modem, f->bit, 1); f->bit_count -= SAMPLE_RATE; } #define BIG_LOG 1 #ifdef BIG_LOG enum { id_s1 = 16, id_s2, id_s3, id_s4 }; #define LOG_VAL(s) { val = (s) ; log_data(id_##s, &(val), sizeof(val)); } //dbg("%u: (mark %d.%d, space %d.%d) diff_energy = %d\n", // f->modem->samples_count+i, // x1,y1, x0,y0, diff_energy); //{int16_t val;LOG_VAL(s1);LOG_VAL(s2);LOG_VAL(s3);LOG_VAL(s4);} log_data(LOG_FSK_DATA, &diff_energy, sizeof(diff_energy)); #endif } #ifdef FAST_FSK f->phase0 = ph0 % COSTAB_SIZE; f->phase1 = ph1 % COSTAB_SIZE; #endif f->hist_index = idx % len; return i; }
// decide where to place and then add to the manager void SimExplosionCloud::lightFuse(SimExplosion * explosion, Point3F & cameraPos, bool igniteNow) { // decide when to detonate if (!igniteNow) explosion->setDetonationTime(g_expRand.getFloat(0,detonationMax)); Point3F pos; Point3F vec(0, 0, 0); Point3F worldPos,worldVec; switch (form) { case Sphere : { // try to make sure explosions no closer together than 1m in z int maxZ = (int) radius; if (maxZ) { if (topOnly) vec.z = g_expRand.getInt(0,maxZ); else vec.z = g_expRand.getInt(-maxZ,maxZ); } // don't break, fall through to circle } case Circle : { float angle = g_expRand.getFloat(0,float(M_2PI)); float circleRad = m_sqrtf(radius*radius - vec.z *vec.z); vec.x = circleRad * m_cos(angle); vec.y = circleRad * m_sin(angle); pos = center; pos += vec; break; } case Screen: { if (radius>0.1f) // if radius==0, skip some work { vec=cameraPos; vec -= center; vec.normalize(); Point3F dirX,dirZ; if (fabs(vec.z) < 0.95) { // vec is not near vector (0,0,1), so we can // use it as the pivot vector m_cross(vec, Point3F(0,0,1), &dirX); dirX.normalize(); m_cross(dirX, vec, &dirZ); } else { // dirY is near vector (0,0,1), so use // pivot Point3F(1,0,0) instead m_cross(Point3F(1,0,0), vec, &dirZ); dirZ.normalize(); m_cross(vec, dirZ, &dirX); } dirX *= g_expRand.getFloat(-radius,radius); dirZ *= g_expRand.getFloat(-radius,radius); vec *= radius; vec += dirX; vec += dirZ; } pos = center; pos += vec; break; } case Box : { int side; if (topOnly) side = g_expRand.getInt(1,5); else side = g_expRand.getInt(0,5); pos = box.fMax; switch (side) { case 0: pos.z = box.fMin.z; case 1: pos.x = g_expRand.getFloat(box.fMin.x,box.fMax.x); pos.y = g_expRand.getFloat(box.fMin.y,box.fMax.y); break; case 2: pos.y = box.fMin.y; case 3: pos.x = g_expRand.getFloat(box.fMin.x,box.fMax.x); pos.z = g_expRand.getFloat(box.fMin.z,box.fMax.z); break; case 4: pos.x = box.fMin.x; case 5: pos.y = g_expRand.getFloat(box.fMin.y,box.fMax.y); pos.z = g_expRand.getFloat(box.fMin.z,box.fMax.z); break; } switch (side) { case 0: vec.set(0,0,box.fMin.z-box.fMax.z); break; case 1: vec.set(0,0,box.fMax.z-box.fMin.z); break; case 2: vec.set(0,box.fMin.y-box.fMax.y,0); break; case 3: vec.set(0,box.fMax.y-box.fMin.y,0); break; case 4: vec.set(box.fMin.x-box.fMax.x,0,0); break; case 5: vec.set(box.fMax.x-box.fMin.x,0,0); break; } break; } } // now put into world coords if (hasTransform) { m_mul(pos,transform,&worldPos); m_mul(vec,(RMat3F&)transform,&worldVec); } else { worldPos=pos; worldVec=vec; } Point3F camAxis = worldPos; camAxis -= cameraPos; if (m_dot(camAxis,worldVec)>0.0f) { worldPos -= worldVec; worldPos -= worldVec; } explosion->setPosition(worldPos); explosion->setAxis(worldVec); // move away from the building... ;-> explosion->setSound(false); manager->addObject(explosion); }