void SteamVR::UpdateCamFromTracker(CCamera* cam, int eye) { vr::HmdMatrix34_t pose; vr::HmdTrackingResult eResult; mVRHmd->GetTrackerFromHeadPose(0, &pose, &eResult); Matrix3 rot(pose.m[0][0], pose.m[0][1], pose.m[0][2], pose.m[1][0], pose.m[1][1], pose.m[1][2], pose.m[2][0], pose.m[2][1], pose.m[2][2]); Vector3 eyePos(pose.m[0][3], pose.m[1][3], pose.m[2][3]); eyePos.z *= -1; // Need to negate z - LHS Quaternion orientation = ToQuaternion(rot); orientation.Invert(); orientation.z *= -1; Vector3 upVec = orientation.RotatedVector(Vector3::cYAxis); Vector3 forwardVec = orientation.RotatedVector(Vector3::cZAxis); CTransform* camTransform = cam->gameObject->transform; mEyePos[eye] = camTransform->GetGlobalPosition() + eyePos; mView[eye] = Math::LookAtLH(mEyePos[eye], mEyePos[eye] + forwardVec, upVec); camTransform->SetPosition(mEyePos[eye]); camTransform->SetRotationFromQuaternion(orientation); // Calculates new frustum and assigns oculus view and proj matrix cam->ComputeOculusFrustum(mView[eye], mProj[eye], mOrthoProj[eye]); }
//******************************************** // Copy //******************************************** void CTransform::Copy(CTransform &transform) { SetScale(transform.GetScale()); SetTranslation(transform.GetTranslation()); SetRotation(transform.GetRotation()); SetValueRotation(transform.GetValueRotation()); }
void CKinematicFlee::move(DynamicMovement& currentProperties) { CTransform* transf = static_cast<CTransform*>(m_entity->getComponentByName(TRANSFORM_COMP)); currentProperties.linearSpeed = transf->getPosition() - m_target; currentProperties.linearAccel = currentProperties.linearAccel + currentProperties.linearAccel.crossProduct(Vector3(0.0f, 1.0f, 0.0f)); currentProperties.linearSpeed.normalise(); currentProperties.linearSpeed *= m_maxLinearSpeed; }
void CKinematicSeek::move(DynamicMovement& currentProperties) { CTransform* transf = static_cast<CTransform*>(m_entity->getComponentByName(TRANSFORM_COMP)); currentProperties.linearSpeed = m_target - transf->getPosition(); if (currentProperties.linearSpeed.length() > m_maxLinearSpeed) { currentProperties.linearSpeed.normalise(); currentProperties.linearSpeed *= m_maxLinearSpeed; } }
// *************************************************************************** void UTransform::unfreezeHRC() { CTransform *object = getObjectPtr(); while (object) { object->unfreezeHRC(); object = object->hrcGetParent(); } }
void CKinematicArrive::move(DynamicMovement ¤tProperties) { CTransform* transf = static_cast<CTransform*>(m_entity->getComponentByName(TRANSFORM_COMP)); currentProperties.linearSpeed = (m_target - transf->getPosition()); currentProperties.linearSpeed /= IMovement::ATTENUATION; if (currentProperties.linearSpeed.squaredLength() > m_maxLinearSpeed2) { currentProperties.linearSpeed.normalise(); currentProperties.linearSpeed *= m_maxLinearSpeed; } }
// *************************************************************************** UInstanceGroup *UTransform::getClusterSystem () const { CTransform *object = getObjectPtr(); CInstanceGroup *ig= object->getClusterSystem(); if(ig==((CInstanceGroup*)-1)) return ((UInstanceGroup*)-1); else if(ig==NULL) return NULL; else return ig->getUserInterface(); }
void CKinematicAlignToTarget::move(DynamicMovement& currentProperties) { CTransform* transf = static_cast<CTransform*>(m_entity->getComponentByName(TRANSFORM_COMP)); Vector3 vec(m_target - transf->getPosition()); currentProperties.angularSpeed = (atan2(-vec.x, -vec.z) - transf->getYaw());// currentProperties.angularSpeed = AI::CAI::correctAngle(currentProperties.angularSpeed); //currentProperties.angularSpeed /= IMovement::ATTENUATION; if (abs(currentProperties.angularSpeed) > m_maxAngularSpeed) { currentProperties.angularSpeed = Ogre::Math::Sign(currentProperties.angularSpeed) * m_maxAngularSpeed; } }
void StateLevel::buildTurret( const Vec2f& pos, const TurretData& data ) { Entity entity = ENTITY_MANAGER.newEntity( Entity::Entity_Turret ); // Initialize transform component CTransform* transform = entity.add<CTransform>(); transform->setPos( pos ); transform->setSize( data.base.buildCells * BuildingGrid::c_cellSize ); // Initialize stats component CStats* stats = entity.add<CStats>(); stats->addStat( Stat::SID_Health ); stats->addStat( Stat::SID_Armor ); stats->addStat( Stat::SID_AValueMin ); stats->addStat( Stat::SID_AValueMax ); stats->addStat( Stat::SID_ASpeed ); stats->addStat( Stat::SID_ARange ); // Todo: Set stat values from TurretData ( only merged health and armor, oh and price ) stats->getStat( Stat::SID_Health )->setBase( data.getHealth() ); stats->getStat( Stat::SID_Armor )->setBase( data.getArmor() ); // Setup turret component CTurret* turret = entity.add<CTurret>(); turret->setup( data ); turret->price = data.getPrice(); // Setup scene node component // Temporary: Requires a new way of connecting ECS to SceneGraph CNode* cNode = entity.add<CNode>(); Node* node = new CNode( *cNode ); cNode->setParent( m_turretNode ); node->setID( entity.ID ); node->enableAutoDelete( true ); m_turretNode->addChild( node ); // Setup sprites of all turret parts // and add them to the Scene graph Sprite* baseSprite = turret->base.getSprite(); baseSprite->setSprite( data.base.spriteID ); baseSprite->setCenter( ( data.base.buildCells * BuildingGrid::c_cellSize ) / 2 ); node->addChild( baseSprite, "TBase" ); for( short i = 0; i < turret->headCount; i++ ) { Sprite* headSprite = turret->head[ i ].getSprite(); headSprite->setSprite( data.head[ i ].spriteID ); headSprite->setPos( data.base.headPosition[ i ] ); headSprite->setOrigin( data.head[ i ].spriteOffset ); node->addChild( headSprite, "THead_" + std::to_string( i ) ); } }
void CDlgEditSymbols::OnBnClickedParsebutton() { CString text, format; COpenScrapeDoc *pDoc = COpenScrapeDoc::GetDocument(); CTransform trans; m_Titletext.GetWindowText(text); m_Value.GetWindowText(format); trans.ParseStringBSL(text, format, &results); m_ParseResults.SetWindowText(results.GetString()); }
void CCollider::calcDist(CTransform & transform) { m_diameter = transform.GetScale(); Vector3 centerPos; centerPos.z = transform.GetTranslate().z; // Determine center x pos if (m_xStart == X_LEFT) { centerPos.x = transform.GetTranslate().x + m_diameter.x * 0.5f; } else if (m_xStart == X_MIDDLE) { centerPos.x = transform.GetTranslate().x; } else if (m_xStart == X_RIGHT) { centerPos.x = transform.GetTranslate().x - m_diameter.x * 0.5f; } // Determine center y pos if (m_yStart == Y_BOTTOM) { centerPos.y = transform.GetTranslate().y + m_diameter.y * 0.5f; } else if (m_yStart == Y_MIDDLE) { centerPos.y = transform.GetTranslate().y; } else if (m_yStart == Y_TOP) { centerPos.y = transform.GetTranslate().y - m_diameter.y * 0.5f; } m_position = centerPos; }
void ParseXML( std::vector< GameObject* > &gos, const char *filename, const Vectormath::Aos::Transform3 &transform, WorldDB *worlddb ) { char *xml; if ( !PHYSFS_readFile( filename, (void**)&xml ) ) { return; } pugi::xml_document doc; pugi::xml_parse_result result = doc.parse( xml );//load_file(filename); if ( result ) { pugi::xml_node scene = doc.child( "Scene" ); if ( scene ) { for (pugi::xml_node go = scene.child("GameObject"); go; go = go.next_sibling("GameObject")) { GameObject *gameObject = new GameObject(worlddb); gameObject->Bind( NULL, NULL ); for (pugi::xml_node tag = go.first_child(); tag; tag = tag.next_sibling()) { if ( stricmp( tag.name(), "Component" ) == 0 ) { Component *c = gameObject->AddComponent( tag.attribute("name").value(), tag.attribute("type").value() ); c->Bind(NULL,NULL); for (pugi::xml_node ctag = tag.first_child(); ctag; ctag = ctag.next_sibling()) { c->Bind( ctag.name(), ctag.child_value() ); } CTransform *t = dynamic_cast<CTransform*>( c ); if ( t ) { t->setLocal( transform * t->local() ); } } else { gameObject->Bind( tag.name(), tag.child_value() ); } } gameObject->Enter(); gos.push_back( gameObject ); } } } free( xml ); }
void PPhysics2D::v_updateEntity(entityID id, const GameTime& gameTime) { CRigidBody *body = getEntityAs<CRigidBody>(id); CTransform *transform = getEntityAs<CTransform>(id); //transform->m_position.addScaledVector(body->m_velocity, gameTime.getElapsedSecond()); transform->setX(transform->getX() + body->m_velocity.x * gameTime.getElapsedSecond()); transform->setY(transform->getY() + body->m_velocity.y * gameTime.getElapsedSecond()); if (body->m_bApplyGravity) { body->addForce(glm::vec2(.0f, 200.0f)); } //body->m_velocity.addScaledVector(body->m_forceAccum, gameTime.getElapsedSecond()); body->m_velocity.x += body->m_forceAccum.x * gameTime.getElapsedSecond(); body->m_velocity.y += body->m_forceAccum.y * gameTime.getElapsedSecond(); body->m_velocity *= powf(body->m_damping, gameTime.getElapsedSecond()); body->clearForce(); }
void CGame::addEnemies() { const int id = mGameObjects.size(); ///@todo: add later: read these params from a style file const std::size_t numOfCircles = 16; const std::size_t numOfSegments = 32; const std::string filePath = "../AeroSimulator/res/smile.dds"; const SSphereParams params(2.0f, numOfCircles, numOfSegments, glm::pi<float>(), 2.0f * glm::pi<float>()); SRenderableData data(mShaders[eShaders::TEXTURE_SHADER], ¶ms, filePath, glm::vec4()); CTransform transform; transform.setTranslate(glm::vec3(0.0f, 30.0f, -10.0f)); transform.setRotate(glm::vec3(0.0f, 90.0f, 0.0f)); tGoSharedPtr pObject(new CFigure(id, eGameObjects::AIRPLANE, CFigure::eFigure::SPHERE, data, transform)); addObject(id, pObject, "* CGame::addEnemy "); }
void CGame::addCameras() { // currently just 1 camera const int id = mGameObjects.size(); const glm::vec3 translate(0.0f, 29.0f, -3.0f); const glm::vec3 rotate(0.0f, 180.0f, 0.0f); CTransform transform; transform.setTranslate(translate); transform.setRotate(rotate); ///@todo: add the type and the id of the game object to the constructor of the CCamera const SFrustum frustum(45.0f, 16.0f / 9.0f, 0.1f, 1100.0f); std::shared_ptr<CCamera> camera( new CCamera(id, CAMERA, transform, frustum)); if (camera) { GCameraManager.addCamera(camera); LOG("* CGame: a camera has been just added to the camera manager."); addObject(id, camera, "* CGame::addCamera() "); } }
// *************************************************************************** void UTransform::parent(UTransform newFather) { CTransform *object = getObjectPtr(); if (object->getForceClipRoot()) { nlwarning("Transform has been flagged to be glued to the root, can't change parent. See UTransform::setForceClipRoot(bool)."); return; } if(!newFather.empty()) { // link me to other. CTransform *other= newFather.getObjectPtr(); if(other->getOwnerScene()!=object->getOwnerScene()) nlerror("Try to parent 2 object from 2 differnet scenes!!"); other->hrcLinkSon( object ); } else { // link me to Root. object->getOwnerScene()->getRoot()->hrcLinkSon( object ); } }
// *************************************************************************** void UTransform::getLastParentClusters(std::vector<CCluster*> &clusters) const { CTransform *object = getObjectPtr(); CScene *scene = object->getOwnerScene(); // look in the list of parent of the transform object and extract the CCluster parents if (scene == NULL) return; CClipTrav &clipTrav= scene->getClipTrav(); uint num= object->clipGetNumParents(); for(uint i=0;i<num;i++) { CCluster *pcluster = dynamic_cast<CCluster*>(object->clipGetParent(i)); if (pcluster != NULL) clusters.push_back(pcluster); } // If the object is link to a QuadCluster, add the RootCluster to the list CTransformShape *trShp= dynamic_cast<CTransformShape*>( object ); if( trShp && trShp->isLinkToQuadCluster() ) clusters.push_back(clipTrav.RootCluster); }
void PParticuleManager::v_updateEntity(entityID id, const GameTime& gameTime) { CParticuleEmitter *e = getEntityAs<CParticuleEmitter>(id); CTransform *transform = getEntityAs<CTransform>(id); if (e->m_bActive) { e->m_elapsedRate += gameTime.getElapsedMillisecond(); if (e->m_elapsedRate > e->m_rate) { // due to custom memory allocation used by clone method, the pointer could // be null sometimes IParticule* p = e->m_particulePrototype->cloneIntoPool(); if (p != nullptr) { // TODO : cause a division per zero /*float lv = (e->m_lifetimeVariation > 0) ? MathUtils::randint(e->m_lifetimeVariation * 2) - e->m_lifetimeVariation : 0; float av = (e->m_angleVariation > 0) ? MathUtils::randint(e->m_angleVariation * 2) - e->m_angleVariation : 0; float sv = (e->m_speedVariation > 0) ? MathUtils::randint(e->m_speedVariation * 2) - e->m_speedVariation : 0; float pv = (e->m_spawnPositionVariation > 0) ? MathUtils::randint(e->m_spawnPositionVariation * 2) - e->m_spawnPositionVariation : 0;*/ float lv , av, sv, pv = 0; p->m_x = transform->getX() + pv; p->m_y = transform->getY() + pv; p->m_elapsed = 0; p->m_lifetime = e->m_lifetime + lv; glm::vec2 velocity = MathUtils::fromPolar(e->m_angle + av, e->m_speed + sv); p->m_vx = velocity.x; p->m_vy = velocity.y; p->m_gravityApplied = e->m_bIsGravityApplied; m_particulesEmitted.push_back(p); } e->m_elapsedRate = 0; } } }
void CCollider::calcAABB(CTransform & transform) { Vector3 scale = transform.GetScale(); Vector3 centerPos; centerPos.z = transform.GetTranslate().z; // Determine center x pos if (m_xStart == X_LEFT) { centerPos.x = transform.GetTranslate().x + scale.x * 0.5f; } else if (m_xStart == X_MIDDLE) { centerPos.x = transform.GetTranslate().x; } else if (m_xStart == X_RIGHT) { centerPos.x = transform.GetTranslate().x - scale.x * 0.5f; } // Determine center y pos if (m_yStart == Y_BOTTOM) { centerPos.y = transform.GetTranslate().y + scale.y * 0.5f; } else if (m_yStart == Y_MIDDLE) { centerPos.y = transform.GetTranslate().y; } else if (m_yStart == Y_TOP) { centerPos.y = transform.GetTranslate().y - scale.y * 0.5f; } Vector3 pos = centerPos; m_minBound.Set(pos.x - (scale.x * 0.5f), pos.y - (scale.y * 0.5f), pos.z - (scale.z * 0.5f)); m_maxBound.Set(pos.x + (scale.x * 0.5f), pos.y + (scale.y * 0.5f), pos.z + (scale.z * 0.5f)); }
void PPlayer::v_updateEntity(entityID id, const GameTime& gameTime) { CPlayer *player = getEntityAs<CPlayer>(id); CTransform *transform = getEntityAs<CTransform>(id); CRigidBody *body = getEntityAs<CRigidBody>(id); if (player->m_bAlive) { player->m_elapsedTime += gameTime.getElapsedMillisecond(); double temp = 0.25f * sin((double)(MathUtils::TWO_PI * 0.001 * player->m_elapsedTime + 0)); // set screen position with floating in account player->m_floatingAmount = temp; transform->setOffsetY(transform->getOffsetY() + player->m_floatingAmount); if (player->m_bSpeedUp) { if (player->m_actualThrustAmount < player->m_speedupThrustAmount) { player->m_actualThrustAmount += 350 * gameTime.getElapsedSecond(); } player->m_bSpeedUp = false; } else { if (player->m_actualThrustAmount < player->m_maxThrustAmount) { player->m_actualThrustAmount += 150 * gameTime.getElapsedSecond(); } else if (player->m_actualThrustAmount > player->m_maxThrustAmount) { player->m_actualThrustAmount -= 250 * gameTime.getElapsedSecond(); } } body->m_velocity.y = sin(transform->getRotation()) * player->m_actualThrustAmount; body->m_velocity.x = player->m_forward.x * cos(transform->getRotation()) * player->m_actualThrustAmount; if (player->m_cooldown > 0) { player->m_cooldown -= gameTime.getElapsedMillisecond(); // Design issue : Draw with UpdateProcess Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, 75, 5, 0xFF, 0xFF, 0xFF); Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, (1 - (player->m_cooldown / player->m_defaultCooldown)) * 75, 5, 0x66, 0x99, 0x99); } } }
int testTransform(string transType) { int fail = 0; CTransform* trans = CTransform::getNewTransformPointer(transType); int ncols = 9; double a[19] = {-1e16, -1e8, -1e4, -100, -1, -0.1, -1e-5, -1e-9, -1e-13, 0, 1e-13, 1e-9, 1e-5, 0.1, 1, 100, 1e4, 1e8, 1e16}; double x[19]; double newa[19]; double g[19]; cout << "Transform " << transType << endl; for(int i=0; i<9; i++) { x[i] = trans->atox(a[i]); newa[i] = trans->xtoa(x[i]); if(newa[i]!=a[i]) { cout << "FAIL: " << endl; cout << "a: " << a[i] << " x: " << x[i] << " newa: " << newa[i] << endl; fail++; } else cout << "atox -> xtoa check passed: a: " << a[i] << endl; g[i] = trans->gradfact(x[i]); double diff = 1e-6; double aplus = a[i]+diff; double xplus = trans->atox(aplus); double aminus = a[i]-diff; double xminus = trans->atox(aminus); double gdiff = (xplus - xminus)/(2*diff); if(abs(gdiff-g[i])>2*diff) { cout << "FAIL: Gradient: " << "g: " << g[i] << " gdiff: " << gdiff << endl; } else cout << "Gradient check passed: a: " << a[i] << endl; } ptransforms->addTransform(trans, 1); ptransforms->addTransform(trans, 2); return fail; }
void UTransform::setTransparencyPriority(uint8 priority) { CTransform *object = getObjectPtr(); object->setTransparencyPriority(priority); }
// *************************************************************************** float UTransform::getShadowMapDirectionZThreshold() const { CTransform *object = getObjectPtr(); return object->getShadowMapDirectionZThreshold(); }
// *************************************************************************** void UTransform::freezeHRC() { CTransform *object = getObjectPtr(); object->freezeHRC(); }
void CDlgScraperOutput::DoBitblt(HBITMAP bitmap, RMapCI r_iter) { CDC *pDC = m_ScraperBitmap.GetDC(); HDC hdcControl = *pDC; HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); HDC hdcCompat1 = CreateCompatibleDC(hdcScreen); HDC hdcCompat2 = CreateCompatibleDC(hdcScreen); HBITMAP hbm2 = NULL, old_bitmap1 = NULL, old_bitmap2 = NULL; int w = 0, h = 0, zoom = 0; RECT rect = {0}; CBrush gray_brush, *pTempBrush = NULL, oldbrush; CPen null_pen, *pTempPen = NULL, oldpen; CString res = ""; CTransform trans; if (in_startup) { DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); return; } m_ScraperBitmap.GetWindowRect(&rect); // Erase control area gray_brush.CreateSolidBrush(COLOR_GRAY); pTempBrush = (CBrush*)pDC->SelectObject(&gray_brush); oldbrush.FromHandle((HBRUSH)pTempBrush); // Save old brush null_pen.CreatePen(PS_NULL, 0, COLOR_BLACK); pTempPen = (CPen*)pDC->SelectObject(&null_pen); oldpen.FromHandle((HPEN)pTempPen); // Save old pen pDC->Rectangle(1, 1, rect.right-rect.left, rect.bottom-rect.top); pDC->SelectObject(oldbrush); pDC->SelectObject(oldpen); // return if all we needed to do was erase display if (bitmap == NULL) { DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); return; } // load bitmap into 1st DC and stretchblt to 2nd DC old_bitmap1 = (HBITMAP) SelectObject(hdcCompat1, bitmap); zoom = m_Zoom.GetCurSel()==0 ? 1 : m_Zoom.GetCurSel()==1 ? 2 : m_Zoom.GetCurSel()==2 ? 4 : m_Zoom.GetCurSel()==3 ? 8 : m_Zoom.GetCurSel()==4 ? 16 : 1; w = (r_iter->second.right - r_iter->second.left) * zoom; h = (r_iter->second.bottom - r_iter->second.top) * zoom; hbm2 = CreateCompatibleBitmap(hdcScreen, w, h); old_bitmap2 = (HBITMAP) SelectObject(hdcCompat2, hbm2); StretchBlt( hdcCompat2, 0, 0, w, h, hdcCompat1, 0, 0, r_iter->second.right - r_iter->second.left, r_iter->second.bottom - r_iter->second.top, SRCCOPY ); // Copy 2nd DC to control BitBlt( hdcControl, 1, 1, rect.right-rect.left-2, rect.bottom-rect.top-2, hdcCompat2, 0, 0, SRCCOPY ); // Output result trans.DoTransform(r_iter, hdcCompat1, &res); m_ScraperResult.SetWindowText(res); // Clean up SelectObject(hdcCompat1, old_bitmap1); SelectObject(hdcCompat2, old_bitmap2); DeleteObject(hbm2); DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); }
// *************************************************************************** void UTransform::setShadowMapDirectionZThreshold(float zthre) { CTransform *object = getObjectPtr(); object->setShadowMapDirectionZThreshold(zthre); }
// *************************************************************************** void UTransform::setShadowMapMaxDepth(float depth) { CTransform *object = getObjectPtr(); object->setShadowMapMaxDepth(depth); }
// *************************************************************************** bool UTransform::fastIntersect(const NLMISC::CVector &p0, const NLMISC::CVector &dir, float &dist2D, float &distZ, bool computeDist2D) { CTransform *object = getObjectPtr(); return object->fastIntersect(p0, dir, dist2D, distZ, computeDist2D); }
// *************************************************************************** bool UTransform::supportFastIntersect() const { CTransform *object = getObjectPtr(); return object->supportFastIntersect(); }
// *************************************************************************** float UTransform::getShadowMapMaxDepth() const { CTransform *object = getObjectPtr(); return object->getShadowMapMaxDepth(); }