void ClientConnected(struct Connection* client) { cout << "Accepted connection from " << inet_ntoa(client->addr.sin_addr) << endl; assert(pairs_.count(client->sock) == 0); // We've received a client connection; Establish a new connection to the // remote address int remote_sock; if ((remote_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { close(client->sock); err(EX_OSERR, "socket()"); } // TODO: Open remote connection asyncronously cout << "Openining new remote connection" << endl; if (connect(remote_sock, (const struct sockaddr*)&remote_, sizeof(struct sockaddr_in)) != 0) { err(EX_OSERR, "connect()"); } cout << "Connection established. (remote=" << remote_sock << ",client=" << client->sock << ")" << endl; // Setup socket pairs pairings SetForward(client->sock); SetForward(remote_sock); pairs_[remote_sock] = client->sock; pairs_[client->sock] = remote_sock; }
void GLCamera::SetLookAt(glm::vec3 _target) { glm::vec3 forward; forward.x = _target.x - m_position.x; forward.y = _target.y - m_position.y; forward.z = _target.z - m_position.z; SetForward(forward); }
GLCamera::GLCamera(float _fovy, int _width,int _height, float _nearZ, float _farZ) { //m_ViewPort.MinDepth = 0.0f; //m_ViewPort.MaxDepth = 1.0f; m_width = _width; m_height = _height; m_aspectRatio = (float)m_width / (float)m_height; m_FOVy = _fovy;//2 * glm::atan(glm::tan(0.5f * _fovy) * m_aspectRatio); m_nearZ = _nearZ; m_farZ = _farZ; m_position = glm::vec3(0, 0, 0); m_forward = glm::vec3(0, 0, -1); m_right = glm::vec3(1, 0, 0); m_up = glm::vec3(0, 1, 0); UpdateView(); UpdateProjection(); SetForward(glm::vec3(0,0,-1)); }
void Transform::Rotate(glm::vec3 axis, float angle) { SetForward(glm::vec3(glm::rotate(glm::mat4(), angle, axis) * glm::vec4(forward, 1.0f))); }
void Transform::LookAt(glm::vec3 target) { SetForward(target - position); }
void AglMatrix::SetBackward(const AglVector3& pValue) { SetForward(-pValue); }
inline void VMatrix::SetBasisVectors( const Vector &vForward, const Vector &vLeft, const Vector &vUp ) { SetForward( vForward ); SetLeft( vLeft ); SetUp( vUp ); }
SceneGraphManager *createGraph() { int lightIndex = SINGLETONINSTANCE(LightingManager)->getAvailableLightIndex(); SINGLETONINSTANCE(LightingManager)->lights[lightIndex].enable(true); SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setDiffuse(0.5f,0.5f,0.5f, 1.0f); SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setSpecular(0.7f,0.2f,0.1f, 1.0f); SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setAmbient(0.2f,0.2f,0.2f, 1.0f); SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setPos(10.0f,10.0f,10.0f); auto root = new Object(); root->Name = "Root"; root->transformation->Reset(); float mapWidth = 40.0f; auto ground = new Object(); ground->Name = "Ground"; ground->model = SINGLETONINSTANCE( MediaManager )->ground; ground->transformation->Reset(); ground->SetPos2D(20.0f,20.0f); ground->SetScale(mapWidth,mapWidth,1.0f); SINGLETONINSTANCE(PathPlanner)->StartUp(mapWidth); auto underground = new Object(); underground->Name = "Underground"; underground->model = SINGLETONINSTANCE( MediaManager )->ground; underground->transformation->Reset(); underground->getPos()->SetZ(-10.0f); underground->SetScale(mapWidth*10,mapWidth*10,1.0f); Rectangle physicsBox(Point(-0.5f, -0.5f), 1.0f, 1.0f); auto box = new Object(); box->Name = "Box"; box->model = SINGLETONINSTANCE( MediaManager )->boxModel; StaticObjectModel* tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box->physicsModel = tempStaticObject; box->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box->SetPos2D(20.0f, 0.0f); box->SetScale(40.0f, 1.0f, 3.0f); //box->physicsModel->debug(); auto box1 = new Object(); box1->Name = "Box1"; tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box1->model = SINGLETONINSTANCE( MediaManager )->boxModel; box1->physicsModel = tempStaticObject; box1->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box1->SetPos2D(20.0f, 40.0f); box1->SetScale(40.0f, 1.0f, 3.0f); auto box2 = new Object(); box2->Name = "Box2"; box2->model = SINGLETONINSTANCE( MediaManager )->boxModel; tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box2->physicsModel = tempStaticObject; box2->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box2->SetPos2D(0.0f, 20.0f); box2->SetScale(1.0f, 40.0f, 3.0f); auto box3 = new Object(); box3->Name = "Box3"; box3->model = SINGLETONINSTANCE( MediaManager )->boxModel; tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box3->physicsModel = tempStaticObject; box3->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box3->SetPos2D(40.0f, 20.0f); box3->SetScale(1.0f, 40.0f, 3.0f); auto box4 = new Object(); box4->Name = "Box4"; box4->model = SINGLETONINSTANCE( MediaManager )->boxModel; tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box4->physicsModel = tempStaticObject; box4->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box4->SetPos2D(27.0f, 15.0f); box4->SetScale(1.0f, 30.0f, 3.0f); auto box5 = new Object(); box5->Name = "Box5"; box5->model = SINGLETONINSTANCE( MediaManager )->boxModel; tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE); box5->physicsModel = tempStaticObject; box5->physicsModel->InitializeAsRectangle(physicsBox); SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject); box5->SetPos2D(13.0f, 25.0f); box5->SetScale(1.0f, 30.0f, 3.0f); root->children->push_back(*underground); root->children->push_back(*ground); root->children->push_back(*box); root->children->push_back(*box1); root->children->push_back(*box2); root->children->push_back(*box3); root->children->push_back(*box4); root->children->push_back(*box5); SINGLETONINSTANCE(PhysicsSystem)->SetStaticPathMap(); Point forward; forward.X = 0; forward.Y = -1; forward = forward.GetNormalizedPoint(); auto player = new Object(); SINGLETONINSTANCE(PlayerInteraction)->StartUp(player); player->Name = "Player"; player->model = SINGLETONINSTANCE( MediaManager )->crazyModel; MovingObjectModel* tempMovingObject = new MovingObjectModel(CIRCULARSHAPE, PLAYERTYPE, forward, player); player->physicsModel = tempMovingObject; Circle circle(Point(0.0f,0.0f),0.5f); player->physicsModel->InitializeAsCircle(circle); SINGLETONINSTANCE(PhysicsSystem)->AddMovingObject(tempMovingObject); player->SetPos2D(15,20); player->Rotate(90.0f, 1.0f, 0.0f, 0.0f); player->SetForward(0.0f, 1.0f); player->setLookAt2D(forward.X,forward.Y); root->children->push_back(*player); player->physicsModel->SetTargetPosition(new Point(50,5)); auto camera = new Camera(); camera->Position.SetX(20); camera->Position.SetY(5); camera->Position.SetZ(50); camera->LookAt.SetX(20); camera->LookAt.SetY(20); camera->LookAt.SetZ(-1); camera->Up.SetX(0); camera->Up.SetY(1); camera->Up.SetZ(0); SceneGraphManager *sceneGraph = new SceneGraphManager(camera, root); return sceneGraph; }