bool CMapLocation::Update() //returns actual { R_ASSERT(m_cached.m_updatedFrame!=Device.dwFrame); if( m_flags.test(eTTL) ) { if( m_actual_time < Device.dwTimeGlobal) { m_cached.m_Actuality = false; m_cached.m_updatedFrame = Device.dwFrame; return m_cached.m_Actuality; } } CObject* pObject = Level().Objects.net_Find(m_objectID); if (m_owner_se_object || (!IsGameTypeSingle() && pObject) ) { m_cached.m_Actuality = true; if(IsGameTypeSingle()) CalcLevelName (); CalcPosition (); }else m_cached.m_Actuality = false; m_cached.m_updatedFrame = Device.dwFrame; return m_cached.m_Actuality; }
int CNvrFileReader::CalcPosition(j_uint64_t timeStamp, j_uint32_t interval) { int nRet = J_OK; nRet = OpenFile(); if (nRet != J_OK) return nRet; FrameMap::iterator it = m_iFrameMap.begin(); if (it->second.timeStamp > ((timeStamp + interval) * 1000)) { J_OS::LOGINFO("CFileReader::CalcPosition J_OUT_RANGE"); return J_OUT_RANGE; } for (; it != m_iFrameMap.end(); it++) { if(it->second.timeStamp >= (timeStamp * 1000)) { if (it != m_iFrameMap.begin()) --it; break; } } if (it == m_iFrameMap.end()) { J_OS::LOGINFO("CFileReader::CalcPosition J_NO_RESOURCE"); return CalcPosition(timeStamp, interval); } fseek(m_pFileId, it->second.offset, SEEK_SET); m_nextTimeStamp = it->second.timeStamp; return J_OK; }
void TransformMath::CalcTransform(Trans& outputTrans, Node* node, Node* parent, TransformEnt& entity, int gridWidth, int gridHeight) { Trans& parentTrans = parent->GetTransform(); // calculate scale ofVec2f scale = CalcScale(node, parent, entity.size.x, entity.size.y, entity.sType, gridWidth, gridHeight); // calculate position ofVec2f absPos = CalcPosition(node, parent, entity.pos, entity.pType, gridWidth, gridHeight); auto shape = node->GetMesh(); // fix position according to the anchor absPos.x += (0.0f - entity.anchor.x) * shape->GetWidth()*scale.x; absPos.y += (0.0f - entity.anchor.y) * shape->GetHeight()*scale.y; int zIndex = entity.zIndex; // if zIndex is equal to 0, the value will be taken from the parent if (zIndex == 0) zIndex = (int)parentTrans.localPos.z; // set transformation outputTrans.localPos = ofVec3f(absPos.x, absPos.y, (float)zIndex); outputTrans.scale = ofVec3f(scale.x, scale.y, 1); outputTrans.rotationCentroid = ofVec2f(shape->GetWidth(), shape->GetHeight()) * entity.rotationCentroid * (scale); // multiply by abs scale outputTrans.rotation = entity.rotation; }
void CDayPlanSlider::OnMouseMove(LPARAM lParam) { POINT p = { static_cast<short>(LOWORD(lParam)), static_cast<short>(HIWORD(lParam)) }; // MapWindowPoints(m_hwnd, m_parent, &p, 1); RECT rp; GetClientRect(m_parentHwnd, &rp); int x = p.x; int offset = quickTabWidth + 2; if(x - offset > 70 && x + offset < rp.right) { RECT r = { left, top, right, bottom }; SetLocation(x - offset, 0); RECT rr = { m_pLeft->left, m_pLeft->top, m_pLeft->right, m_pLeft->bottom }; r = rr; r.right = x - 3; rp.left += 70; m_pLeft->SetBounds(rp.left, 0, r.right - r.left, r.bottom); r.left = x + 3; m_pRight->SetBounds(r.left, 0, rp.right - r.left, r.bottom); CalcPosition(); InvalidateRect(m_parentHwnd, NULL, FALSE); // UpdateWindow(m_parent); } }
double IK::Update(double max_timestep, double min_timestep, double max_integ_error) { double ret; double new_timestep = max_timestep; for(int i=0; i<2; i++) { CalcPosition(); calc_jacobian(); calc_feedback(); ret = solve_ik(); IntegrateAdaptive(new_timestep, i, min_timestep, max_integ_error); } // cerr << new_timestep << endl; CalcPosition(); return ret; }
CRect RichEditBkImg::GetRect() { if (m_bDirty) { CalcPosition(m_itemPos, m_nPosCount); m_bDirty= FALSE; } return m_rcObj; }
void MovementNode::Path(Situation *sit1, Situation *sit2, vector<direction>* ans) { debug("MovementNode::Path()"); coordMove box_move = CalcPosition(sit1, sit2); coord man_dest_coord = 2 * (box_move.begin) - box_move.end; /* display */ // cout << "sit1:" << sit1->toString() << endl; // cout << "sit2:" << sit2->toString() << endl; // cout << "man_dest_coord:" << man_dest_coord << endl; MovementNode *node1 = new MovementNode(sit1->man_y * sit1->WIDTH + sit1->man_x, 0, 0); MovementNode *node2 = new MovementNode((int) man_dest_coord, 0, 0); deque<MovementNode*> path; path.clear(); Astar(node1, node2, sit1, &path); /* display path */ // cout << "*** path:" << endl; // for (deque<MovementNode*>::iterator it = path.begin(); it < path.end(); ++it) { // cout << " -> " << (*it)->toString() << endl; // } /* * compute the directions */ ans->clear(); for (deque<MovementNode*>::iterator it = path.begin(); it < path.end(); ++it) { // determine the differences in x and y coord end_coordo = (*it)->coordo, begin_coordo = (*it)->father->coordo; direction curr_dir = convert_coord_diffs_to_direction(begin_coordo, end_coordo, sit1->WIDTH); // push the result ans->push_back(curr_dir); } /* add the direction between the final state and sit2 */ direction last_dir = convert_coord_diffs_to_direction(box_move.begin, box_move.end, sit1->WIDTH); // cout << "last_dir:" << (int) last_dir << endl; ans->push_back(last_dir); /* clean the useless nodes */ set<MovementNode*> to_clean; to_clean.insert(openlist.begin(), openlist.end()); to_clean.insert(closedlist.begin(), closedlist.end()); to_clean.insert(node1); to_clean.insert(node2); // cout << "to clean:" << endl; for (set<MovementNode*>::iterator it = to_clean.begin(); it != to_clean.end(); ++it) { // cout << " ->" << (*it)->toString() << endl; delete *it; } }
/////////////////////////////////////////////////////////////////////////////// // CalcNormal: calculate the world space normal of the vertex at (i,j) void CTerrain::CalcNormal(ssize_t i, ssize_t j, CVector3D& normal) const { CVector3D left, right, up, down; // Calculate normals of the four half-tile triangles surrounding this vertex: // get position of vertex where normal is being evaluated CVector3D basepos; CalcPosition(i, j, basepos); if (i > 0) { CalcPosition(i-1, j, left); left -= basepos; left.Normalize(); } if (i < m_MapSize-1) { CalcPosition(i+1, j, right); right -= basepos; right.Normalize(); } if (j > 0) { CalcPosition(i, j-1, up); up -= basepos; up.Normalize(); } if (j < m_MapSize-1) { CalcPosition(i, j+1, down); down -= basepos; down.Normalize(); } CVector3D n0 = up.Cross(left); CVector3D n1 = left.Cross(down); CVector3D n2 = down.Cross(right); CVector3D n3 = right.Cross(up); // Compute the mean of the normals normal = n0 + n1 + n2 + n3; float nlen=normal.Length(); if (nlen>0.00001f) normal*=1.0f/nlen; }
double IK::Update(double timestep) { double ret; CalcPosition(); #ifdef MEASURE_TIME clock_t t1 = clock(); #endif calc_jacobian(); calc_feedback(); #ifdef MEASURE_TIME clock_t t2 = clock(); calc_jacobian_time += (double)(t2 - t1) / (double)CLOCKS_PER_SEC; #endif ret = solve_ik(); #ifdef MEASURE_TIME solve_ik_time += (double)(clock() - t2) / (double)CLOCKS_PER_SEC; #endif Integrate(timestep); CalcPosition(); return ret; }
void RichEditBkImg::DrawObject(IRenderTarget * pRT) { if (m_bDirty) { // 等所依赖的前一个/后一个兄弟节点先更新位置信息完毕 CalcPosition(m_itemPos, m_nPosCount); } CRect rcHost = m_pObjectHost->GetHostRect(); CRect rcTemp = rcHost; if (rcHost.IntersectRect(m_rcObj,rcTemp)) { SSkinImgFrame * pSkin = ImageProvider::GetImage(m_strSource); if (pSkin) { pSkin->Draw(pRT, m_rcObj, 0); } } }
int CNvrFileReader::SetTime(j_uint64_t s_time, j_uint64_t e_time) { int nRet = J_OK; nRet = ListRecord(s_time, e_time); if (nRet != J_OK) { return nRet; } nRet = CalcPosition(s_time); if (nRet != J_OK) { return nRet; } m_bGoNext = true; m_nextTimeStamp = s_time * 1000; return J_OK; }
static void TSLookup(const int nUs, const int nThem, const int UNUSED(nTSP), const int UNUSED(nTSC), short int arEquity[4], const int n, const int fCubeful, FILE * pfTmp) { int iPos = CalcPosition(nUs, nThem, n); unsigned char ac[8]; int i; unsigned short int us; /* seek to position */ if (fseek(pfTmp, iPos * (fCubeful ? 8 : 2), SEEK_SET) < 0) { perror("temp file"); exit(-1); } if (fread(ac, 1, 8, pfTmp) < 8) { if (errno) perror("temp file"); else fprintf(stderr, "error reading temp file\n"); exit(-1); } /* re-position at EOF */ if (fseek(pfTmp, 0L, SEEK_END) < 0) { perror("temp file"); exit(-1); } for (i = 0; i < (fCubeful ? 4 : 1); ++i) { us = (unsigned short) (ac[2 * i] | ac[2 * i + 1] << 8); arEquity[i] = us - 0x8000; } ++cLookup; }
static int CalcPosition(const int i, const int j, const int n) { int k; if (i + j < n) k = (i + j) * (i + j + 1) / 2 + j; else k = n * n - CalcPosition(n - 1 - i, n - 1 - j, n - 1) - 1; #if 0 if (n == 6) { fprintf(stderr, "%2d ", k); if (j == n - 1) fprintf(stderr, "\n"); } #endif return k; }
static void generate_ts(const int nTSP, const int nTSC, const int fHeader, const int fCubeful, const int nHashSize, bearoffcontext * pbc, FILE * output) { int i, j, k; int iPos; int n; short int asiEquity[4]; xhash h; FILE *pfTmp; unsigned char ac[8]; char *tmpfile; int fTTY = isatty(STDERR_FILENO); pfTmp = GetTemporaryFile(NULL, &tmpfile); if (pfTmp == NULL) exit(2); /* initialise xhash */ if (XhashCreate(&h, nHashSize / (fCubeful ? 8 : 2))) { fprintf(stderr, _("Error creating xhash with %d elements\n"), nHashSize / (fCubeful ? 8 : 2)); exit(2); } XhashStatus(&h); /* write header information */ if (fHeader) { char sz[41]; sprintf(sz, "gnubg-TS-%02d-%02d-%1dxxxxxxxxxxxxxxxxxxxxxxx\n", nTSP, nTSC, fCubeful); fputs(sz, output); } /* generate bearoff database */ n = Combination(nTSP + nTSC, nTSC); iPos = 0; /* positions above diagonal */ for (i = 0; i < n; i++) { for (j = 0; j <= i; j++, ++iPos) { BearOff2(i - j, j, nTSP, nTSC, asiEquity, n, fCubeful, &h, pbc, pfTmp); for (k = 0; k < (fCubeful ? 4 : 1); ++k) WriteEquity(pfTmp, asiEquity[k]); XhashAdd(&h, (i - j) * n + j, asiEquity, fCubeful ? 8 : 2); } if (fTTY) fprintf(stderr, "%d/%d \r", iPos, n * n); } /* positions below diagonal */ for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++, ++iPos) { BearOff2(i + n - j, j, nTSP, nTSC, asiEquity, n, fCubeful, &h, pbc, pfTmp); for (k = 0; k < (fCubeful ? 4 : 1); ++k) WriteEquity(pfTmp, asiEquity[k]); XhashAdd(&h, (i + n - j) * n + j, asiEquity, fCubeful ? 8 : 2); } if (fTTY) fprintf(stderr, "%d/%d \r", iPos, n * n); } putc('\n', stderr); XhashStatus(&h); XhashDestroy(&h); /* sort file from ordering: * * 136 123 * 258 to 456 * 479 789 * */ for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { unsigned int count = fCubeful ? 8 : 2; k = CalcPosition(i, j, n); fseek(pfTmp, count * k, SEEK_SET); if (fread(ac, 1, count, pfTmp) != count || fwrite(ac, 1, count, output) != count) { fprintf(stderr, "failed to read from or write to database file\n"); exit(3); } } } fclose(pfTmp); g_unlink(tmpfile); }