Пример #1
0
void ofxFPSCamera::updateCameraRoll() {
    float angle = rollspeed * ofGetLastFrameTime();
    if (b_roll_ccw||b_roll_cw) {
        roll(angle*(b_roll_ccw-b_roll_cw));
        upvector = getUpDir();
    }
    if (b_roll_reset) {
        roll(-this->getRoll());
        upvector = ofVec3f(0, 1, 0);
    }
}
void SelectableMovableObjectClass::DrawGUI( bool select )
{
	// Draw axes (if selected)
	if ( Selected )
	{
		ofSetLineWidth( 100 );
		float length = 200;

		Camera->begin();
		{
			// Forward Axis (Blue)
			ShaderSelect( select, 0 );
			{
				ofSetColor( ofColor::blue );
				ofDrawLine( getPosition(), getPosition() + ( getLookAtDir() * length ) );
			}
			ShaderSelect( select );

			// Right Axis (Red)
			ShaderSelect( select, 1 );
			{
				ofSetColor( ofColor::red );
				ofDrawLine( getPosition(), getPosition() + ( getSideDir() * length ) );
			}
			ShaderSelect( select );

			// Up Axis (Green)
			ShaderSelect( select, 2 );
			{
				ofSetColor( ofColor::green );
				ofDrawLine( getPosition(), getPosition() + ( getUpDir() * -length ) );
			}
			ShaderSelect( select );
		}
		Camera->end();

		ofSetColor( 255, 255, 255 );
	}

	ShaderSelect( select, 3 );
	{
		SelectableObjectClass::DrawGUI( select );
	}
	ShaderSelect( select );
}
Пример #3
0
//----------------------------------------
void ofLight::onOrientationChanged() {
	if(data->glIndex==-1) return;
	if(getIsDirectional()) {
		// if we are a directional light and not positional, update light position (direction)
		auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz();
		data->position = {lookAtDir.x,lookAtDir.y,lookAtDir.z,0.f};
		ofGetGLRenderer()->setLightPosition(data->glIndex,data->position);
	}else if(getIsSpotlight() || getIsAreaLight()) {
		// determines the axis of the cone light
		auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz();
		data->direction = lookAtDir;
		ofGetGLRenderer()->setLightSpotDirection(data->glIndex, glm::vec4(data->direction, 0.0f));
	}
	if(getIsAreaLight()){
		data->up = getUpDir();
		data->right = getXAxis();
	}
}
Пример #4
0
//----------------------------------------
void ofLight::onOrientationChanged() {
	if(data->glIndex==-1) return;
	// if we are a directional light and not positional, update light position (direction)
	if(getIsDirectional()) {
		// (tig) takes into account global orientation should node be parented.
		ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized();
		data->position = ofVec4f(lookAtDir.x,lookAtDir.y,lookAtDir.z,0);
		ofGetGLRenderer()->setLightPosition(data->glIndex,data->position);
	}else if(getIsSpotlight() || getIsAreaLight()) {
		// determines the axis of the cone light //

		// (tig) takes into account global orientation should node be parented.
		ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized();
		data->direction = ofVec3f(lookAtDir.x,lookAtDir.y,lookAtDir.z);
		ofGetGLRenderer()->setLightSpotDirection(data->glIndex,data->direction);
	}
	if(getIsAreaLight()){
		data->up = getUpDir();
		data->right = getXAxis();
	}
}
void SelectableMovableObjectClass::OnDragged( int x, int y, int button )
{
	SelectableObjectClass::OnDragged( x, y, button );

	// Move along the axis selected
	{
		// Different directions depending on axis selected
		ofVec3f offset;
		{
			// Get different axis depending on selected
			switch ( *AxisSelected )
			{
				case 0: // Blue forward
					offset = getLookAtDir();
					break;
				case 1: // Red right
					offset = getSideDir();
					break;
				case 2: // Green up
					offset = -getUpDir();
					break;
				default:
					break;
			}
		}

		// Calculate direction of axis in screen space
		ofVec2f direction = Camera->worldToScreen( getPosition() - offset, ofGetCurrentViewport() );
		direction /= ofVec2f( ofGetViewportWidth(), ofGetViewportHeight() );

		// Calculate the position of the object in screen space
		ofVec2f position = Camera->worldToScreen( getPosition(), ofGetCurrentViewport() );
		position /= ofVec2f( ofGetViewportWidth(), ofGetViewportHeight() );

		// Get the direction vector from these two aspects
		ofVec2f axisdir = direction - position;
		axisdir.normalize();

		// Check the movement of the cursor in relation to the axis line
		ofVec2f mousedir = LastMouse - ofVec2f( *mouseX, *mouseY );
		mousedir.y *= -1;
		float length = mousedir.length();
		{
			if ( length > 10 )
			{
				length = 10;
			}
		}
		float directionamount = axisdir.dot( mousedir ) * length / 2;

		// Check for snapping enabled
		if ( KeyPressed[OF_KEY_SHIFT] )
		{
			if ( abs( directionamount ) > GRID_SNAP_FORCE )
			{
				// Get the length along this axis
				ofVec3f nodedir = getPosition() * offset;
				float length = nodedir.length();
				if ( ( nodedir.x > 0 ) || ( nodedir.z > 0 ) )
				{
					length *= -1;
				}

				// Divide and floor to get closest minimum grid snap point on this axis
				length = floor( length / GRID_SNAP_DISTANCE );

				// Correct to move in the right direction (i.e. backwards or forwards along the vector)
				if ( signbit( directionamount ) )
				{
					// Take 1 to move to the next grid point
					length--;
				}
				else
				{
					// Plus 1 to move to the next grid point
					length++;
				}

				// Move
				length *= GRID_SNAP_DISTANCE;
				ofVec3f pos = getPosition();
				{
					if ( offset.x != 0 )
					{
						pos.x = length;
					}
					if ( offset.y != 0 )
					{
						pos.y = -length;
					}
					if ( offset.z != 0 )
					{
						pos.z = length;
					}
				}
				setPosition( pos );
			}
		}
		else
		{
			// Move the object
			move( offset * directionamount );
		}

		// Update lastmouse to this frame for mousedir calculation
		LastMouse = ofVec2f( *mouseX, *mouseY );

		// Update slider variables
		SliderX = CLAMP( getPosition().x, -AXISLIMIT_X, AXISLIMIT_X );
		SliderY = CLAMP( getPosition().y, -AXISLIMIT_Y, AXISLIMIT_Y );
		SliderZ = CLAMP( getPosition().z, -AXISLIMIT_Z, AXISLIMIT_Z );
	}
}
Пример #6
0
void ofxFPSCamera::updateCameraPosition() {
    float speed = movespeed * ofGetLastFrameTime();
    move((getLookAtDir()*(b_fwd-b_back)+
          getSideDir()*(b_strafe_left-b_strafe_right)+
          getUpDir()*(b_strafe_up-b_strafe_down))*movespeed);
}