int CCollision::IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr, bool AllowThrough) { float Distance = distance(Pos0, Pos1); int End(Distance+1); vec2 Last = Pos0; int ix = 0, iy = 0; // Temporary position for checking collision int dx = 0, dy = 0; // Offset for checking the "through" tile if (AllowThrough) { ThroughOffset(Pos0, Pos1, &dx, &dy); } for(int i = 0; i <= End; i++) { float a = i/(float)End; vec2 Pos = mix(Pos0, Pos1, a); ix = round_to_int(Pos.x); iy = round_to_int(Pos.y); int Nx = clamp(ix/32, 0, m_Width-1); int Ny = clamp(iy/32, 0, m_Height-1); if (g_Config.m_SvOldTeleportWeapons) *pTeleNr = IsTeleport(Ny*m_Width+Nx); else *pTeleNr = IsTeleportWeapon(Ny*m_Width+Nx); if(*pTeleNr) { if(pOutCollision) *pOutCollision = Pos; if(pOutBeforeCollision) *pOutBeforeCollision = Last; return COLFLAG_TELE; } if((CheckPoint(ix, iy) && !(AllowThrough && IsThrough(ix + dx, iy + dy)))) { if(pOutCollision) *pOutCollision = Pos; if(pOutBeforeCollision) *pOutBeforeCollision = Last; return GetCollisionAt(ix, iy); } Last = Pos; } if(pOutCollision) *pOutCollision = Pos1; if(pOutBeforeCollision) *pOutBeforeCollision = Pos1; return 0; }
// TODO: OPT: rewrite this smarter! void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) { if(pBounces) *pBounces = 0; vec2 Pos = *pInoutPos; vec2 Vel = *pInoutVel; if(CheckPoint(Pos + Vel)) { int Affected = 0; if(CheckPoint(Pos.x + Vel.x, Pos.y)) { pInoutVel->x *= -Elasticity; if(pBounces) (*pBounces)++; Affected++; } if(CheckPoint(Pos.x, Pos.y + Vel.y)) { pInoutVel->y *= -Elasticity; if(pBounces) (*pBounces)++; Affected++; } if(Affected == 0) { pInoutVel->x *= -Elasticity; pInoutVel->y *= -Elasticity; } } else { *pInoutPos = Pos + Vel; } }
void Engine::GenerarGallinas(int **table) { chickens_.clear(); for (int i = 0; i < 7; ++i) for(int j = 0; j < 7; j++) { if(table[i][j] == 2) { Gallina gallina = CheckPoint(QPoint(j,i),table); if(gallina.pos_inicial != QPoint(-1,-1)) chickens_.push_back(gallina); } } }
int CTransCtrl::DoHitTest( int nShowButton ) { int test = TestDesktop( ); if( test != 0 ) return test; POINT mouse; GetCursorPos( &mouse ); if( SendMessage( m_hDeskListViewWnd, WM_NCHITTEST, 0, MAKELPARAM( mouse.x, mouse.y) ) != HTNOWHERE ) { if( CheckPoint( mouse ) ) { if( !IsWindowVisible( m_hDeskListViewWnd ) ) { if( nShowButton ) { ShowButton( true ); } else ShowWindow( m_hDeskListViewWnd, SW_SHOWNA ); } } else { if( nShowButton ) { ShowButton( false ); } if( IsWindowVisible( m_hDeskListViewWnd ) ) ShowWindow( m_hDeskListViewWnd, SW_HIDE ); } } else{ if( nShowButton ) { ShowButton( false ); } if( IsWindowVisible( m_hDeskListViewWnd ) ) { ShowWindow( m_hDeskListViewWnd, SW_HIDE ); } } return 0; }
int CCollision::IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr) { float Distance = distance(Pos0, Pos1); int End(Distance+1); vec2 Last = Pos0; int ix = 0, iy = 0; // Temporary position for checking collision for(int i = 0; i <= End; i++) { float a = i/(float)End; vec2 Pos = mix(Pos0, Pos1, a); ix = round_to_int(Pos.x); iy = round_to_int(Pos.y); int Index = GetPureMapIndex(Pos); if (g_Config.m_SvOldTeleportWeapons) *pTeleNr = IsTeleport(Index); else *pTeleNr = IsTeleportWeapon(Index); if(*pTeleNr) { if(pOutCollision) *pOutCollision = Pos; if(pOutBeforeCollision) *pOutBeforeCollision = Last; return TILE_TELEINWEAPON; } if(CheckPoint(ix, iy)) { if(pOutCollision) *pOutCollision = Pos; if(pOutBeforeCollision) *pOutBeforeCollision = Last; return GetCollisionAt(ix, iy); } Last = Pos; } if(pOutCollision) *pOutCollision = Pos1; if(pOutBeforeCollision) *pOutBeforeCollision = Pos1; return 0; }
void GUIComponentManager::UpdateNode(int index) { GUIComponent *currentCreateGUIComponent = guiComponentFactory.CreateGUIComponent(guiPresentation->GetNewComponent()); StoreGUIComponent(currentCreateGUIComponent, index); //qDebug() << guiComponents.at(index)->GetPosition(); if(!CheckPoint(guiComponents.at(index)->GetPosition())) { QPointF point = guiPresentation->GetMousePoint(); guiComponents.at(index)->setPos(point); } else { guiComponents.at(index)->setPos(guiComponents.at(index)->GetPosition()); } guiComponents.at(index)->UpdatePoint(); //qDebug() << guiComponents.at(index)->GetPosition(); DrawNode(guiComponents.at(index)); DesroyPreview(); }
void GUIComponentManager::UpdateComponent(int id) { GUIComponent *currentCreateGUIComponent = guiComponentFactory.CreateGUIComponent(guiPresentation->GetComponent(id)); StoreGUIComponent(currentCreateGUIComponent, id); //qDebug() << guiComponents.at(index)->GetPosition(); if(!CheckPoint(guiComponents.at(id)->GetPosition())) { QPointF point = guiPresentation->GetMousePoint(); guiComponents.at(id)->setPos(point); } else { guiComponents.at(id)->setPos(guiComponents.at(id)->GetPosition()); } guiComponents.at(id)->UpdatePoint(); //qDebug() << guiComponents.at(index)->GetPosition(); DrawNode(guiComponents.at(id)); ClearSelected(); }
void ProjectJournal::redo() { while( !m_redoCheckPoints.isEmpty() ) { CheckPoint c = m_redoCheckPoints.pop(); JournallingObject *jo = m_joIDs[c.joID]; if( jo ) { DataFile curState( DataFile::JournalData ); jo->saveState( curState, curState.content() ); m_undoCheckPoints.push( CheckPoint( c.joID, curState ) ); bool prev = isJournalling(); setJournalling( false ); jo->restoreState( c.data.content().firstChildElement() ); setJournalling( prev ); engine::getSong()->setModified(); break; } } }
/// // CheckLine() // // Compute intersection of P1 --> P2 line segment with face planes // Then test intersection point to see if it is on cube face // Consider only face planes in "outcode_diff" // Note: Zero bits in "outcode_diff" means face line is outside of */ // static int CheckLine(const vector3& p1, const vector3& p2, int outcode_diff) { if ((0x01 & outcode_diff) != 0) if (CheckPoint(p1,p2,( .5f-p1.x())/(p2.x()-p1.x()),0x3e) == INSIDE) return(INSIDE); if ((0x02 & outcode_diff) != 0) if (CheckPoint(p1,p2,(-.5f-p1.x())/(p2.x()-p1.x()),0x3d) == INSIDE) return(INSIDE); if ((0x04 & outcode_diff) != 0) if (CheckPoint(p1,p2,( .5f-p1.y())/(p2.y()-p1.y()),0x3b) == INSIDE) return(INSIDE); if ((0x08 & outcode_diff) != 0) if (CheckPoint(p1,p2,(-.5f-p1.y())/(p2.y()-p1.y()),0x37) == INSIDE) return(INSIDE); if ((0x10 & outcode_diff) != 0) if (CheckPoint(p1,p2,( .5f-p1.z())/(p2.z()-p1.z()),0x2f) == INSIDE) return(INSIDE); if ((0x20 & outcode_diff) != 0) if (CheckPoint(p1,p2,(-.5f-p1.z())/(p2.z()-p1.z()),0x1f) == INSIDE) return(INSIDE); return(OUTSIDE); }
int main(int argc, char **argv) { DM dm; PetscSection s; Vec u; AppCtx user; PetscInt cells[3] = {2, 2, 2}; PetscInt size = 0, cStart, cEnd, cell, c, f, i, j; PetscErrorCode ierr; ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr; ierr = ProcessOptions(PETSC_COMM_WORLD, &user);CHKERRQ(ierr); ierr = DMPlexCreateHexBoxMesh(PETSC_COMM_WORLD, user.dim, cells, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, &dm);CHKERRQ(ierr); ierr = DMSetFromOptions(dm);CHKERRQ(ierr); /* Create a section for SEM order k */ { PetscInt *numDof, d; ierr = PetscMalloc1(user.Nf*(user.dim+1), &numDof);CHKERRQ(ierr); for (f = 0; f < user.Nf; ++f) { for (d = 0; d <= user.dim; ++d) numDof[f*(user.dim+1)+d] = PetscPowInt(user.k[f]-1, d)*user.Nc[f]; size += PetscPowInt(user.k[f]+1, d)*user.Nc[f]; } ierr = DMPlexCreateSection(dm, user.dim, user.Nf, user.Nc, numDof, 0, NULL, NULL, NULL, NULL, &s);CHKERRQ(ierr); ierr = SetSymmetries(dm, s, &user);CHKERRQ(ierr); ierr = PetscFree(numDof);CHKERRQ(ierr); } ierr = DMSetDefaultSection(dm, s);CHKERRQ(ierr); /* Create spectral ordering and load in data */ ierr = DMPlexCreateSpectralClosurePermutation(dm, NULL);CHKERRQ(ierr); ierr = DMGetLocalVector(dm, &u);CHKERRQ(ierr); switch (user.dim) { case 2: ierr = LoadData2D(dm, 2, 2, size, u, &user);CHKERRQ(ierr);break; case 3: ierr = LoadData3D(dm, 2, 2, 2, size, u, &user);CHKERRQ(ierr);break; } /* Remove ordering and check some values */ ierr = PetscSectionSetClosurePermutation(s, (PetscObject) dm, NULL);CHKERRQ(ierr); switch (user.dim) { case 2: ierr = CheckPoint(dm, u, 0, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 13, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 15, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 19, &user);CHKERRQ(ierr); break; case 3: ierr = CheckPoint(dm, u, 0, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 13, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 15, &user);CHKERRQ(ierr); ierr = CheckPoint(dm, u, 19, &user);CHKERRQ(ierr); break; } /* Recreate spectral ordering and read out data */ ierr = DMPlexCreateSpectralClosurePermutation(dm, s);CHKERRQ(ierr); switch (user.dim) { case 2: ierr = ReadData2D(dm, u, &user);CHKERRQ(ierr);break; case 3: ierr = ReadData3D(dm, u, &user);CHKERRQ(ierr);break; } ierr = DMRestoreLocalVector(dm, &u);CHKERRQ(ierr); ierr = PetscSectionDestroy(&s);CHKERRQ(ierr); ierr = DMDestroy(&dm);CHKERRQ(ierr); ierr = PetscFree(user.Nc);CHKERRQ(ierr); ierr = PetscFree(user.k);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
int Co_CheckCollision(Map *map, Mobile mob, Collision *collision) { double v = G_Length(mob.vel); if (ISZERO(v)) return 0; int collisions = 0; Collision c = { .mob = mob, .t0 = DBL_MAX, }; for (int i = 0; i < map->numwalls; i++) { Wall *w = &map->walls[i]; Segment s = w->seg; Line l = G_SupportLine(s); Vector normal = G_Normal(l); double lp = G_LinePointDistance(l, mob.pos); // Skip if we are too far away from the line. if (lp > v + mob.radius) continue; // Skip if we are moving parallel to the line. if (G_Parallel(mob.vel, l.dir) && lp > mob.radius) continue; // Check for collision against the interior of the wall. double d, t = (lp - mob.radius) / fabs(G_Dot(mob.vel, normal)); if (t >= 0 && t <= 1) { // We hit the support line. Vector I = G_Sub( G_Sum(mob.pos, G_Scale(t, mob.vel)), G_Scale(G_Side(l, mob.pos) * mob.radius, normal) ); if (G_IsPointOnSegment(s, I)) { // We hit the segment: we have a collision. d = G_Distance(mob.pos, I); if (t < c.t0) { collisions++; c.point = I; c.t0 = t; c.wall = w; c.distance = d; } continue; } } // Check for collision against the start vertex. if (CheckPoint(s.start, mob, &d, &t)) { // We hit the start vertex. if (t < c.t0) { collisions++; c.point = s.start; c.t0 = t; c.wall = w; c.distance = d; } continue; } // Check for collision against the end vertex. if (CheckPoint(s.end, mob, &d, &t)) { // We hit the end vertex. if (t < c.t0) { collisions++; c.point = s.end; c.t0 = t; c.wall = w; c.distance = d; } continue; } } if (collisions && collision) { *collision = c; } return collisions; }
int CPieceRook::MoveTest(int x, int y) { if(!CheckPoint(x, y)) { return PM_UNREACHABLE; } if(m_x != x && m_y != y) { return PM_UNREACHABLE; } if(m_x == x && m_y == y) { return PM_UNREACHABLE; } int i; int min, max; CPiece * piece; //Ô¶¾àÀëÕÏ°Èü... if(m_x != x) { //ºáÏòÒƶ¯ min = x; max = x; if(x < m_x) { max = m_x; }else{ min = m_x; } for(i=min+1; i<max; i++) { piece = m_board->GetPiece(i, y); if (piece != NULL) { return PM_UNREACHABLE; } } }else{ //×ÝÏòÒƶ¯ min = y; max = y; if(y < m_y) { max = m_y; }else{ min = m_y; } for(i=min+1; i<max; i++) { piece = m_board->GetPiece(x, i); if (piece != NULL) { return PM_UNREACHABLE; } } } //ÎÞÕÏ°.. piece = m_board->GetPiece(x, y); if(piece == NULL) { return PM_MOVE; } if(piece->GetCamp() == this->GetCamp()) { return PM_UNREACHABLE; } return PM_CAPTURE; }
void Test_FixTjunctions( face_t *list ) { int i, j, m; int k; int count, count2; face_t *f, *f2; int trinum, trinum2; int addnum; int nofixnum = 0, splitnum = 0, startnum = 0; printf( "fixing tjunctions ...\n" ); count2 = count = 0; trinum2 = trinum = 0; for ( f = list; f ; f=f->next ) { // printf( "in num: %d\n", f->p->pointnum ); InitJPolyFromPolygon( f->p ); // count2 += f->p->pointnum; count++; trinum += ( jpnum - 2 ); addnum = 0; for ( f2 = list; f2 ; f2=f2->next ) { if ( f == f2 ) continue; for ( k = 0; k < 3; k++ ) { if ( f->min[k] > f2->max[k] || f->max[k] < f2->min[k] ) break; } if ( k != 3 ) continue; for ( m = 0; m < f2->p->pointnum; m++ ) { CheckPoint( f2->p->p[m] ); } } // printf( "jpoly: %d\n", jpnum ); trinum2 += ( jpnum-2 ); if ( jpnum == f->p->pointnum ) count2++; ClassifyJPoly(); f->type = jtype; if ( jtype != 1024 ) { f->fix = PolygonFromJPoly(); f->fix2 = NULL; } else { PolygonsFromJPoly( &f->fix, &f->fix2 ); } if ( jtype == -1 ) nofixnum++; else if ( jtype == 1024 ) splitnum++; else startnum++; } printf( " fixed faces %d of %d\n", count2, count ); printf( " trinum from %d to %d\n", trinum, trinum2 ); printf( " %d nofixnum, %d splitnum, %d startnum\n", nofixnum, splitnum, startnum ); }
void CHandDrawEffect::DrawEdge(IplImage* image, IplImage* image2, IplImage* base, int plane) { CvSeq* contourSeq0 = NULL; int height = image->height; int width = image->width; int step = image->widthStep; int channels = image->nChannels; uchar* data = (uchar*)image->imageData; if(plane < 3) { cvCvtColor(image, hsv, CV_BGR2HSV); // HSVのplaneを線画生成の元にする for(int i = 0; i < height * width; i++) grayImage->imageData[i] = hsv->imageData[i * 3 + plane]; } else { cvCvtColor(image, grayImage, CV_BGR2GRAY); // グレーイメージを作り線画生成の元にする } IplImage* target = base; // 書き込むターゲットイメージ for(int x = 20; x < 240; x += Y) { cvThreshold(grayImage, binaryImage, x, 255, CV_THRESH_BINARY); // x の値を境に2値化し輪郭を抽出 contourSeq0 = 0; cvFindContours(binaryImage, memStorage0, &contourSeq0, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); // 輪郭線探索 if(lineNoise > 0) { // 不連続ラインの場合 for(; contourSeq0 != 0; contourSeq0 = contourSeq0->h_next) { CvPoint *p; if(contourSeq0->total< X * 5) continue; // 5角形以下の細かいのは排除 int index = 0; for(int i = 0; i < contourSeq0->total; i += X) { p = CV_GET_SEQ_ELEM(CvPoint, contourSeq0, i); // 点の場所と色を登録 CvScalar color = GetColor(image2, p->x, p->y); MulScaler(color, DARK); // 輝度を修正 color.val[3] = CheckPoint(image, p->x, p->y, lineNoise); // 有効点かどうかを近接ピクセルから判断して[3]へ格納 SetPoint(index, p, color); // pointTableへ保存 index++; if(index > MAX_POINT) { // printf("INDEX ERROR\n"); index = 0; } } // 5連続以下の有効点は無効 (Pending:高速化) for(int i = 0; i < index; i++) { int p1 = i; int p2, p3, p4, p0; if(pointTable[p1].color.val[3]) { p2 = (p1 + 1) % index; p3 = (p1 + 2) % index; p4 = (p1 + 3) % index; p0 = (p1 - 1 + index) % index; if(pointTable[p0].color.val[3]) continue; if(!pointTable[p2].color.val[3] || !pointTable[p3].color.val[3] || !pointTable[p4].color.val[3]) { pointTable[p1].color.val[3] = 0; } } } // 接続された有効点を描く for(int i = 0; i < index; i++) { int p1 = i; int p2 = (i + 1) % index; // if (p2==index) p2 = 0; if(pointTable[p1].color.val[3] && pointTable[p2].color.val[3]) { CvScalar c = pointTable[p1].color; MulScaler(c, DARK); cvLine(target, pointTable[p1].p, pointTable[p2].p, c, lineWidth, CV_AA); } } } } else { // 全部描く場合 for(; contourSeq0 != 0; contourSeq0 = contourSeq0->h_next) { CvPoint *p1 = 0; CvPoint *p2; if(contourSeq0->total < X * 5) continue; for(int i = 0; i < contourSeq0->total; i += X) { p1 = CV_GET_SEQ_ELEM(CvPoint, contourSeq0, (i) % contourSeq0->total);//始点 p2 = CV_GET_SEQ_ELEM(CvPoint, contourSeq0, (i + X + Z) % contourSeq0->total);// 終点 CvScalar color = GetColor(image, p1->x, p1->y); MulScaler(color, DARK); cvLine(target, *p1, *p2, color, lineWidth, CV_AA); } } } } cvClearMemStorage(memStorage0); }
bool Frustum::CheckPoint(XMFLOAT3 point) { return CheckPoint(point.x, point.y, point.z); }
void ObjectMemory::DumpStats() { tracelock lock(TRACESTREAM); TRACESTREAM << std::endl<< L"Object Memory Statistics:" << std::endl << L"------------------------------" << std::endl; CheckPoint(); _CrtMemDumpStatistics(&CRTMemState); #ifdef _DEBUG checkPools(); #endif TRACESTREAM << std::endl<< L"Pool Statistics:" << std::endl << L"------------------" << std::endl << std::dec << NumPools<< L" pools in the interval (" << m_pools[0].getSize()<< L" to: " << m_pools[NumPools-1].getSize()<< L" by: " << PoolGranularity << L')' << std::endl << std::endl; int pageWaste=0; int totalPages=0; int totalFreeBytes=0; int totalChunks=0; int totalFreeChunks=0; for (int i=0;i<NumPools;i++) { int nSize = m_pools[i].getSize(); int perPage = dwPageSize/nSize; int wastePerPage = dwPageSize - (perPage*nSize); int nPages = m_pools[i].getPages(); int nChunks = perPage*nPages; int waste = nPages*wastePerPage; int nFree = m_pools[i].getFree(); TRACE(L"%d: size %d, %d objects on %d pgs (%d per pg, %d free), waste %d (%d per page)\n", i, nSize, nChunks-nFree, nPages, perPage, nFree, waste, wastePerPage); totalChunks += nChunks; pageWaste += waste; totalPages += nPages; totalFreeBytes += nFree*nSize; totalFreeChunks += nFree; } int objectWaste = 0; int totalObjects = 0; const OTE* pEnd = m_pOT+m_nOTSize; for (OTE* ote=m_pOT; ote < pEnd; ote++) { if (!ote->isFree()) { totalObjects++; if (ote->heapSpace() == OTEFlags::PoolSpace) { int size = ote->sizeOf(); int chunkSize = _ROUND2(size, PoolGranularity); objectWaste += chunkSize - size; } } } int wastePercentage = (totalChunks - totalFreeChunks) == 0 ? 0 : int(double(objectWaste)/ double(totalChunks-totalFreeChunks)*100.0); TRACESTREAM<< L"===============================================" << std::endl; TRACE(L"Total objects = %d\n" "Total pool objs = %d\n" "Total chunks = %d\n" "Total Pages = %d\n" "Total Allocs = %d\n" "Total allocated = %d\n" "Page Waste = %d bytes\n" "Object Waste = %d bytes (avg 0.%d)\n" "Total Waste = %d\n" "Total free chks = %d\n" "Total Free = %d bytes\n", totalObjects, totalChunks-totalFreeChunks, totalChunks, totalPages, FixedSizePool::m_nAllocations, totalPages*dwPageSize, pageWaste, objectWaste, wastePercentage, pageWaste+objectWaste, totalFreeChunks, totalFreeBytes); }