예제 #1
0
void COrbitController::MyMouseMove(int dx, int dy, int rdx, int rdy, int button)
{
	switch (button) {
		case SDL_BUTTON_LEFT: {
			rotation = cRotation - (dx * orbitSpeedFact);
			elevation = cElevation - (dy * orbitSpeedFact);
		} break;

		case SDL_BUTTON_RIGHT: {
			distance = cDistance - (dy * zoomSpeedFact);
		} break;
	}

	if (elevation >  89.0f) elevation =  89.0f;
	if (elevation < -89.0f) elevation = -89.0f;
	if (distance  <   1.0f) distance  =   1.0f;

	switch (button) {
		case SDL_BUTTON_LEFT: {
			Orbit();
		} break;

		case SDL_BUTTON_MIDDLE: {
			Pan(rdx, rdy);
		} break;

		case SDL_BUTTON_RIGHT: {
			Zoom();
		} break;
	}
}
예제 #2
0
Camera::Camera()
{
	fov    = 45.0f;
	aspect = 4.0f / 3.0f;
	near   = 0.1f;
	far    = 100.0f;
	
	orbit_radius = 25.0f;

	HFactor = 0.0f;
	VFactor = 0.0f;

	projection = glm::perspective(fov, aspect, near, far);
	Orbit(0.0f, 0.0f);
	
}
예제 #3
0
void CsCameraManager::ApplyCamera() {
	if (mCurrentCamera > mCameraList.size()) return;

	// make sure the camnode is detached first
	// mSceneMgr->getRootSceneNode()->removeChild(mCameraList[mCurrentCamera].second);

	switch(mCameraType[mCurrentCamera]) {
	case Chaos::FREE_CAMERA:
		break;

	case Chaos::CHASE_CAMERA:
		if (mTargetNode) {
			if (mCameraList[mCurrentCamera].second->getParent()) mCameraList[mCurrentCamera].second->getParent()->removeChild(mCameraList[mCurrentCamera].second);
			mTargetNode->addChild(mCameraList[mCurrentCamera].second);
		}
		break;

	case Chaos::ORBIT_CAMERA:
		if (mTargetNode) {
			if (mCameraList[mCurrentCamera].second->getParent()) mCameraList[mCurrentCamera].second->getParent()->removeChild(mCameraList[mCurrentCamera].second);
			mTargetNode->addChild(mCameraList[mCurrentCamera].second);

			mCameraList[mCurrentCamera].second->setInheritOrientation(true);
			mCameraList[mCurrentCamera].second->setFixedYawAxis(true, mTargetNode->_getDerivedOrientation().zAxis());
			mCameraList[mCurrentCamera].second->setAutoTracking(true, mTargetNode);

			mCameraList[mCurrentCamera].first->setFixedYawAxis(false);
			mCameraList[mCurrentCamera].first->setAutoTracking(false);
		}
		Orbit(0.0);
		break;

	case Chaos::COCKPIT_CAMERA:
		break;

	case Chaos::TRACK_CAMERA:
		break;

	default:
		break;

	}

	// instead of setting the camera, make the default camera try to keep up with the current 
	// using interpolation
	// mViewport->setCamera(mCameraList[mCurrentCamera].first);
}
예제 #4
0
// Update everything (make sure it's consistent)
void Camera::updateCamera(void)
{
	if (IsOrbit)
		Orbit();
   // First find the near height/width, far height/width
	this->privCalcPlaneHeightWidth( );

   // Find the frustum physical verts
	this->privCalcFrustumVerts( );
   // find the frustum collision normals
	this->privCalcFrustumCollisionNormals( );

   // update the projection matrix
	this->privUpdateProjectionMatrix( );

   // update the view matrix
	this->privUpdateViewMatrix( );

}
예제 #5
0
void
CameraDirector::Target(double seconds)
{
    Point target_loc = external_point;

    if (external_ship)
    target_loc = external_ship->Location();

    if (!external_ship || external_ship == ship) {
        if (!external_point) {
            if (ship->Cockpit())
            Virtual(seconds);
            else
            Orbit(seconds);

            return;
        }
    }

    double step  = 1;

    if (requested_mode == MODE_COCKPIT)
    step = transition;

    else if (requested_mode == MODE_TARGET)
    step = 1 - transition;

    if (ship->Cockpit()) {
        // internal padlock:
        Cockpit(seconds);
        camera.Padlock(target_loc, 3*PI/4, PI/8, PI/3);
    }
    else {
        // external padlock:
        Point delta = target_loc - ship->Location();
        delta.Normalize();
        delta *= -5 * ship->Radius() * step;
        delta.y += ship->Radius() * step; 

        camera.MoveTo(ship->Location() + delta);
        camera.LookAt(target_loc);
    }
}
예제 #6
0
파일: tgwave.cpp 프로젝트: ANerd/TGWave
int main(int argc, char *argv[])
{
    if(pthread_mutex_init(&SimParams::Lock, NULL) != 0)
        Bug(true, "Failed to make mutex");
    SimParams &params = Initialize();

    StartInfo *info = new StartInfo(argc, argv, params);
    SDL_Thread *guiThread = SDL_CreateThread(&StartGUI, info);

    TGRender render(0,0);
    TGResourceManager rec;
    TGResource vs = rec.CreateResource(TGResourceType::Shader, "water.vs");
    TGResource fs = rec.CreateResource(TGResourceType::Shader, "water.fs");
    TGResource bfs = rec.CreateResource(TGResourceType::Shader, "black.fs");
    TGResource envvs = rec.CreateResource(TGResourceType::Shader, "envshader.vs");
    TGResource envfs = rec.CreateResource(TGResourceType::Shader, "envshader.fs");
    TGResource colvs = rec.CreateResource(TGResourceType::Shader, "colors.vs");
    TGResource colfs = rec.CreateResource(TGResourceType::Shader, "colors.fs");
    TGResource cvs = rec.CreateResource(TGResourceType::Shader, "cube.vs");
    TGResource cfs = rec.CreateResource(TGResourceType::Shader, "cube.fs");
    Debug("Got shaders");
    Create(rec.GetData(vs).c_str(), rec.GetData(fs).c_str(), rec.GetData(bfs).c_str(), rec.GetData(envvs).c_str(), rec.GetData(envfs).c_str(),
            rec.GetData(colvs).c_str(), rec.GetData(colfs).c_str(), rec.GetData(cvs).c_str(), rec.GetData(cfs).c_str());

    ChangeSize(render.GetSize().Width, render.GetSize().Height);
    bool running = true;
    
    bool mouse1Down = false;
    int clickMovement = 0;

    while(running)
    {
        SDL_Event event;
        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
                case SDL_QUIT:
                    running = false;
                    break;
                case SDL_VIDEORESIZE:
                    render.Resize(event.resize.w, event.resize.h);
                    ChangeSize(event.resize.w, event.resize.h);
                    break;
                case SDL_MOUSEMOTION:
                    clickMovement += abs(event.motion.xrel) + abs(event.motion.yrel);
                    //Debug("Got mouse move with dx=%d, dy=%d", event.motion.xrel, event.motion.yrel);
                    if(mouse1Down)
                        Orbit(event.motion.xrel, event.motion.yrel);
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    Debug("Got mouse down on button %d", event.button.button);
                    if(event.button.button == 1)
                    {
                        clickMovement = 0;
                        mouse1Down = true;
                    }
                    break;
                case SDL_MOUSEBUTTONUP:
                    //Debug("Got mouse up on button %d", event.button.button);
                    if(event.button.button == 1)
                    {
                        if(clickMovement < 5)
                        {
                            Touch(event.button.x, event.button.y);
                        }
                        mouse1Down = false;
                    }
                    break;
                default:
                    break;
            }
        }
        Draw();
        
        render.Present();
    }

    if(pthread_mutex_destroy(&SimParams::Lock) != 0)
        Bug(true, "Failed to destroy mutex");
    return 0;
}
예제 #7
0
void CsCameraManager::Update()  {
	static clock_t prevTime = clock();

	static Ogre::Vector3 lerpPos;
	static Ogre::Quaternion slerpRot;
	static float linLerpStep;
	static float angLerpStep;

	clock_t curTime = clock();
	float timeStep = (curTime - prevTime) / (float) CLOCKS_PER_SEC;
	
	Ogre::SceneNode* camNode = mCameraList[mCurrentCamera].second;
	
	// the interpolation ----------------------------------------
	// the current camera is not actually used, the default camera is used to approximate 
	// the current camera

	posA = mDefaultCamNode->_getDerivedPosition();
	rotA = mDefaultCamNode->_getDerivedOrientation();

	posB = camNode->_getDerivedPosition();
	rotB = camNode->_getDerivedOrientation();

	linLerpStep = 0.5 * timeStep / 0.12;	// reaches half i 0.3 seconds
	angLerpStep = 0.5 * timeStep / 0.12;

	// for fast moving targets
	if (mTargetObject) {
		float linear = mTargetObject->GetLinearVelocity().length();
		float angular = mTargetObject->GetAngularVelocity().length();

		if (linear > 200.0f) {
			linLerpStep += (linear - 150) / 300.0f;
			angLerpStep += (linear - 150) / 300.0f;
		}
		if (angular > 3.0f) {
			linLerpStep += (angular - 2.0f) / 8.0f;
			angLerpStep += (angular - 2.0f) / 8.0f;
		}
	}

	if (linLerpStep > 1.0f) linLerpStep = 0.90f;
	if (angLerpStep > 1.0f) angLerpStep = 0.90f;
	if (linLerpStep < 0.0f) linLerpStep = 0.1f;
	if (angLerpStep < 0.0f) angLerpStep = 0.1f;

	lerpPos = (posB - posA) * linLerpStep + posA;
	slerpRot = Ogre::Quaternion::Slerp(angLerpStep, rotA, rotB, true);

	mDefaultCamNode->setPosition(lerpPos);
	mDefaultCamNode->setOrientation(slerpRot);
	// ----------------------------------------------------------
	if (mCameraType[mCurrentCamera] == Chaos::ORBIT_CAMERA) 
	{
		Orbit(timeStep);
	}
	else if (mCameraType[mCurrentCamera] == Chaos::FREE_CAMERA) 
	{
		if ( mButtonState[Chaos::ARROW_UP]) camNode->translate(0,0,-timeStep * MOVE_SPEED, Ogre::Node::TS_LOCAL);
		if ( mButtonState[Chaos::ARROW_DOWN]) camNode->translate(0,0,timeStep * MOVE_SPEED, Ogre::Node::TS_LOCAL);
		if ( mButtonState[Chaos::ARROW_LEFT]) camNode->translate(-timeStep * MOVE_SPEED,0,0, Ogre::Node::TS_LOCAL);
		if ( mButtonState[Chaos::ARROW_RIGHT]) camNode->translate(timeStep * MOVE_SPEED,0,0, Ogre::Node::TS_LOCAL);

		if (xrel) camNode->yaw(Ogre::Radian(Ogre::Degree(-LOOK_SPEED * xrel * timeStep)), Ogre::Node::TS_WORLD);
		if (yrel) camNode->pitch(Ogre::Radian(Ogre::Degree(-LOOK_SPEED * yrel * timeStep)), Ogre::Node::TS_LOCAL);
	}


	xrel = yrel = zrel = 0;
	prevTime = curTime;
}
예제 #8
0
int main() {
	SDL_Init(SDL_INIT_VIDEO);

	SDL_Surface *screen = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE);
	SDL_Surface *trace = SDL_CreateRGBSurface(SDL_HWSURFACE, 1024, 768, 32, 0, 0, 0, 0);
	SDL_WM_SetCaption("Solar system demo", NULL);

	Uint32 white = SDL_MapRGB(screen->format, 255, 255, 255);
	Uint32 black = SDL_MapRGB(screen->format, 0, 0, 0);
	Uint32 red = SDL_MapRGB(screen->format, 255, 0, 0);
    Uint32 green = SDL_MapRGB(screen->format, 0, 255, 0);
    Uint32 blue = SDL_MapRGB(screen->format, 0, 0, 255);

	// Universe U;
	// Sun *sun = new Sun(1e+10);
	// U.addBody(sun);
	// U.addBody(new SpaceBody(0, sun, 0.7, 150));
	// U.addBody(new SpaceBody(0, sun, 0.5, 150, 0, 0, M_PI/4));
	Universe U;
	double sunmass = 1e+10;
	StaticIntegrator si;
	U.addBody(new Body(sunmass, si));

	KeplerIntegrator ki1(Orbit(sunmass, 0, 0.7, 150));
	U.addBody(new Body(0, ki1));

	// KeplerIntegrator ki2(Orbit(sunmass, 0, 0, 150, M_PI/2));
	// U.addBody(new Body(0, ki2));

    EulerIntegrator ei(Vector3D(150, 0, 0), Vector3D(0, -sqrt((sunmass * G)/150), 0));
    Body *eulerbody = new Body(0, ei);
    U.addBody(eulerbody);

	LeapfrogIntegrator lfi(Vector3D(150, 0, 0), Vector3D(0, -sqrt((sunmass * G)/150), 0));
	Body *leapfrogbody = new Body(0, lfi);
	U.addBody(leapfrogbody);


	SDL_Rect pos1, pos2;
	pos2.x = pos2.y = 0;
	Vector3D v;
	SDL_Surface *rect = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 32, 0, 0, 0, 0);
	SDL_FillRect(rect, NULL, white);
	SDL_Surface *littlerect = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 32, 0, 0, 0, 0);

	bool ok = true;
	SDL_Event evt;
    Uint32 color;
    Uint32 startTime = SDL_GetTicks();
	while (ok) {
		SDL_PollEvent(&evt);
		switch (evt.type) {
			case SDL_QUIT:
				ok = false;
				break;
		}

		SDL_FillRect(screen, NULL, black);
		SDL_BlitSurface(trace, NULL, screen, &pos2);

		// for(int i=0;i<2000;i++)
            U.evolve(200);
		for (std::shared_ptr<Body> &it : U.getBodies()) {
            color=it.get() == eulerbody ? green : (it.get() == leapfrogbody ? red : blue);
			v = Vector3D(512, 384, 0) + it->getPosition();
            if(it.get() == leapfrogbody)
                v+=Vector3D(2,0,0);
			pos1.x = v.getX();
            pos1.y = v.getY();
            SDL_FillRect(littlerect, NULL, color);
            SDL_BlitSurface(littlerect, NULL, trace, &pos1);
            pos1.x -= 5;
            pos1.y -= 5;
			SDL_FillRect(rect, NULL, color);
            SDL_BlitSurface(rect, NULL, screen, &pos1);
		}

		SDL_Flip(screen);
	}

	SDL_Quit();

	return EXIT_SUCCESS;
}
예제 #9
0
void
CameraDirector::ExecFrame(double seconds)
{
    if (!ship)
    return;

    hud = HUDView::GetInstance();

    int flight_phase = ship->GetFlightPhase();

    if (flight_phase < Ship::LOCKED)
    SetMode(MODE_DOCKING);

    if (ship->IsAirborne()) {
        if (flight_phase >= Ship::DOCKING)
        SetMode(MODE_DOCKING);
    }
    else {
        if (flight_phase >= Ship::RECOVERY)
        SetMode(MODE_DOCKING);
    }

    if (flight_phase >= Ship::LOCKED && flight_phase < Ship::ACTIVE) {
        int m = GetMode();
        if (m != MODE_COCKPIT && m != MODE_VIRTUAL)
        SetMode(MODE_COCKPIT);
    }

    if (ship->InTransition()) {
        SetMode(MODE_DROP);
    }
    // automatically restore mode after transition:
    else if (old_mode != MODE_NONE) {
        mode           = old_mode;
        requested_mode = old_mode;
        old_mode       = MODE_NONE;
    }

    int op_mode = mode;
    if (requested_mode > mode)
    op_mode = requested_mode;

    Starshatter* stars = Starshatter::GetInstance();

    // if we are in padlock, and have not locked a ship
    // try to padlock the current target:
    if (op_mode == MODE_TARGET && !external_ship) {
        SimObject* tgt = ship->GetTarget();
        if (tgt && tgt->Type() == SimObject::SIM_SHIP)
        SetViewObject((Ship*) tgt);
    }

    // if in an external mode, check the external ship:
    else if (op_mode >= MODE_TARGET && op_mode <= MODE_ZOOM) {
        if (external_ship && external_ship != ship && !stars->InCutscene()) {
            Contact* c = ship->FindContact(external_ship);
            if (!c || !c->ActLock()) {
                SetViewObject(ship);
            }
        }
    }

    if (ship->Rep()) {
        if (op_mode == MODE_COCKPIT) {
            ship->HideRep();
            ship->HideCockpit();
        }
        else if (op_mode == MODE_VIRTUAL || op_mode == MODE_TARGET) {
            if (ship->Cockpit()) {
                ship->HideRep();
                ship->ShowCockpit();
            }
            else {
                ship->ShowRep();
            }
        }
        else {
            ship->Rep()->SetForeground(op_mode == MODE_DOCKING);
            ship->ShowRep();
            ship->HideCockpit();
        }
    }

    if (hud && hud->Ambient() != Color::Black)
    sim->GetScene()->SetAmbient( hud->Ambient() );
    else
    sim->GetScene()->SetAmbient( sim->GetStarSystem()->Ambient() );

    switch (op_mode) {
    default:
    case MODE_COCKPIT:      Cockpit(seconds);    break;
    case MODE_CHASE:        Chase(seconds);      break;
    case MODE_TARGET:       Target(seconds);     break;
    case MODE_THREAT:       Threat(seconds);     break;
    case MODE_VIRTUAL:      Virtual(seconds);    break;
    case MODE_ORBIT:
    case MODE_TRANSLATE:
    case MODE_ZOOM:         Orbit(seconds);      break;
    case MODE_DOCKING:      Docking(seconds);    break;
    case MODE_DROP:         Drop(seconds);       break;
    }

    if (ship->Shake() > 0 && 
            (op_mode <  MODE_ORBIT ||
                (op_mode == MODE_VIRTUAL && ship->Cockpit()))) {

        Point vib = ship->Vibration() * 0.2;
        camera.MoveBy(vib);
        camera.Aim(0, vib.y, vib.z);
    }

    Transition(seconds);
    DetailSet::SetReference(region, camera.Pos());
}
예제 #10
0
void Camera::Beyond() {
	orbit_radius += MOVE_INDEX;
	Orbit();
	cout << orbit_radius << endl;
}
예제 #11
0
void Camera::Closer() {
	orbit_radius -= MOVE_INDEX;
	Orbit();
}