void HMM::filter(int iseq, double* phi, double* c, double* Z) { assert(o != nullptr); // DEBUG // sanity_check_parameters(); int si = o->sind[iseq]; // start index of the current sequence int sl = o->slen[iseq]; uint32_t* y_ = o->y + si; // pointer to the current sequence vmul(nu, 1, g + y_[0], os, Z, 1, hs); sve(Z, 1, c, hs); // sum vsdiv(Z, 1, c, phi, 1, hs); // normalize for(int t = 1; t < sl; t++) { // recursion step cblas_dgemv(CblasRowMajor, CblasTrans, hs, hs, 1, Q, hs, phi + (t-1)*hs, 1, 0, Z, 1); vmul(Z, 1, g + y_[t], os, Z, 1, hs); sve(Z, 1, c + t, hs); vsdiv(Z, 1, c + t, phi + t*hs, 1, hs); } }
static void drawSpires(float radius) { int i; float left[3], right[3]; float zunit[3] = {0, 0, 1}; float vectors[NUM_SPIRES][3] = { { 1.00f, 0.20f, 0.00f }, { 0.80f, 0.25f, 0.00f }, { 0.90f, 0.50f, 0.00f }, { 0.70f, 0.50f, 0.00f }, { 0.52f, 0.45f, 0.00f }, { 0.65f, 0.75f, 0.00f }, { 0.42f, 0.68f, 0.00f }, { 0.40f, 1.02f, 0.00f }, { 0.20f, 0.90f, 0.00f }, { 0.08f, 0.65f, 0.00f }, { 0.00f, 1.00f, 0.00f }, /* vertical spire */ { -0.08f, 0.65f, 0.00f }, { -0.20f, 0.90f, 0.00f }, { -0.40f, 1.02f, 0.00f }, { -0.42f, 0.68f, 0.00f }, { -0.65f, 0.75f, 0.00f }, { -0.52f, 0.45f, 0.00f }, { -0.70f, 0.50f, 0.00f }, { -0.90f, 0.50f, 0.00f }, { -0.80f, 0.30f, 0.00f }, { -1.00f, 0.20f, 0.00f } }; glColor3f(1, 1, 1); glVertex3f(0, 0, 0); glBlendFunc(GL_ONE, GL_ONE); glBegin(GL_TRIANGLES); for (i=0; i < NUM_SPIRES; i++) { normcrossprod(vectors[i], zunit, right); normcrossprod(zunit, vectors[i], left); vmul(right, SPIRE_WIDTH); vmul(left, SPIRE_WIDTH); glColor4f(1,1,1,0.0); glVertex3fv(right); glVertex3f(radius * vectors[i][0], radius * vectors[i][1], 0.0); glVertex3fv(left); } glEnd(); }
void HMM::Estep(int iseq, double* phi, double* c, double* beta, double* post, double* N, double* Naux1, double* Naux2, double* M, double* NU, double* loglik) { int si = o->sind[iseq]; // start index of the current sequence int sl = o->slen[iseq]; // sequence length uint32_t* y_ = o->y + si; // pointer to the current sequence filter(iseq, phi, c, Naux1); smoother(iseq, c, beta, Naux1); vmul(phi, 1, beta, 1, post, 1, hs * sl); // beta[:, 1:] = beta[:, 1:]*g[:, np.int_(y[1:])]/np.tile(c[1:], [k, 1]) for(int t = 1; t < sl; t++) { double* slice = beta + t*hs; vmul(slice, 1, g + y_[t], os, slice, 1, hs); vsdiv(slice, 1, c + t, slice, 1, hs); } // a = np.dot(phi[:, 0:-1], beta[:, 1:]) double* A = phi; double* B = beta + hs; double* C = Naux1; cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, hs, hs, sl-1, 1, A, hs, B, hs, 0, C, hs); // a = np.transpose(a) * Q double* D = Naux2; mtrans(C, 1, D, 1, hs, hs); vmul(D, 1, Q, 1, D, 1, hs * hs); // N += a vadd(N, 1, D, 1, N, 1, hs*hs); // for each t, update only the col y_[t], with the expected number of states for(int t = 0; t < sl; t++) { vadd(M + y_[t], os, post + t*hs, 1, M + y_[t], os, hs); } // accumulate the expected number of states at t=0 vadd(NU, 1, post, 1, NU, 1, hs); // loglik (destructive for c) double loglik_; vlog(c, c, &sl); sve(c, 1, &loglik_, sl); *loglik += loglik_; }
void qmul(quat *dest, quat *a, quat *b) { vec tmp; dest->s = a->s*b->s - vdot(a->v,b->v); memcpy(dest->v, a->v, sizeof(vec)); vmul(dest->v, b->s); memcpy(tmp, b->v, sizeof(vec)); vmul(tmp, a->s); vadd(dest->v, tmp); vcross(tmp, a->v, b->v); vadd(dest->v, tmp); }
float *calc_arc(float center[3],double radius,int divisions, int start, int end) { float *points = (float *)mem_malloc(sizeof(float)*(divisions*3)); int i; int j=0; int angle = end - start; float phi = deg_to_rad(angle); double delta = (double)((double)(phi ) / (divisions -1 )); double a = 0; for (i=0;i<divisions;i++) { float r[3]; float result[3]; vset(r,cos(a),sin(a),0); a += delta; vmul(r,(float)radius); vadd(result,center,r); points[j]=result[0]; points[j+1]=result[1]; points[j+2]=result[2]; j+=3; } return points; }
void __TFWT2D_TransformerRep::filter() { // use only from inside of critical section // multiply the forward FFT of the image by the filter amplitudes // but treat the whole operation as one large real*real vector multiply vmul((float*)m_pkrnlmask, 1, // src1 *(float**)m_poutbuf, 1, // src2 *(float**)m_poutbuf, 1, // dst m_nicols*m_nirows); // total size }
void IntegrateBRDF(float* res, float roughness, float NoV){ float* V = new float[3]; float *Xi = new float[2]; float *H = new float[3]; float *L = new float[3]; float *N = new float[3]; V[0] = sqrt(1.0f - NoV * NoV); // sin V[1] = 0.0; V[2] = NoV; // cos N[0] = 0.0; N[1] = 0.0; N[2] = 1.0; // cos float A = 0.0; float B = 0.0; int NumSamples = 1024; for (int i = 0; i < NumSamples; i++){ Hammersley(Xi, i, NumSamples); ImportanceSampleGGX(H, Xi, roughness, N); vmul(L, 2.0f * dot(V, H), H); vsub(L,V); float NoL = saturate(L[2]); float NoH = saturate(H[2]); float VoH = saturate(dot(V, H)); //BRDF拆分项计算 if (NoL > 0.0){ float G = (VoH == 0) ? 1.0f : min(1.0f, min(2.0f*NoH*NoV / VoH, 2.0f*NoH*NoL / VoH)); float G_Vis = G * VoH / (NoH * NoV); float Fc = (float)pow(1.0 - VoH, 5.0); A += (1.0f - Fc) * G_Vis; B += Fc * G_Vis; } } delete[] V; delete[] Xi; delete[] H; delete[] N; delete[] L; res[0] = A / NumSamples; res[1] = B / NumSamples; }
int prodimg(QSP_ARG_DECL Data_Obj *dpto,Data_Obj *rowobj,Data_Obj *colobj) /** make the product image */ { Vec_Obj_Args oa1, *oap=&oa1; if( OBJ_COLS(rowobj) != OBJ_COLS(dpto) ){ sprintf(DEFAULT_ERROR_STRING, "prodimg: row size mismatch, target %s (%d) and row %s (%d)", OBJ_NAME(dpto),OBJ_COLS(dpto),OBJ_NAME(rowobj), OBJ_COLS(rowobj)); NWARN(DEFAULT_ERROR_STRING); return(-1); } else if( OBJ_ROWS(colobj) != OBJ_ROWS(dpto) ){ sprintf(DEFAULT_ERROR_STRING, "prodimg: column size mismatch, target %s (%d) and column %s (%d)", OBJ_NAME(dpto),OBJ_ROWS(dpto),OBJ_NAME(colobj), OBJ_ROWS(colobj)); NWARN(DEFAULT_ERROR_STRING); return(-1); } else if( !same_pixel_type(QSP_ARG dpto,rowobj) ){ NWARN("type/precision mismatch"); return(-1); } else if( !same_pixel_type(QSP_ARG dpto,colobj) ){ NWARN("type precision mismatch"); return(-1); } #ifdef FOOBAR else if( ! FLOATING_OBJ(dpto) ){ NWARN("sorry, only float and double supported for prodimg"); return(-1); } else if( IS_COMPLEX(dpto) || IS_COMPLEX(colobj) || IS_COMPLEX(rowobj) ){ NWARN("Sorry, complex not supported"); return(-1); } #endif /* FOOBAR */ setvarg3(oap,dpto,rowobj,colobj); vmul(QSP_ARG oap); return(0); }
void HMM::smoother(int iseq, double* c, double* beta, double* Z) { int si = o->sind[iseq]; // start index of the current sequence int sl = o->slen[iseq]; // length of the current sequence uint32_t* y_ = o->y + si; // pointer to the current sequence double one = 1; // initialize: fill last frame of beta with ones vfill(&one, beta + (sl-1)*hs, 1, hs); for(int t = sl - 2; t > -1; t--) { double* out = beta + t*hs; vmul(beta + (t+1)*hs, 1, g + y_[t+1], os, Z, 1, hs); // using out as a temp vector because in cblas_dgemv, x cannot be y cblas_dgemv(CblasRowMajor, CblasNoTrans, hs, hs, 1, Q, hs, Z, 1, 0, out, 1); vsdiv(out, 1, c + t+1, out, 1, hs); } }
void sph_model::zoom(double *w, const double *v) { double d = vdot(v, zoomv); if (-1 < d && d < 1) { double b = scale(zoomk, acos(d) / M_PI) * M_PI; double y[3]; double x[3]; vcrs(y, v, zoomv); vnormalize(y, y); vcrs(x, zoomv, y); vnormalize(x, x); vmul(w, zoomv, cos(b)); vmad(w, w, x, sin(b)); } else vcpy(w, v); }
// Modified by Rick //bool intersect(dynent *d, vec &from, vec &to) // if lineseg hits entity bounding box bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits entity bounding box { vec v = to, w = d->o, *p; vsub(v, from); vsub(w, from); float c1 = dotprod(w, v); if(c1<=0) p = &from; else { float c2 = dotprod(v, v); if(c2<=c1) p = &to; else { float f = c1/c2; vmul(v, f); vadd(v, from); p = &v; }; }; /* Modified by Rick return p->x <= d->o.x+d->radius && p->x >= d->o.x-d->radius && p->y <= d->o.y+d->radius && p->y >= d->o.y-d->radius && p->z <= d->o.z+d->aboveeye && p->z >= d->o.z-d->eyeheight;*/ if( p->x <= d->o.x+d->radius && p->x >= d->o.x-d->radius && p->y <= d->o.y+d->radius && p->y >= d->o.y-d->radius && p->z <= d->o.z+d->aboveeye && p->z >= d->o.z-d->eyeheight) { if (end) *end = *p; return true; } return false; };
float *calc_circle(float center[3],double radius,int divisions) { float *points = (float *)mem_malloc(sizeof(float)*divisions*3); int i; int j=0; double delta = (double)((double)(_PI * 2) / divisions); for (i=0;i<divisions;i++) { float r[3]; float result[3]; vset(r,cos(i*delta),sin(i*delta),0); vmul(r,(float)radius); vadd(result,center,r); points[j]=result[0]; points[j+1]=result[1]; points[j+2]=result[2]; j+=3; } return points; }
void catmulrom(vec &z, vec &a, vec &b, vec &c, float s, vec &dest) // spline interpolation { vec t1 = b, t2 = c; vsub(t1, z); vmul(t1, 0.5f) vsub(t2, a); vmul(t2, 0.5f); float s2 = s*s; float s3 = s*s2; dest = a; vec t = b; vmul(dest, 2*s3 - 3*s2 + 1); vmul(t, -2*s3 + 3*s2); vadd(dest, t); vmul(t1, s3 - 2*s2 + s); vadd(dest, t1); vmul(t2, s3 - s2); vadd(dest, t2); };
void catmulrom(Vec3 &z, Vec3 &a, Vec3 &b, Vec3 &c, float s, Vec3 &dest) // spline interpolation { Vec3 t1 = b, t2 = c; vsub(t1, z); vmul(t1, 0.5f) vsub(t2, a); vmul(t2, 0.5f); float s2 = s * s; float s3 = s * s2; dest = a; Vec3 t = b; vmul(dest, 2 * s3 - 3 * s2 + 1); vmul(t, -2 * s3 + 3 * s2); vadd(dest, t); vmul(t1, s3 - 2 * s2 + s); vadd(dest, t1); vmul(t2, s3 - s2); vadd(dest, t2); }
// --------------------------------------------- // vector math // void siglab_sbMpy3(float *src1, float *src2, float *dst, long nel) { vmul(src1, 1, src2, 1, dst, 1, nel); }
int YYPARSE_DECL() { int yym, yyn, yystate, yyresult; #if YYBTYACC int yynewerrflag; YYParseState *yyerrctx = NULL; #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE yyerror_loc_range[2]; /* position of error start & end */ #endif #if YYDEBUG const char *yys; if ((yys = getenv("YYDEBUG")) != 0) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } if (yydebug) fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX); #endif #if YYBTYACC yyps = yyNewState(0); if (yyps == 0) goto yyenomem; yyps->save = 0; #endif /* YYBTYACC */ yynerrs = 0; yyerrflag = 0; yychar = YYEMPTY; yystate = 0; #if YYPURE memset(&yystack, 0, sizeof(yystack)); #endif if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystack.s_mark = yystack.s_base; yystack.l_mark = yystack.l_base; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base; #endif yystate = 0; *yystack.s_mark = 0; yyloop: if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { #if YYBTYACC do { if (yylvp < yylve) { /* we're currently re-reading tokens */ yylval = *yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = *yylpp++; #endif yychar = *yylexp++; break; } if (yyps->save) { /* in trial mode; save scanner results for future parse attempts */ if (yylvp == yylvlim) { /* Enlarge lexical value queue */ int p = yylvp - yylvals; int s = yylvlim - yylvals; s += YYLVQUEUEGROWTH; if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem; if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; #endif yylvp = yylve = yylvals + p; yylvlim = yylvals + s; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns + p; yylplim = yylpsns + s; #endif yylexp = yylexemes + p; } *yylexp = (short) YYLEX; *yylvp++ = yylval; yylve++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpp++ = yylloc; yylpe++; #endif yychar = *yylexp++; break; } /* normal operation, no conflict encountered */ #endif /* YYBTYACC */ yychar = YYLEX; #if YYBTYACC } while (0); #endif /* YYBTYACC */ if (yychar < 0) yychar = YYEOF; /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */ #if YYDEBUG if (yydebug) { yys = yyname[YYTRANSLATE(yychar)]; fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)", YYDEBUGSTR, yydepth, yystate, yychar, yys); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval)); #endif fputc('\n', stderr); } #endif } #if YYBTYACC /* Do we have a conflict? */ if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { YYINT ctry; if (yypath) { YYParseState *save; #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n", YYDEBUGSTR, yydepth, yystate); #endif /* Switch to the next conflict context */ save = yypath; yypath = save->save; save->save = NULL; ctry = save->ctry; if (save->state != yystate) YYABORT; yyFreeState(save); } else { /* Unresolved conflict - start/continue trial parse */ YYParseState *save; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate); if (yyps->save) fputs("ALREADY in conflict, continuing trial parse.\n", stderr); else fputs("Starting trial parse.\n", stderr); } #endif save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); if (save == NULL) goto yyenomem; save->save = yyps->save; save->state = yystate; save->errflag = yyerrflag; save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base); memcpy (save->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base); memcpy (save->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base); memcpy (save->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif ctry = yytable[yyn]; if (yyctable[ctry] == -1) { #if YYDEBUG if (yydebug && yychar >= YYEOF) fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth); #endif ctry++; } save->ctry = ctry; if (yyps->save == NULL) { /* If this is a first conflict in the stack, start saving lexemes */ if (!yylexemes) { yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short)); if (yylexemes == NULL) goto yyenomem; yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE)); if (yylvals == NULL) goto yyenomem; yylvlim = yylvals + YYLVQUEUEGROWTH; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE)); if (yylpsns == NULL) goto yyenomem; yylplim = yylpsns + YYLVQUEUEGROWTH; #endif } if (yylvp == yylve) { yylvp = yylve = yylvals; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns; #endif yylexp = yylexemes; if (yychar >= YYEOF) { *yylve++ = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpe++ = yylloc; #endif *yylexp = (short) yychar; yychar = YYEMPTY; } } } if (yychar >= YYEOF) { yylvp--; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp--; #endif yylexp--; yychar = YYEMPTY; } save->lexeme = yylvp - yylvals; yyps->save = save; } if (yytable[yyn] == ctry) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", YYDEBUGSTR, yydepth, yystate, yyctable[ctry]); #endif if (yychar < 0) { yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp++; #endif yylexp++; } if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yyctable[ctry]; *++yystack.s_mark = (short) yystate; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yylloc; #endif yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; } else { yyn = yyctable[ctry]; goto yyreduce; } } /* End of code dealing with conflicts */ #endif /* YYBTYACC */ if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", YYDEBUGSTR, yydepth, yystate, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yylloc; #endif yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; } if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag != 0) goto yyinrecovery; #if YYBTYACC yynewerrflag = 1; goto yyerrhandler; goto yyerrlab; yyerrlab: yynewerrflag = 0; yyerrhandler: while (yyps->save) { int ctry; YYParseState *save = yyps->save; #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n", YYDEBUGSTR, yydepth, yystate, yyps->save->state, (int)(yylvp - yylvals - yyps->save->lexeme)); #endif /* Memorize most forward-looking error state in case it's really an error. */ if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals) { /* Free old saved error context state */ if (yyerrctx) yyFreeState(yyerrctx); /* Create and fill out new saved error context state */ yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); if (yyerrctx == NULL) goto yyenomem; yyerrctx->save = yyps->save; yyerrctx->state = yystate; yyerrctx->errflag = yyerrflag; yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base); memcpy (yyerrctx->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base); memcpy (yyerrctx->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base); memcpy (yyerrctx->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yyerrctx->lexeme = yylvp - yylvals; } yylvp = yylvals + save->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + save->lexeme; #endif yylexp = yylexemes + save->lexeme; yychar = YYEMPTY; yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base); memcpy (yystack.s_base, save->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base); memcpy (yystack.l_base, save->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base); memcpy (yystack.p_base, save->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif ctry = ++save->ctry; yystate = save->state; /* We tried shift, try reduce now */ if ((yyn = yyctable[ctry]) >= 0) goto yyreduce; yyps->save = save->save; save->save = NULL; yyFreeState(save); /* Nothing left on the stack -- error */ if (!yyps->save) { #if YYDEBUG if (yydebug) fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n", YYPREFIX, yydepth); #endif /* Restore state as it was in the most forward-advanced error */ yylvp = yylvals + yyerrctx->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + yyerrctx->lexeme; #endif yylexp = yylexemes + yyerrctx->lexeme; yychar = yylexp[-1]; yylval = yylvp[-1]; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = yylpp[-1]; #endif yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base); memcpy (yystack.s_base, yyerrctx->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base); memcpy (yystack.l_base, yyerrctx->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base); memcpy (yystack.p_base, yyerrctx->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yystate = yyerrctx->state; yyFreeState(yyerrctx); yyerrctx = NULL; } yynewerrflag = 1; } if (yynewerrflag == 0) goto yyinrecovery; #endif /* YYBTYACC */ YYERROR_CALL("syntax error"); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */ #endif #if !YYBTYACC goto yyerrlab; yyerrlab: #endif ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n", YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* lookahead position is error end position */ yyerror_loc_range[1] = yylloc; YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */ *++yystack.p_mark = yyloc; #endif goto yyloop; } else { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: error recovery discarding state %d\n", YYDEBUGSTR, yydepth, *yystack.s_mark); #endif if (yystack.s_mark <= yystack.s_base) goto yyabort; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* the current TOS position is the error start position */ yyerror_loc_range[0] = *yystack.p_mark; #endif #if defined(YYDESTRUCT_CALL) #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("error: discarding state", yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark); #else YYDESTRUCT_CALL("error: discarding state", yystos[*yystack.s_mark], yystack.l_mark); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ #endif /* defined(YYDESTRUCT_CALL) */ --yystack.s_mark; --yystack.l_mark; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) --yystack.p_mark; #endif } } } else { if (yychar == YYEOF) goto yyabort; #if YYDEBUG if (yydebug) { yys = yyname[YYTRANSLATE(yychar)]; fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n", YYDEBUGSTR, yydepth, yystate, yychar, yys); } #endif #if defined(YYDESTRUCT_CALL) #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc); #else YYDESTRUCT_CALL("error: discarding token", yychar, &yylval); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ #endif /* defined(YYDESTRUCT_CALL) */ yychar = YYEMPTY; goto yyloop; } yyreduce: yym = yylen[yyn]; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)", YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ if (yym > 0) { int i; fputc('<', stderr); for (i = yym; i > 0; i--) { if (i != yym) fputs(", ", stderr); fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]], yystack.l_mark[1-i]), stderr); } fputc('>', stderr); } #endif fputc('\n', stderr); } #endif if (yym > 0) yyval = yystack.l_mark[1-yym]; else memset(&yyval, 0, sizeof yyval); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* Perform position reduction */ memset(&yyloc, 0, sizeof(yyloc)); #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ { YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym); /* just in case YYERROR is invoked within the action, save the start of the rhs as the error start position */ yyerror_loc_range[0] = yystack.p_mark[1-yym]; } #endif switch (yyn) { case 3: #line 57 "calc1.y" { (void) printf("%15.8f\n", yystack.l_mark[-1].dval); } break; case 4: #line 61 "calc1.y" { (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); } break; case 5: #line 65 "calc1.y" { dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; } break; case 6: #line 69 "calc1.y" { vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; } break; case 7: #line 73 "calc1.y" { yyerrok; } break; case 9: #line 80 "calc1.y" { yyval.dval = dreg[yystack.l_mark[0].ival]; } break; case 10: #line 84 "calc1.y" { yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; } break; case 11: #line 88 "calc1.y" { yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; } break; case 12: #line 92 "calc1.y" { yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; } break; case 13: #line 96 "calc1.y" { yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; } break; case 14: #line 100 "calc1.y" { yyval.dval = -yystack.l_mark[0].dval; } break; case 15: #line 104 "calc1.y" { yyval.dval = yystack.l_mark[-1].dval; } break; case 16: #line 110 "calc1.y" { yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; } break; case 17: #line 114 "calc1.y" { yyval.vval.lo = yystack.l_mark[-3].dval; yyval.vval.hi = yystack.l_mark[-1].dval; if ( yyval.vval.lo > yyval.vval.hi ) { (void) printf("interval out of order\n"); YYERROR; } } break; case 18: #line 124 "calc1.y" { yyval.vval = vreg[yystack.l_mark[0].ival]; } break; case 19: #line 128 "calc1.y" { yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; } break; case 20: #line 133 "calc1.y" { yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; } break; case 21: #line 138 "calc1.y" { yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; } break; case 22: #line 143 "calc1.y" { yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; } break; case 23: #line 148 "calc1.y" { yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); } break; case 24: #line 152 "calc1.y" { yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); } break; case 25: #line 156 "calc1.y" { if (dcheck(yystack.l_mark[0].vval)) YYERROR; yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); } break; case 26: #line 161 "calc1.y" { if (dcheck ( yystack.l_mark[0].vval )) YYERROR; yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); } break; case 27: #line 166 "calc1.y" { yyval.vval.hi = -yystack.l_mark[0].vval.lo; yyval.vval.lo = -yystack.l_mark[0].vval.hi; } break; case 28: #line 171 "calc1.y" { yyval.vval = yystack.l_mark[-1].vval; } break; #line 1443 "calc1.tab.c" default: break; } yystack.s_mark -= yym; yystate = *yystack.s_mark; yystack.l_mark -= yym; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark -= yym; #endif yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); #endif fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); } #endif yystate = YYFINAL; *++yystack.s_mark = YYFINAL; *++yystack.l_mark = yyval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yyloc; #endif if (yychar < 0) { #if YYBTYACC do { if (yylvp < yylve) { /* we're currently re-reading tokens */ yylval = *yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = *yylpp++; #endif yychar = *yylexp++; break; } if (yyps->save) { /* in trial mode; save scanner results for future parse attempts */ if (yylvp == yylvlim) { /* Enlarge lexical value queue */ int p = yylvp - yylvals; int s = yylvlim - yylvals; s += YYLVQUEUEGROWTH; if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem; if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; #endif yylvp = yylve = yylvals + p; yylvlim = yylvals + s; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns + p; yylplim = yylpsns + s; #endif yylexp = yylexemes + p; } *yylexp = (short) YYLEX; *yylvp++ = yylval; yylve++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpp++ = yylloc; yylpe++; #endif yychar = *yylexp++; break; } /* normal operation, no conflict encountered */ #endif /* YYBTYACC */ yychar = YYLEX; #if YYBTYACC } while (0); #endif /* YYBTYACC */ if (yychar < 0) yychar = YYEOF; /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */ #if YYDEBUG if (yydebug) { yys = yyname[YYTRANSLATE(yychar)]; fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n", YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); } #endif } if (yychar == YYEOF) goto yyaccept; goto yyloop; } if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); #endif fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); } #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; *++yystack.s_mark = (short) yystate; *++yystack.l_mark = yyval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yyloc; #endif goto yyloop; #if YYBTYACC /* Reduction declares that this path is valid. Set yypath and do a full parse */ yyvalid: if (yypath) YYABORT; while (yyps->save) { YYParseState *save = yyps->save; yyps->save = save->save; save->save = yypath; yypath = save; } #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); #endif if (yyerrctx) { yyFreeState(yyerrctx); yyerrctx = NULL; } yylvp = yylvals + yypath->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + yypath->lexeme; #endif yylexp = yylexemes + yypath->lexeme; yychar = YYEMPTY; yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); memcpy (yystack.s_base, yypath->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); memcpy (yystack.l_base, yypath->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); memcpy (yystack.p_base, yypath->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yystate = yypath->state; goto yyloop; #endif /* YYBTYACC */ yyoverflow: YYERROR_CALL("yacc stack overflow"); #if YYBTYACC goto yyabort_nomem; yyenomem: YYERROR_CALL("memory exhausted"); yyabort_nomem: #endif /* YYBTYACC */ yyresult = 2; goto yyreturn; yyabort: yyresult = 1; goto yyreturn; yyaccept: #if YYBTYACC if (yyps->save) goto yyvalid; #endif /* YYBTYACC */ yyresult = 0; yyreturn: #if defined(YYDESTRUCT_CALL) if (yychar != YYEOF && yychar != YYEMPTY) #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); #else YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ { YYSTYPE *pv; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE *pp; for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) YYDESTRUCT_CALL("cleanup: discarding state", yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); #else for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) YYDESTRUCT_CALL("cleanup: discarding state", yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ } #endif /* defined(YYDESTRUCT_CALL) */ #if YYBTYACC if (yyerrctx) { yyFreeState(yyerrctx); yyerrctx = NULL; } while (yyps) { YYParseState *save = yyps; yyps = save->save; save->save = NULL; yyFreeState(save); } while (yypath) { YYParseState *save = yypath; yypath = save->save; save->save = NULL; yyFreeState(save); } #endif /* YYBTYACC */ yyfreestack(&yystack); return (yyresult); }
void CChildView::PrefilterEnvMap(float* res, float Roughness, float* R){ //int maxY = imgOriginal.GetHeight(), maxX = imgOriginal.GetWidth(); int maxY = cube[0].GetHeight(), maxX = cube[0].GetWidth(); float angle1, angle2, angle3, a, b; int plane; COLORREF pixel; float* N = R; float* V = R; res[0] = res[1] = res[2] = 0; int NumSamples = 512; float TotalWeight = 0.0; float* Xi = new float[2]; float* H = new float[3]; float* L = new float[3]; float* center = new float[3]; float* tmp = new float[3]; float* z = new float[3]; float* x = new float[3]; x[0] = 1.0f; x[1] = 0.0f; x[2] = 0.0f; z[0] = 0.0f; z[1] = 0.0f; z[2] = 1.0f; center[0] = 0.5; center[1] = 0.5; center[2] = -0.5; for (int i = 0; i < NumSamples; i++) { Hammersley(Xi, i, NumSamples); ImportanceSampleGGX(H, Xi, Roughness, N); vmul(L, 2.0f * dot(V, H), H); vsub(L, V); float NoL = saturate(dot(N, L)); if (NoL > 0){ //First we calculate the angle of plane x-z,z-y to axis z, x-y to axis x //x-z z tmp[0] = L[0]; tmp[1] = 0.0f; tmp[2] = L[2]; normalize(tmp); angle1 = tmp[2]; //x-y y tmp[0] = L[0]; tmp[1] = L[1]; tmp[2] = 0.0f; normalize(tmp); angle2 = tmp[0]; //y-z z tmp[0] = 0.0f; tmp[1] = L[1]; tmp[2] = L[2]; normalize(tmp); angle3 = tmp[2]; //judge in which plane if (angle1 >= 0.71f && angle3 >= 0.71f){ plane = 2; vmul(L, 0.5f / L[2], L); a = L[1] + 0.5f; b = (L[0] + 0.5f); } else if (angle1 <= -0.71f && angle3 <= -0.71f){ plane = 3; vmul(L, 0.5f / L[2], L); a = 1.0f - (L[1] + 0.5f); b = L[0] + 0.5f; } else if (angle2 >= 0.71f){ plane = 4; vmul(L, 0.5f / L[0], L); a = 1.0f - (L[1] + 0.5f); b = 1.0f - (L[2] + 0.5f); } else if (angle2 <= -0.71f){ plane = 5; vmul(L, 0.5f / L[0], L); a = 1.0f - (L[1] + 0.5f); b = 1.0f - (L[2] + 0.5f); } else if (L[1] >= 0){ plane = 1; vmul(L, 0.5f / L[1], L); a = (L[0] + 0.5f); b = (L[2] + 0.5f); } else if (L[1] < 0){ plane = 0; vmul(L, 0.5f / L[1], L); a = L[0] + 0.5f; b = 1.0f - (L[2] + 0.5f); } else{ plane = 0; a = 0; b = 0; ::AfxMessageBox(_T("ERROR")); } //Eliminate boundary if (a > 1.0f || a<0.0f || b>1.0f || b < 0.0f){ CString tstr; tstr.Format(_T("plane: %d a: %lf b: %lf"), plane, a, b); //::AfxMessageBox(tstr); } a = (a < 0.0f) ? 0.0f : a; b = (b < 0.0f) ? 0.0f : b; a = (a > 1.0f) ? 1.0f : a; b = (b > 1.0f) ? 1.0f : b; a = a * (maxX-1); b = (1.0f-b) * (maxY-1); pixel = cube[plane].GetPixel((int)a,(int)b); L[0] = GetRValue(pixel); L[1] = GetGValue(pixel); L[2] = GetBValue(pixel); vmul(L, NoL, L); vadd(res, L); //res += textureCube(cubemap, L).rgb * NoL; TotalWeight += NoL; } } vmul(res, 1/TotalWeight, res); delete[] Xi; delete[] H; delete[] L; delete[] center; delete[] tmp; delete[] x; delete[] z; }
static void sigget(sprite_t *s, int signal, void *data) { float v[2] = {0,0}; sprite_t *p; float r[2]; int sigabs; switch(signal) { case SIGNAL_CANCONTROL: *(int *)data = !(s->state & PLANE_CRASHING); break; case SIGNAL_DAMAGE: ((mech_sprite_t *)s)->damage += *(int *)data; ((player_t*)s->owner)->damage=(100*((mech_sprite_t *)s)->damage)/hitpoints; break; case SIGNAL_LAST_ENNEMI: ((player_t*)s->owner)->lastEnnemi=(player_t*)data; break; case SIGNAL_ACCELERATE: s->state |= PLANE_ACCELERATING; break; case -SIGNAL_ACCELERATE: s->state &= ~PLANE_ACCELERATING; break; case SIGNAL_UP: s->state |= PLANE_UP; s->state &= ~PLANE_DOWN; break; case -SIGNAL_UP: s->state &= ~PLANE_UP; break; case SIGNAL_DOWN: s->state |= PLANE_DOWN; s->state &= ~PLANE_UP; break; case -SIGNAL_DOWN: s->state &= ~PLANE_DOWN; break; case SIGNAL_FIRE: /* create bullet */ if (sprite_timer_finished(((struct biplane*)s)->gun_timer) && !(s->state & PLANE_CRASHING)) { sound_effect(&sound_gunfire,s->x,s->y); p = sprite_create(((struct biplane*)s)->bullet_type,s->owner); //p->owner=s->owner; sprite_group_insert(bullet_group,p); r[0] = mech_heading((mech_sprite_t *)s)[0]; r[1] = mech_heading((mech_sprite_t *)s)[1]; vmul(r,21); /* Find start of bullet in clumsy way */ vrot(r,-9); sprite_set_pos(p,s->x + r[0],s->y + r[1]); sprite_get_vel(s,v); vmadd(v,200,mech_heading((mech_sprite_t *)s)); sprite_set_vel(p,v); /* cannot fire again in some time */ sprite_timer_set(&(((struct biplane*)s)->gun_timer),bullet_delay); } break; case SIGNAL_NUM0: /* create bomb */ if (sprite_timer_finished(((struct biplane*)s)->bomb_timer) && (!(s->state & PLANE_CRASHING)) && (((struct biplane*)s)->nr_bombs > 0)) { ((struct biplane*)s)->nr_bombs--; p = sprite_create(&bomb,s->owner); p->anim_p = s->anim_p; ((mech_sprite_t *)p)->angle = ((mech_sprite_t *)s)->angle; r[0] = mech_heading((mech_sprite_t *)s)[0]; r[1] = mech_heading((mech_sprite_t *)s)[1]; vmul(r,14); vrot(r,-80); sprite_set_pos(p,s->x + r[0],s->y + r[1]); sprite_get_vel(s,v); vmadd(v,5,r); sprite_set_vel(p,v); sprite_group_insert(bomb_group,p); sprite_timer_set(&(((struct biplane*)s)->bomb_timer), bomb_delay); } break; case SIGNAL_NUM1: /* jump ship */ if (sprite_timer_finished(((struct biplane*)s)->bomb_timer) && (!(s->state & PLANE_CRASHING))) { p = sprite_create(¶chute,NULL); r[0] = mech_heading((mech_sprite_t *)s)[0]; r[1] = mech_heading((mech_sprite_t *)s)[1]; vmul(r,14); vrot(r,80); sprite_set_pos(p,s->x + r[0],s->y + r[1]); sprite_get_vel(s,v); vmadd(v,5,r); sprite_set_vel(p,v); sprite_group_insert(mech_group,p); sprite_timer_set(&(((struct biplane*)s)->bomb_timer),bomb_delay); } break; case SIGNAL_KILL: create_effect(&explosion,s->x,s->y); sprite_kill(s); break; case SIGNAL_ISHARMLESS: if (s->state & PLANE_CRASHING) ((struct signal_reply *)data)->reply = 1; break; case SIGNAL_STATSTRING://TTODO : useless ? sprintf(data,"%i bombs",((struct biplane*)s)->nr_bombs); break; default: break; } }
f128tuple histohit(f128tuple xyvec, const colorset pointcolors[4], const i32 th_id){ // don't plot the first 20 iterations if(threadHits[th_id]++ > 20){ f128 xarr = xyvec.x; f128 yarr = xyvec.y; // check to see if any points have escaped to infinity or are NaN // if they have, reset them and the threadHits counter to 0 if(vvalid(xarr.v) && vvalid(yarr.v)){ // scale the points from fractal-space to histogram-space f128 scaledX; scaledX.v = vadd( vmul( vadd(xarr.v, xoffsetvec), hwidShrunkvec), halfhwidvec); f128 scaledY; scaledY.v = vadd( vmul( vadd(yarr.v, yoffsetvec), hheiShrunkvec), halfhheivec); // extract each point and plot for (i32 i = 0; i < FLOATS_PER_VECTOR_REGISTER; i++){ const u32 ix = scaledX.f[i]; const u32 iy = scaledY.f[i]; if(ix < hwid && iy < hhei){ const u64 cell = ix + (iy * hwid); // lock the row omp_set_lock(&(locks[iy])); // load the existing data // the cache miss here takes up maybe 2/3s of the program's execution time __m128 histocolor = vload((float *)&(h[cell])); // add the new color to the old histocolor = vadd( histocolor, pointcolors[i].vec); // write back vstore((float *)&(h[cell]), histocolor); ++goodHits; // unlock the cell omp_unset_lock(&(locks[iy])); } else { ++missHits; } } } else { ++badHits; threadHits[th_id] = 0; xyvec.x = zerovec; xyvec.y = zerovec; } } return xyvec; }
static Vertex vunit(const Vertex v) { return vmul(v, 1.0f / vlen(v)); }
void qinverse(quat *dest, quat *q) { memcpy(dest, q, sizeof(quat)); qconj(dest); vmul(dest->v, 1.0/qlengthsquare(q)); }
v2<T> calc_align(b2<T> par, v2<T> dim, v2<float> align = v2<float>(0.5, 0.5)) { return v2<T>(v2<float>(par.pos) + vmul(v2<float>(par.dim - dim), align)); }
int main() { freopen("saferoute.in", "r", stdin); freopen("saferoute.out", "w", stdout); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); a[i] = y2 - y1; b[i] = x1 - x2; c[i] = -a[i] * x1 - b[i] * y1; } for (int i = 0; i < 2; i++) { int x, y; scanf("%d%d", &x, &y); px[i] = x; py[i] = y; } int cn = 2; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int z = a[i] * b[j] - b[i] * a[j]; if (z == 0) continue; double cx = 1. * (b[i] * c[j] - b[j] * c[i]) / z; double cy = 1. * (c[i] * a[j] - a[i] * c[j]) / z; bool found = false; for (int k = 0; k < cn; k++) { if (comp(cx, px[k]) == 0 && comp(cy, py[k]) == 0) { found = true; break; } } if (!found) { px[cn] = cx; py[cn++] = cy; } } } for (int i = 0; i < cn; i++) id[i] = i; for (int i = 0; i < cn; i++) for (int j = i + 1; j < cn; j++) { int c1 = comp(px[i], px[j]); int c2 = comp(py[i], py[j]); if (c1 > 0 || (c1 == 0 && c2 > 0)) { std::swap(px[i], px[j]); std::swap(py[i], py[j]); std::swap(id[i], id[j]); } } int start = -1; int finish = -1; for (int i = 0; i < cn; i++) if (id[i] == 0) start = i; else if (id[i] == 1) finish = i; int cs = 0; for (int i = 0; i < n; i++) { int cc = 0; for (int j = 0; j < cn; j++) { double f = a[i] * px[j] + b[i] * py[j] + c[i]; if (comp(f, 0) == 0) { q[cc++] = j; } } for (int j = 0; j + 1 < cc; j++) { st[cs] = q[j]; fi[cs] = q[j + 1]; cs++; st[cs] = q[j + 1]; fi[cs] = q[j]; cs++; } } for (int i = 0; i < cs; i++) { d[i] = INF; } for (int i = 0; i < cs; i++) { if (st[i] == start) d[i] = 0; } for (int i = 0; i < cs; i++) vx[i] = px[fi[i]] - px[st[i]], vy[i] = py[fi[i]] - py[st[i]]; while (true) { int mi = -1; for (int i = 0; i < cs; i++) { if (was[i] || d[i] == INF) continue; if (mi < 0 || d[mi] > d[i]) mi = i; } if (mi < 0) break; was[mi] = true; for (int i = 0; i < cs; i++) { if (st[i] != fi[mi]) continue; double ang = atan2(vmul(mi, i), smul(mi, i)); if (ang < 0) ang = -ang; if (d[i] > d[mi] + ang) d[i] = d[mi] + ang; } } double ans = INF; for (int i = 0; i < cs; i++) { if (fi[i] == finish) { if (ans > d[i]) ans = d[i]; } } if (ans == INF) puts("-1"); else { printf("%.17lf\n", ans / PI * 180); } }
void rot_quat(quat *dest, double angle, vec naxis) { dest->s = cos(angle*0.5f); memcpy(dest->v, naxis, sizeof(vec)); vmul(dest->v, sin(angle*0.5f)); }
static void cpArbiterApplyImpulse_NEON(cpArbiter *arb) { cpBody *a = arb->body_a; cpBody *b = arb->body_b; cpFloatx2_t surface_vr = vld((cpFloat_t *)&arb->surface_vr); cpFloatx2_t n = vld((cpFloat_t *)&arb->n); cpFloat_t friction = arb->u; int numContacts = arb->count; struct cpContact *contacts = arb->contacts; for(int i=0; i<numContacts; i++) { struct cpContact *con = contacts + i; cpFloatx2_t r1 = vld((cpFloat_t *)&con->r1); cpFloatx2_t r2 = vld((cpFloat_t *)&con->r2); cpFloatx2_t perp = vmake(-1.0, 1.0); cpFloatx2_t r1p = vmul(vrev(r1), perp); cpFloatx2_t r2p = vmul(vrev(r2), perp); cpFloatx2_t vBias_a = vld((cpFloat_t *)&a->v_bias); cpFloatx2_t vBias_b = vld((cpFloat_t *)&b->v_bias); cpFloatx2_t wBias = vmake(a->w_bias, b->w_bias); cpFloatx2_t vb1 = vadd(vBias_a, vmul_n(r1p, vget_lane(wBias, 0))); cpFloatx2_t vb2 = vadd(vBias_b, vmul_n(r2p, vget_lane(wBias, 1))); cpFloatx2_t vbr = vsub(vb2, vb1); cpFloatx2_t v_a = vld((cpFloat_t *)&a->v); cpFloatx2_t v_b = vld((cpFloat_t *)&b->v); cpFloatx2_t w = vmake(a->w, b->w); cpFloatx2_t v1 = vadd(v_a, vmul_n(r1p, vget_lane(w, 0))); cpFloatx2_t v2 = vadd(v_b, vmul_n(r2p, vget_lane(w, 1))); cpFloatx2_t vr = vsub(v2, v1); cpFloatx2_t vbn_vrn = vpadd(vmul(vbr, n), vmul(vr, n)); cpFloatx2_t v_offset = vmake(con->bias, -con->bounce); cpFloatx2_t jOld = vmake(con->jBias, con->jnAcc); cpFloatx2_t jbn_jn = vmul_n(vsub(v_offset, vbn_vrn), con->nMass); jbn_jn = vmax(vadd(jOld, jbn_jn), vdup_n(0.0)); cpFloatx2_t jApply = vsub(jbn_jn, jOld); cpFloatx2_t t = vmul(vrev(n), perp); cpFloatx2_t vrt_tmp = vmul(vadd(vr, surface_vr), t); cpFloatx2_t vrt = vpadd(vrt_tmp, vrt_tmp); cpFloatx2_t jtOld = {}; jtOld = vset_lane(con->jtAcc, jtOld, 0); cpFloatx2_t jtMax = vrev(vmul_n(jbn_jn, friction)); cpFloatx2_t jt = vmul_n(vrt, -con->tMass); jt = vmax(vneg(jtMax), vmin(vadd(jtOld, jt), jtMax)); cpFloatx2_t jtApply = vsub(jt, jtOld); cpFloatx2_t i_inv = vmake(-a->i_inv, b->i_inv); cpFloatx2_t nperp = vmake(1.0, -1.0); cpFloatx2_t jBias = vmul_n(n, vget_lane(jApply, 0)); cpFloatx2_t jBiasCross = vmul(vrev(jBias), nperp); cpFloatx2_t biasCrosses = vpadd(vmul(r1, jBiasCross), vmul(r2, jBiasCross)); wBias = vadd(wBias, vmul(i_inv, biasCrosses)); vBias_a = vsub(vBias_a, vmul_n(jBias, a->m_inv)); vBias_b = vadd(vBias_b, vmul_n(jBias, b->m_inv)); cpFloatx2_t j = vadd(vmul_n(n, vget_lane(jApply, 1)), vmul_n(t, vget_lane(jtApply, 0))); cpFloatx2_t jCross = vmul(vrev(j), nperp); cpFloatx2_t crosses = vpadd(vmul(r1, jCross), vmul(r2, jCross)); w = vadd(w, vmul(i_inv, crosses)); v_a = vsub(v_a, vmul_n(j, a->m_inv)); v_b = vadd(v_b, vmul_n(j, b->m_inv)); // TODO would moving these earlier help pipeline them better? vst((cpFloat_t *)&a->v_bias, vBias_a); vst((cpFloat_t *)&b->v_bias, vBias_b); vst_lane((cpFloat_t *)&a->w_bias, wBias, 0); vst_lane((cpFloat_t *)&b->w_bias, wBias, 1); vst((cpFloat_t *)&a->v, v_a); vst((cpFloat_t *)&b->v, v_b); vst_lane((cpFloat_t *)&a->w, w, 0); vst_lane((cpFloat_t *)&b->w, w, 1); vst_lane((cpFloat_t *)&con->jBias, jbn_jn, 0); vst_lane((cpFloat_t *)&con->jnAcc, jbn_jn, 1); vst_lane((cpFloat_t *)&con->jtAcc, jt, 0); } }
double sph_model::view_face(const double *M, int vw, int vh, double ee, double ww, double nn, double ss, int j) { double ne[3], a[3], e[3], A[4], E[4]; // North-east corner double nw[3], b[3], f[3], B[4], F[4]; // North-west corner double se[3], c[3], g[3], C[4], G[4]; // South-east corner double sw[3], d[3], h[3], D[4], H[4]; // South-west corner vnormalize(ne, cube_v[cube_i[j][0]]); vnormalize(nw, cube_v[cube_i[j][1]]); vnormalize(se, cube_v[cube_i[j][2]]); vnormalize(sw, cube_v[cube_i[j][3]]); bislerp(a, ne, nw, se, sw, ee, nn); bislerp(b, ne, nw, se, sw, ww, nn); bislerp(c, ne, nw, se, sw, ee, ss); bislerp(d, ne, nw, se, sw, ww, ss); zoom(a, a); zoom(b, b); zoom(c, c); zoom(d, d); // Compute the maximum extent due to bulge. double v[3]; v[0] = a[0] + b[0] + c[0] + d[0]; v[1] = a[1] + b[1] + c[1] + d[1]; v[2] = a[2] + b[2] + c[2] + d[2]; double k = vlen(v) / vdot(a, v); // Compute the outer corners of the bulge bound. vmul(e, a, k); vmul(f, b, k); vmul(g, c, k); vmul(h, d, k); // Compute W and reject any volume on the far side of the singularity. A[3] = M[ 3] * a[0] + M[ 7] * a[1] + M[11] * a[2] + M[15]; B[3] = M[ 3] * b[0] + M[ 7] * b[1] + M[11] * b[2] + M[15]; C[3] = M[ 3] * c[0] + M[ 7] * c[1] + M[11] * c[2] + M[15]; D[3] = M[ 3] * d[0] + M[ 7] * d[1] + M[11] * d[2] + M[15]; E[3] = M[ 3] * e[0] + M[ 7] * e[1] + M[11] * e[2] + M[15]; F[3] = M[ 3] * f[0] + M[ 7] * f[1] + M[11] * f[2] + M[15]; G[3] = M[ 3] * g[0] + M[ 7] * g[1] + M[11] * g[2] + M[15]; H[3] = M[ 3] * h[0] + M[ 7] * h[1] + M[11] * h[2] + M[15]; if (A[3] <= 0 && B[3] <= 0 && C[3] <= 0 && D[3] <= 0 && E[3] <= 0 && F[3] <= 0 && G[3] <= 0 && H[3] <= 0) return 0; // Compute Z and apply the near and far clipping planes. A[2] = M[ 2] * a[0] + M[ 6] * a[1] + M[10] * a[2] + M[14]; B[2] = M[ 2] * b[0] + M[ 6] * b[1] + M[10] * b[2] + M[14]; C[2] = M[ 2] * c[0] + M[ 6] * c[1] + M[10] * c[2] + M[14]; D[2] = M[ 2] * d[0] + M[ 6] * d[1] + M[10] * d[2] + M[14]; E[2] = M[ 2] * e[0] + M[ 6] * e[1] + M[10] * e[2] + M[14]; F[2] = M[ 2] * f[0] + M[ 6] * f[1] + M[10] * f[2] + M[14]; G[2] = M[ 2] * g[0] + M[ 6] * g[1] + M[10] * g[2] + M[14]; H[2] = M[ 2] * h[0] + M[ 6] * h[1] + M[10] * h[2] + M[14]; if (A[2] > A[3] && B[2] > B[3] && C[2] > C[3] && D[2] > D[3] && E[2] > E[3] && F[2] > F[3] && G[2] > G[3] && H[2] > H[3]) return 0; if (A[2] < -A[3] && B[2] < -B[3] && C[2] < -C[3] && D[2] < -D[3] && E[2] < -E[3] && F[2] < -F[3] && G[2] < -G[3] && H[2] < -H[3]) return 0; // Compute Y and apply the bottom and top clipping planes. A[1] = M[ 1] * a[0] + M[ 5] * a[1] + M[ 9] * a[2] + M[13]; B[1] = M[ 1] * b[0] + M[ 5] * b[1] + M[ 9] * b[2] + M[13]; C[1] = M[ 1] * c[0] + M[ 5] * c[1] + M[ 9] * c[2] + M[13]; D[1] = M[ 1] * d[0] + M[ 5] * d[1] + M[ 9] * d[2] + M[13]; E[1] = M[ 1] * e[0] + M[ 5] * e[1] + M[ 9] * e[2] + M[13]; F[1] = M[ 1] * f[0] + M[ 5] * f[1] + M[ 9] * f[2] + M[13]; G[1] = M[ 1] * g[0] + M[ 5] * g[1] + M[ 9] * g[2] + M[13]; H[1] = M[ 1] * h[0] + M[ 5] * h[1] + M[ 9] * h[2] + M[13]; if (A[1] > A[3] && B[1] > B[3] && C[1] > C[3] && D[1] > D[3] && E[1] > E[3] && F[1] > F[3] && G[1] > G[3] && H[1] > H[3]) return 0; if (A[1] < -A[3] && B[1] < -B[3] && C[1] < -C[3] && D[1] < -D[3] && E[1] < -E[3] && F[1] < -F[3] && G[1] < -G[3] && H[1] < -H[3]) return 0; // Compute X and apply the left and right clipping planes. A[0] = M[ 0] * a[0] + M[ 4] * a[1] + M[ 8] * a[2] + M[12]; B[0] = M[ 0] * b[0] + M[ 4] * b[1] + M[ 8] * b[2] + M[12]; C[0] = M[ 0] * c[0] + M[ 4] * c[1] + M[ 8] * c[2] + M[12]; D[0] = M[ 0] * d[0] + M[ 4] * d[1] + M[ 8] * d[2] + M[12]; E[0] = M[ 0] * e[0] + M[ 4] * e[1] + M[ 8] * e[2] + M[12]; F[0] = M[ 0] * f[0] + M[ 4] * f[1] + M[ 8] * f[2] + M[12]; G[0] = M[ 0] * g[0] + M[ 4] * g[1] + M[ 8] * g[2] + M[12]; H[0] = M[ 0] * h[0] + M[ 4] * h[1] + M[ 8] * h[2] + M[12]; if (A[0] > A[3] && B[0] > B[3] && C[0] > C[3] && D[0] > D[3] && E[0] > E[3] && F[0] > F[3] && G[0] > G[3] && H[0] > H[3]) return 0; if (A[0] < -A[3] && B[0] < -B[3] && C[0] < -C[3] && D[0] < -D[3] && E[0] < -E[3] && F[0] < -F[3] && G[0] < -G[3] && H[0] < -H[3]) return 0; // Compute the length of the longest visible edge, in pixels. // return max(length(A, B, vw, vh), // length(C, D, vw, vh), // length(A, C, vw, vh), // length(B, D, vw, vh)); return std::max(max(length(A, B, vw, vh), length(C, D, vw, vh), length(A, C, vw, vh), length(B, D, vw, vh)), max(length(E, F, vw, vh), length(G, H, vw, vh), length(E, G, vw, vh), length(F, H, vw, vh))); }
int main(int argc, char const *argv[]) { int *c = (int *)malloc(3 * sizeof(int)); // Изначально вводит тип предполагаемой операции: // + - сложение // c - умножение на число // m - скалярное произведение // v - векторное произведение // g - скалярной произведение с кв.формой int j; char s; scanf("%s\n", &s); for (j = 0; j < 3; j++) scanf("%d", a + j); for (j = 0; j < 3; j++) scanf("%d", b + j); if (s == '+') { c = sum(a, b); printf("Result:\n"); int j; for (j = 0; j < 3; j++) printf("%d ", c[j]); } if (s == 'c') { c = cmul(a, b); printf("Result:\n"); int j; for (j = 0; j < 3; j++) printf("%d ", c[j]); } if (s == 'v') { c = vmul(a, b); printf("Result:\n"); int j; for (j = 0; j < 1; j++) printf("%d ", c[j]); } if (s == 'm') { c = scmul(a, b); printf("Result:\n"); printf("%d ", c[0]); } if (s == 'g') { for (j = 0; j < 3; j++) scanf("%d", g + j); c = scmul_g(a, b, g); printf("Result:\n"); printf("%d ", c[0]); } free(c); return 0; }
static Triangle tmul(const Triangle t, const float scale) { const Triangle s = { vmul(t.a, scale), vmul(t.b, scale), vmul(t.c, scale) }; return s; }
static void simulate(void) { int sh, i, j, pl, pl2, actp; double l; Vec2d v; for(i = 0; i < conf.segmentSteps; ++i) { for(pl = 0; pl < conf.maxPlayers; ++pl) { SimPlayer* p = &(player[pl]); if(p->watch) continue; if(!p->active) continue; for(sh = 0; sh < conf.numShots; ++sh) { SimShot* s = &(p->shot[sh]); SimMissile* m = &(s->missile); if(!m->live) continue; for(j = 0; j < conf.numPlanets; ++j) { v = vsub(planet[j].position, m->position); l = length(v); if (l <= planet[j].radius) { planetHit(s); } v = vdiv(v, l); v = vmul(v, planet[j].mass / (l * l)); v = vdiv(v, conf.segmentSteps); m->speed = vadd(m->speed, v); } v = vdiv(m->speed, conf.segmentSteps); m->position = vadd(m->position, v); for(pl2 = 0; pl2 < conf.maxPlayers; ++pl2) { if(!player[pl2].active) continue; l = distance(player[pl2].position, m->position); if ( (l <= conf.playerDiameter) && (m->leftSource == 1) ) { if(conf.debug & 1) printf("l = %.5f playerDiameter = %.5f missile.x = %.5f missile.y = %.5f player.x = %5f player.y = %5f\n",l,conf.playerDiameter,m->position.x,m->position.y,player[pl2].position.x,player[pl2].position.y); playerHit(s, pl, pl2); } if ( (l > (conf.playerDiameter + 1)) && (pl2 == pl) ) { m->leftSource = 1; } } if ( (m->position.x < -conf.marginleft) || (m->position.x > conf.battlefieldW + conf.marginright) || (m->position.y < -conf.margintop) || (m->position.y > conf.battlefieldH + conf.marginbottom) ) { wallHit(s); } } } } for(pl = 0, actp = 0; pl < conf.maxPlayers; ++pl) actp += player[pl].active; for(pl = 0; pl < conf.maxPlayers; ++pl) { SimPlayer* p = &(player[pl]); if(!p->active) continue; if(p->watch) continue; if(p->timeout) p->timeout--; if(p->valid || actp == 1) p->timeout = conf.timeout; for(sh = 0; sh < conf.numShots; ++sh) { SimShot* s = &(p->shot[sh]); if(!s->missile.live) continue; p->timeout = conf.timeout; player[currentPlayer].timeoutcnt = 0; s->dot[s->length++] = d2f(s->missile.position); if(s->length == conf.maxSegments) { s->missile.live = 0; allSendShotFinished(s); } } } }
void qconj(quat *dest) { vmul(dest->v,-1); }