Button::Button() { m_BackColor = irr::video::SColor(255, 0, 0, 0); m_FrontColor = irr::video::SColor(255, 255, 255, 255); m_Topleft = v2d(0, 0); m_BotRight = v2d(0, 0); borderthickness = 1; m_backdrop = GraphicsRect(m_Topleft.X, m_Topleft.Y, m_BotRight.X, m_BotRight.Y); m_backdrop.SetColor(m_BackColor); m_main = GraphicsRect(m_Topleft.X + borderthickness, m_Topleft.Y + borderthickness, m_BotRight.X - borderthickness, m_BotRight.Y - borderthickness); m_main.SetColor(m_FrontColor); m_TextColor = irr::video::SColor(255, 0, 0, 0); pressed = false; }
void SphereWorld::allUCanEat(MX::Player* player) { for(auto it = collidables.begin(); it!=collidables.end(); ++it) { if (!(*it)->alive) continue; if(player->isInNeck(*it) || *it == player) continue; v2d d = (*it)->pos - player->pos; float rrit = (*it)->r; //(*it)->scaleX*(*it)->scaleX + (*it)->scaleY*(*it)->scaleY; float rrp = player->r; //player->scaleX*player->scaleX + player->scaleY*player->scaleY; if(norm(d) < rrit*rrit + rrp*rrp + 2*rrit*rrp) (*it)->onEat(player); } static const float MARGIN = 50.0f; if(player->pos.x < MARGIN) player->bounce(v2d(1.0f, 0.0f)); else if(player->pos.x > 1280-MARGIN) player->bounce(v2d(-1.0f, 0.0f)); if(player->pos.y < MARGIN) player->bounce(v2d(0.0f, 1.0f)); else if(player->pos.y > 800-MARGIN) player->bounce(v2d(0.0f, -1.0f)); }
void FiniteElementDemo::physicsDebugDraw() { { btAlignedObjectArray<btVector3FloatData> m_linePoints; btAlignedObjectArray<unsigned int> m_lineIndices; //geometry::Tetrahedron<math::default_math_types> tet; for (int t=0;t<m_data->m_mesh1.m_tetrahedra.size();t++) { vector3_type v0d = m_data->m_mesh1.m_nodes[m_data->m_mesh1.m_tetrahedra[t].m_nodes[0]].m_coord; vector3_type v1d = m_data->m_mesh1.m_nodes[m_data->m_mesh1.m_tetrahedra[t].m_nodes[1]].m_coord; vector3_type v2d = m_data->m_mesh1.m_nodes[m_data->m_mesh1.m_tetrahedra[t].m_nodes[2]].m_coord; vector3_type v3d = m_data->m_mesh1.m_nodes[m_data->m_mesh1.m_tetrahedra[t].m_nodes[3]].m_coord; btVector3 v0(v0d(0),v0d(1),v0d(2)); btVector3 v1(v1d(0),v1d(1),v1d(2)); btVector3 v2(v2d(0),v2d(1),v2d(2)); btVector3 v3(v3d(0),v3d(1),v3d(2)); btVector3FloatData vf0,vf1,vf2,vf3; v0.serializeFloat(vf0); v1.serializeFloat(vf1); v2.serializeFloat(vf2); v3.serializeFloat(vf3); unsigned int baseIndex = m_linePoints.size(); m_linePoints.push_back(vf0); m_linePoints.push_back(vf1); m_linePoints.push_back(vf2); m_linePoints.push_back(vf3); m_lineIndices.push_back(baseIndex+0); m_lineIndices.push_back(baseIndex+1); m_lineIndices.push_back(baseIndex+0); m_lineIndices.push_back(baseIndex+2); m_lineIndices.push_back(baseIndex+0); m_lineIndices.push_back(baseIndex+3); m_lineIndices.push_back(baseIndex+1); m_lineIndices.push_back(baseIndex+2); m_lineIndices.push_back(baseIndex+2); m_lineIndices.push_back(baseIndex+3); m_lineIndices.push_back(baseIndex+1); m_lineIndices.push_back(baseIndex+3); } float debugColor[4]={0,0,0.4,1}; m_app->m_renderer->drawLines(&m_linePoints[0].m_floats[0],debugColor, m_linePoints.size(),sizeof(btVector3FloatData), &m_lineIndices[0], m_lineIndices.size(), 1); }; }
TEST(Vector2, Addition) { float fv[2] = { 1.0f, 2.0f }; FasTC::Vec2f v2f (fv); double dv[2] = { 4.3, -10.2 }; FasTC::Vec2d v2d (dv); EXPECT_NEAR((v2f + v2d).X(), 5.3, kEpsilon); EXPECT_NEAR((v2f + v2d).Y(), -8.2, kEpsilon); }
bool CLevelGraph::neighbour_in_direction (const Fvector &direction, u32 start_vertex_id) const { u32 cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1); Fbox2 box; Fvector2 identity, start, dest, dir; identity.x = identity.y = header().cell_size()*.5f; start = v2d(vertex_position(start_vertex_id)); dir = v2d(direction); dir.normalize_safe (); dest = dir; dest.mul (header().cell_size()*4.f); dest.add (start); Fvector2 temp; unpack_xz (vertex(start_vertex_id),temp.x,temp.y); float cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); const_iterator I,E; begin (cur_vertex_id,I,E); for ( ; I != E; ++I) { u32 next_vertex_id = value(cur_vertex_id,I); if ((next_vertex_id == prev_vertex_id) || !is_accessible(next_vertex_id)) continue; unpack_xz (vertex(next_vertex_id),temp.x,temp.y); box.min = box.max = temp; box.grow (identity); if (box.pick_exact(start,dir)) { Fvector2 temp; temp.add (box.min,box.max); temp.mul (.5f); float dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); if (dist > cur_sqr) continue; return (true); } } return (false); }
main() { int d,dd,i,j,k,*jj,*a,ii; //void d2brev(int, int, int []); //int b2drev(int, int []); void d2v(int, int, int, int *); int v2d(int, int, int *); int m; m=10; jj=(int *) malloc(m * sizeof(int)); a=(int *) malloc(m * sizeof(int)); /* d = dimension, dd=k^d */ scanf("%d %d %d", &k,&d,&i); while(k>0) { d2v(d,k,i,jj); printf("i=%d: ", i); for(j=1;j<=d;j++) printf(" %d", jj[j]); printf("\n"); ii=v2d(d,k,jj); printf("ii=%d\n", ii); scanf("%d %d %d", &k,&d,&i); } free(jj); free(a); }
bool FrankieScene::OnMouseDown (iEvent &ev) { if (csMouseEventHelper::GetButton (&ev) == 0 && avatarTest->physicsEnabled) { // Trying to kill Frankie // We will trace a beam to the point clicked by the mouse to check if // something is hit. Let's start by computing the beam end points. int mouseX = csMouseEventHelper::GetX (&ev); int mouseY = csMouseEventHelper::GetY (&ev); csRef<iCamera> camera = avatarTest->view->GetCamera (); csVector2 v2d (mouseX, avatarTest->g2d->GetHeight () - mouseY); csVector3 v3d = camera->InvPerspective (v2d, 10000); csVector3 startBeam = camera->GetTransform ().GetOrigin (); csVector3 endBeam = camera->GetTransform ().This2Other (v3d); // If Frankie is already dead, simply check for adding a force on him if (frankieDead) { // Trace a physical beam to find if a rigid body was hit CS::Physics::Bullet::HitBeamResult hitResult = avatarTest->bulletDynamicSystem->HitBeam (startBeam, endBeam); if (hitResult.hasHit && hitResult.body->GetType () == CS::Physics::Bullet::RIGID_BODY) { // Apply a big force at the point clicked by the mouse csVector3 force = endBeam - startBeam; force.Normalize (); hitResult.body->QueryRigidBody ()->AddForceAtPos (hitResult.isect, force * 10.0f); } return true; } // At first, test with a sector HitBeam if we clicked on an animated mesh csSectorHitBeamResult sectorResult = camera->GetSector ()->HitBeam (startBeam, endBeam, true); if (!sectorResult.mesh) return false; csRef<CS::Mesh::iAnimatedMesh> animesh = scfQueryInterface<CS::Mesh::iAnimatedMesh> (sectorResult.mesh->GetMeshObject ()); if (!animesh) return false; // OK, it's an animesh, it must be Frankie, let's kill him frankieDead = true; // Close the eyes of Frankie as he is dead animesh->SetMorphTargetWeight (animeshFactory->FindMorphTarget ("eyelids_closed"), 0.7f); // Stop the child animations, there is only the ragdoll animation node which is active lookAtNode->Stop (); // Set the ragdoll state of the CS::Animation::iBodyChain of the body and the tail as dynamic ragdollNode->SetBodyChainState (bodyChain, CS::Animation::STATE_DYNAMIC); ragdollNode->SetBodyChainState (tailChain, CS::Animation::STATE_DYNAMIC); // Update the display of the dynamics debugger if (avatarTest->dynamicsDebugMode == DYNDEBUG_COLLIDER || avatarTest->dynamicsDebugMode == DYNDEBUG_MIXED) avatarTest->dynamicsDebugger->UpdateDisplay (); // Fling the body a bit const csOrthoTransform& tc = avatarTest->view->GetCamera ()->GetTransform (); uint boneCount = ragdollNode->GetBoneCount (CS::Animation::STATE_DYNAMIC); for (uint i = 0; i < boneCount; i++) { CS::Animation::BoneID boneID = ragdollNode->GetBone (CS::Animation::STATE_DYNAMIC, i); iRigidBody* rb = ragdollNode->GetBoneRigidBody (boneID); rb->SetLinearVelocity (tc.GetT2O () * csVector3 (0.0f, 0.0f, 0.1f)); } // Trace a physical beam to find which rigid body was hit CS::Physics::Bullet::HitBeamResult hitResult = avatarTest->bulletDynamicSystem->HitBeam (startBeam, endBeam); if (hitResult.hasHit && hitResult.body->GetType () == CS::Physics::Bullet::RIGID_BODY) { // Apply a big force at the point clicked by the mouse csVector3 force = endBeam - startBeam; force.Normalize (); hitResult.body->QueryRigidBody ()->AddForceAtPos (hitResult.isect, force * 1.0f); hitResult.body->QueryRigidBody ()->SetLinearVelocity (tc.GetT2O () * csVector3 (0.0f, 0.0f, 1.0f)); } return true; } return false; }
bool CLevelGraph::create_straight_path(u32 start_vertex_id, const Fvector &start_point, const Fvector &finish_point, xr_vector<Fvector> &tpaOutputPoints, xr_vector<u32> &tpaOutputNodes, bool bAddFirstPoint, bool bClearPath) const { return (create_straight_path(start_vertex_id,v2d(start_point),v2d(finish_point),tpaOutputPoints,tpaOutputNodes,bAddFirstPoint,bClearPath)); }
Proj *projectile_new(Entity *proj, PROJECTILETYPE type) { Proj *projdata; cJSON *json, *root, *obj; FILE *file; long len; char *data; int i; file = fopen("def/projectilesconfig.txt","r"); if(!file) { slog("No file found. Projectile.c"); return; } fseek(file, 0, SEEK_END); len = ftell(file); fseek(file, 0, SEEK_SET); data = (char *) malloc(len + 1); fread(data, 1, len, file); fclose(file); json = cJSON_Parse(data); root = cJSON_GetObjectItem(json,"projectilesconfig"); if(!root) return; if(type = SHELL) obj = cJSON_GetObjectItem(root,"shell"); else if(type = FLAME) obj = cJSON_GetObjectItem(root,"flame"); else if(type = LASER) obj = cJSON_GetObjectItem(root,"laser"); proj->sprite = sprite_load(cJSON_GetObjectItem(obj,"file")->valuestring, v2d(cJSON_GetObjectItem(obj,"x")->valuedouble, cJSON_GetObjectItem(obj,"y")->valuedouble)); projdata->type = type; proj->data = projdata; for(i = 0; i < MaxProj; i++) { //if(proj } if(type = SHELL) { proj->update = &proj_update_shell; proj->think = NULL; } if(type = FLAME) { proj->update = &proj_update_flame; proj->think = NULL; } if(type = LASER) { proj->update = &proj_update_laser; proj->think = NULL; } return projdata; }