/* AFuncS : OTR Core Authentication Function (ADP=s) */ __m128i AFuncS( const uint8 *header, uint32 h_len) { uint32 i; uint32 m, last; block chain = _mm_setzero_si128(), tmp, mask; const __m128i *hdp = (__m128i*)header; last = h_len % BLOCK; if (last == 0) last = BLOCK; m = (h_len - last) / BLOCK; //header = m blocks + last bytes for (i = 0; i < m; i++){ chain = _mm_xor_si128(chain, hdp[i]); AES_encrypt(chain, &chain, encrypt_key); } hdp += m; /* last block */ ozp(last, (uint8*)&hdp[0], &tmp); chain = _mm_xor_si128(tmp, chain); if (last != BLOCK){ mul2(Q, &mask); } else{ mul4(Q, &mask); } chain = _mm_xor_si128(chain, mask); AES_encrypt(chain, &chain, encrypt_key); return chain; //TA }
void test_mixer_with_sines() { Sine vox1(431); // create 4 scaled sine waves MulOp mul1(vox1, 0.3); Sine vox2(540); MulOp mul2(vox2, 0.1); Sine vox3(890); MulOp mul3(vox3, 0.3); Sine vox4(1280); MulOp mul4(vox4, 0.01); Mixer mix(2); // create a stereo mixer mix.add_input(mul1); // add them to the mixer mix.add_input(mul2); mix.add_input(mul3); mix.add_input(mul4); logMsg("playing mix of 4 sines..."); run_test(mix); logMsg("mix done."); }
/* MixBytes reversibly mixes the bytes within a column */ void MixBytes(u8 x[ROWS][COLS1024], int columns) { int i, j; u8 temp[ROWS]; for (i = 0; i < columns; i++) { for (j = 0; j < ROWS; j++) { temp[j] = mul2(x[(j+0)%ROWS][i])^ mul2(x[(j+1)%ROWS][i])^ mul3(x[(j+2)%ROWS][i])^ mul4(x[(j+3)%ROWS][i])^ mul5(x[(j+4)%ROWS][i])^ mul3(x[(j+5)%ROWS][i])^ mul5(x[(j+6)%ROWS][i])^ mul7(x[(j+7)%ROWS][i]); } for (j = 0; j < ROWS; j++) { x[j][i] = temp[j]; } } }
__inline__ static void mul3twice(__m128i in, __m128i *out){ __m128i tmp; mul4(in, &tmp); *out = _mm_xor_si128(in, tmp); }
void model_draw(const shader_t *s, GLuint utrans, GLuint uquats, const GLuint *texture, const uint32_t *mdl, int anim_id, double frame, const float *teamcolor, const float *color, uint16_t tex_over) { /* assumes valid model data */ uint8_t ngeo, teamcolor_end, nbone, nanim; const uint8_t *p, *tr, *qt; const chunkinfo_t *ck; const anim_t *anim; const bone_t *b; vec3 trans, ptrans; vec4 rot, prot; int vis, i, offset, tex; vec3 rtrans[maxbones]; vec4 rotation[maxbones]; /* parse header */ p = (const uint8_t*)mdl; ngeo = p[0]; teamcolor_end = p[1]; nbone = p[2]; nanim = p[3]; anim = (const anim_t*)&p[4]; ck = (const chunkinfo_t*)&anim[nanim]; p = (const uint8_t*)&ck[ngeo]; anim += anim_id; vis = anim->vis; frame = frame * anim->frames; /* calculate transformations for frame */ i = 0; do { b = (const bone_t*)p; tr = (const uint8_t*)&b[1]; qt = tr + nanim; p = qt + nanim; p = align4(p); get_trans(&trans, p, tr, anim_id, frame); p += b->keyframes[0] * sizeof(keyframe_t); get_rot(&rot, p, qt, anim_id, frame); p += b->keyframes[1] * sizeof(keyframe4_t); if(b->parent < 0) { ptrans = vec3(0.0, 0.0, 0.0); prot = vec4(0.0, 0.0, 0.0, 1.0); } else { ptrans = rtrans[b->parent]; prot = rotation[b->parent]; } rotation[i] = mul4(rot, prot); trans = add3(ptrans, qrot3(add3(b->pivot, trans), prot)); rtrans[i] = add3(qrot3(neg3(b->pivot), rotation[i]), trans); } while (++i < nbone); /* load transformations */ glUniform4fv(uquats, nbone, (float*)rotation); glUniform3fv(utrans, nbone, (float*)rtrans); //GLuint test; //glGenBuffers(1, &test); // //glBufferData(GL_ELEMENT_ARRAY_BUFFER, ck[ngeo - 1].index, indices, GL_STATIC_DRAW); /* draw visible vertices */ i = 0; offset = 0; tex = 0xFFFF; glUniform4fv(s->k, 1, teamcolor); glUniform4fv(s->samp, 1, color); do { if(i == teamcolor_end) glUniform4fv(s->k, 1, transparency); if((vis & (1 << i))) { if (tex_over != 0xFFFF) { glBindTexture(GL_TEXTURE_2D, tex_over == 0xFFFE ? 0 : texture[tex_over]); } else if (ck[i].texture != tex) { tex = ck[i].texture; glBindTexture(GL_TEXTURE_2D, texture[tex]); } glDrawElements(GL_TRIANGLES, ck[i].index - offset, GL_UNSIGNED_SHORT, (void*)(size_t)offset); } offset = ck[i].index; } while(++i != ngeo); //glDeleteBuffers(1, &test); }
/* todo: implement this correctly */ vec3 model_gettrans(const uint32_t *mdl, int anim_id, double frame, int bone) { uint8_t ngeo, nbone, nanim; const uint8_t *p, *tr, *qt; const chunkinfo_t *ck; const anim_t *anim; const bone_t *b; vec3 trans, ptrans; vec4 rot, prot; int i; vec3 translation[maxbones]; vec3 rtrans[maxbones]; vec4 rotation[maxbones]; if (bone == 0xFF) return vec3(0.0, 0.0, 0.0); /* parse header */ p = (const uint8_t*)mdl; ngeo = p[0]; nbone = p[2]; nanim = p[3]; anim = (const anim_t*)&p[4]; ck = (const chunkinfo_t*)&anim[nanim]; p = (const uint8_t*)&ck[ngeo]; anim += anim_id; frame = frame * anim->frames; /* calculate transformations for frame */ i = 0; do { b = (const bone_t*)p; tr = (const uint8_t*)&b[1]; qt = tr + nanim; p = qt + nanim; if(nanim & 1) { /* alignment */ p += 2; } get_trans(&trans, p, tr, anim_id, frame); p += b->keyframes[0] * sizeof(keyframe_t); get_rot(&rot, p, qt, anim_id, frame); p += b->keyframes[1] * sizeof(keyframe4_t); if(b->parent < 0) { ptrans = vec3(0.0, 0.0, 0.0); prot = vec4(0.0, 0.0, 0.0, 1.0); } else { ptrans = rtrans[b->parent]; prot = rotation[b->parent]; } rotation[i] = mul4(rot, prot); translation[i] = add3(ptrans, qrot3(add3(b->pivot, trans), prot)); rtrans[i] = add3(qrot3(neg3(b->pivot), rotation[i]), translation[i]); if (i == bone) return translation[i]; } while(++i < nbone); return vec3(0.0, 0.0, 0.0); }
void Earth::draw() const { Camera* cam = static_cast<Camera*>(getGame()->getObjectByName("cam")); // mat4f t = glm::scale(fullTransform, vec3f(radius)); // mat4f modelViewProjectionMatrix = cam->projection * cam->view * t; // mat4f modelViewMatrix = t; // mat4f normalMatrix( glm::transpose(glm::inverse(modelViewMatrix))); // vec3f lightPos = vec3f(0,0,0); // parentObject->pos; // Texture* earth_day = TextureManager::get("earth_daytime"); // earth_day->bind(); // sphere.program->uniform("sampler")->set(2); // Texture* earth_night = TextureManager::get("earth_nighttime"); // earth_night->bind(); // sphere.program->uniform("EarthNight")->set(3); // Texture* earth_cloud = TextureManager::get("earth_cloud"); // earth_cloud->bind(); // sphere.program->uniform("EarthCloudGloss")->set(4); // Texture* earth_specular_map = TextureManager::get("earth_specular"); // earth_specular_map->bind(); // sphere.program->uniform("EarthSpecularMap")->set(5); // sphere.program->uniform("LightPosition")->set(lightPos); // sphere.program->uniform("MVPMatrix")->set(modelViewProjectionMatrix); // sphere.program->uniform("MVMatrix")->set(modelViewMatrix); // sphere.program->uniform("NormalMatrix")->set(normalMatrix); mat4f projection = cam->projection; mat4f view = cam->view; mat4f model = glm::scale(fullTransform, getScale()); mat4f t = projection*view*model; mat4f normalMatrix( glm::transpose(glm::inverse(model))); vec3f lightPos = vec3f(0.0f);// - position; float shininess = 10.0f; vec3f emission = vec3f(0.0f); //vec3f specular = vec3f(0.5f); vec3f specular = vec3f(1.0f, 0.9255f, 0.698f)*0.3f; vec3f lightAmbient = vec3f(0.0f); vec3f lightDiffuse(1.0f); vec3f lightSpecular(1.0f); mat4f viewModel = glm::inverse(view*model); vec4f camPos = viewModel[3]; mat4f iModel = ( (glm::inverse(model))); vec3f cameraPos = vec3f(camPos); //(vec3f) (iModel*(vec4f(cam->getPosition(), 0)));//**** //vec3f(model*vec4f(cam->getPosition(),1.0));// float Kr = 0.0025f; float Km = 0.0010f; float ESun = 2.f; float fScale = 1.f/(outerRadius-innerRadius); float fScaleDepth = 0.25f; //Must be 25% float fCameraHeight = glm::length(cameraPos); float g = -0.750f; // Mie aerosol scattering constant float g2 = g*g; vec3f wavelength = vec3f(0.650f, 0.570f, 0.475f); vec3f v3InvWavelength = vec3f(1.0f / powf(wavelength.x, 4.0f), 1.0f / powf(wavelength.y, 4.0f), 1.0f / powf(wavelength.z, 4.0f)); vec3f lightPos_v2 = glm::normalize(mul4(iModel, -getPosition())); // vec3f lightPos = vec3f(0.f); sphere.program->uniform("v3CameraPos")->set(cameraPos); // The camera's current position sphere.program->uniform("v3LightPos")->set(lightPos_v2); // The direction vector to the light source sphere.program->uniform("v3InvWavelength")->set(v3InvWavelength); // 1 / pow(wavelength, 4) for the red, green, and blue channels // sphere.program->uniform("fCameraHeight")->set(fCameraHeight); // The camera's current height sphere.program->uniform("fCameraHeight2")->set(fCameraHeight*fCameraHeight); // fCameraHeight^2 sphere.program->uniform("fOuterRadius")->set(outerRadius); // The outer (spheresphere) radius sphere.program->uniform("fOuterRadius2")->set(outerRadius*outerRadius); // fOuterRadius^2 sphere.program->uniform("fInnerRadius")->set(innerRadius); // The inner (planetary) radius // sphere.program->uniform("fInnerRadius2")->set(innerRavec3f(0.0f);//******* //dius*innerRadius); // fInnerRadius^2 sphere.program->uniform("fKrESun")->set(Kr*ESun); // Kr * ESun sphere.program->uniform("fKmESun")->set(Km*ESun); // Kr * ESun sphere.program->uniform("fKr4PI")->set(Kr*4.f*PI); // Kr * 4 * PI sphere.program->uniform("fKm4PI")->set(Km*4.f*PI); // Km * 4 * PI sphere.program->uniform("fScale")->set(fScale); // 1 / (fOuterRadius - fInnerRadius) sphere.program->uniform("fScaleDepth")->set(fScaleDepth); // The scale depth (i.e. the altitude at which the spheresphere's average density is found) sphere.program->uniform("fScaleOverScaleDepth")->set(fScale / (fScaleDepth) ); // fScale / fScaleDepth sphere.program->uniform("lightPos")->set(lightPos); sphere.program->uniform("shininess")->set(shininess); sphere.program->uniform("emission")->set(emission); sphere.program->uniform("specular")->set(specular); sphere.program->uniform("lightAmbient")->set(lightAmbient); sphere.program->uniform("lightDiffuse")->set(lightDiffuse); //sphere.program->uniform("lightSpecular")->set(lightSpecular); Texture* tex; tex = Textures.get("earth"); tex->bind(); sphere.program->uniform("sampler")->set((int)tex->getSlot()); tex = Textures.get("earthNight"); tex->bind(); sphere.program->uniform("samplerNight")->set((int)tex->getSlot()); tex = Textures.get("earthWater"); tex->bind(); sphere.program->uniform("samplerWater")->set((int)tex->getSlot()); tex = Textures.get("earthWaterTex"); tex->bind(); sphere.program->uniform("samplerWaterTex")->set((int)tex->getSlot()); tex = Textures.get("earthNormal"); tex->bind(); sphere.program->uniform("samplerNormal")->set((int)tex->getSlot()); tex = Textures.get("earthClouds"); tex->bind(); sphere.program->uniform("samplerCloud")->set((int)tex->getSlot()); sphere.program->uniform("modelViewProjectionMatrix")->set(t); sphere.program->uniform("modelMatrix")->set(model); sphere.program->uniform("viewMatrix")->set(view); sphere.program->uniform("normalMatrix")->set(normalMatrix); sphere.program->uniform("globaltime")->set(time); //glDisable(GL_CULL_FACE); //glDepthMask(GL_FALSE); sphere.draw(); //glDepthMask(GL_TRUE); //glEnable(GL_CULL_FACE); }