Пример #1
0
void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){
	ofRectangle viewport = getViewport(this->viewport);
	if(viewport.inside(mouse.x, mouse.y)){
		lastMouse = mouse;
		prevMouse = mouse;
		prevAxisX = getXAxis();
		prevAxisY = getYAxis();
		prevAxisZ = getZAxis();
		prevPosition = ofCamera::getGlobalPosition();
		prevOrientation = ofCamera::getGlobalOrientation();

		if ((bEnableMouseMiddleButton && mouse.button == OF_MOUSE_BUTTON_MIDDLE) || events->getKeyPressed(doTranslationKey)  || mouse.button == OF_MOUSE_BUTTON_RIGHT){
			bDoTranslate = true;
			bDoRotate = false;
		}else if (mouse.button == OF_MOUSE_BUTTON_LEFT) {
			bDoTranslate = false;
			bDoRotate = true;
			if(ofVec2f(mouse.x - viewport.x - (viewport.width/2), mouse.y - viewport.y - (viewport.height/2)).length() < min(viewport.width/2, viewport.height/2)){
				bInsideArcball = true;
			}else {
				bInsideArcball = false;
			}
		}
		bApplyInertia = false;
	}
}
Пример #2
0
//----------------------------------------
void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){
	ofRectangle area = getControlArea();
	if(area.inside(mouse.x, mouse.y)){
		lastMouse = mouse;
		prevMouse = mouse;
		prevAxisX = getXAxis();
		prevAxisY = getYAxis();
		prevAxisZ = getZAxis();
		prevPosition = ofCamera::getGlobalPosition();
		prevOrientation = ofCamera::getGlobalOrientation();

		if((bEnableMouseMiddleButton && mouse.button == OF_MOUSE_BUTTON_MIDDLE) || events->getKeyPressed(doTranslationKey)  || mouse.button == OF_MOUSE_BUTTON_RIGHT){
			bDoTranslate = true;
			bDoRotate = false;
		}else if(mouse.button == OF_MOUSE_BUTTON_LEFT){
			bDoTranslate = false;
			bDoRotate = true;
			if(glm::length(glm::vec2(mouse.x - area.x - (area.width/2), mouse.y - area.y - (area.height/2))) < std::min(area.width/2, area.height/2)){
				bInsideArcball = true;
			}else{
				bInsideArcball = false;
			}
		}
		bApplyInertia = false;
	}
}
Пример #3
0
//------------------------------------------------
void TravelingCam::update(ofEventArgs& a) {

    unsigned long long t = ofGetElapsedTimeMillis();
    if (bTweening) {
        currentSpeed = tween.update();
    } else if (pathLength < currentDistance + slowdownDist) {

        currentSpeed = ofMap(currentDistance, pathLength - slowdownDist, pathLength, 0, speed);

    } else {
        currentSpeed = speed;
    }



    unsigned long long dt = t - lastUpdateTime;
    currentDistance += currentSpeed * dt;

    ofPoint p = path.getPointAtLength(currentDistance);
    float inc = 10;

    if (pathLength < currentDistance + inc ) {
        inc = pathLength - currentDistance;
    }
    ofPoint p0 = path.getPointAtLength(currentDistance + inc);

    p.y *= heightMult;
    p0.y *= heightMult;
    //lookAt( p + (p - p0).normalize());
    setPosition( p);
    dirVec  = p + (p0 - p).normalize();

    lookAt(dirVec, ofVec3f(0,1,0));

    boom(altura);
    if(bMousePressed || bXenoRunning) {
        ofVec2f c (ofGetWidth()/2, ofGetHeight()/2);



        ofVec2f mouseNorm = mousePos - c;
        xenoPos = xenoPos + (mouseNorm- xenoPos)*xenoFactor;
        if ((mouseNorm - xenoPos).length() < 1) {
            xenoPos = mouseNorm;
            bXenoRunning = false;
        }

//        mouseNorm.x /= c.x;
        //      mouseNorm.y /= c.y;

        rotate(ofMap(xenoPos.x, -c.x, c.x, 90, -90), getYAxis());
        rotate(ofMap(xenoPos.y, -c.y, c.y, 60, -60), getXAxis());
    }
    lastUpdateTime = t;
}
Пример #4
0
//----------------------------------------
glm::vec3 ofEasyCam::up() const{
	if(relativeYAxis){
		if(bApplyInertia){
			return getYAxis();
		}else{
			return prevAxisY;
		}
	}else{
		return upAxis;
	}
}
Пример #5
0
//----------------------------------------
void ofEasyCam::updateTranslation(){
	if (bApplyInertia) {
		moveX *= drag;
		moveY *= drag;
		moveZ *= drag;
		if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) {
			bApplyInertia = false;
			bDoTranslate = false;
		}
	}
	move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ));
}	
Пример #6
0
//----------------------------------------
void ofEasyCam::updateTranslation(){
	if (bApplyInertia) {
		moveX *= drag;
		moveY *= drag;
		moveZ *= drag;
		if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) {
			bApplyInertia = false;
			bDoTranslate = false;
		}
		move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ));
	}else{
		setPosition(prevPosition + ofVec3f(prevAxisX * moveX) + (prevAxisY * moveY) + (prevAxisZ * moveZ));
	}
}	
Пример #7
0
//----------------------------------------
void ofEasyCam::updateRotation(){
	if (bApplyInertia) {
		xRot *=drag; 
		yRot *=drag;
		zRot *=drag;
		
		if (ABS(xRot) <= minDifference && ABS(yRot) <= minDifference && ABS(zRot) <= minDifference) {
			bApplyInertia = false;
			bDoRotate = false;
		}
		curRot = ofQuaternion(xRot, getXAxis(), yRot, getYAxis(), zRot, getZAxis());
		setPosition((getGlobalPosition()-target.getGlobalPosition())*curRot +target.getGlobalPosition());
		rotate(curRot);
	}else{
		curRot = ofQuaternion(xRot, prevAxisX, yRot, prevAxisY, zRot, prevAxisZ);
		setPosition((prevPosition-target.getGlobalPosition())*curRot +target.getGlobalPosition());
		setOrientation(prevOrientation * curRot);
	}
}
Пример #8
0
//----------------------------------------
void ofEasyCam::updateTranslation(){
	if(bApplyInertia){
		moveX *= drag;
		moveY *= drag;
		moveZ *= drag;

		if(ABS(moveZ) >= minDifference){
			bIsBeingScrolled = true;
		} else {
			bIsBeingScrolled = false;
		}

		if(ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference){
			bApplyInertia = false;
			bDoTranslate = false;
		}
		move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ));
	}else if(bDoTranslate || bIsBeingScrolled){
		setPosition(prevPosition + glm::vec3(prevAxisX * moveX) + (prevAxisY * moveY) + (prevAxisZ * moveZ));
		bIsBeingScrolled = false;
	}
}	
Пример #9
0
int main(void) {
	wdt_enable(WDTO_1S);

	//odDebugInit();
	//DBG1(0x00, 0, 0);  /* debug output: main starts */

	mouseInit();

	usbInit();

	usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
	uchar i = 0;
	while(--i){  /* fake USB disconnect for > 250 ms */
		wdt_reset();
		_delay_ms(1);
	}
	usbDeviceConnect();

	sei();
	//DBG1(0x01, 0, 0);  /* debug output: main loop starts */
	
	
	for(;;){ /* main event loop */
		//DBG1(0x02, 0, 0);  /* debug output: main loop iterates */
		wdt_reset();
		usbPoll();
		
		reportBuffer[0]=getXAxis();
		reportBuffer[1]=getYAxis();
		reportBuffer[2]=getZAxis();
		
		if(usbInterruptIsReady()){
		// called after every poll of the interrupt endpoint
		//DBG1(0x03, 0, 0);  // debug output: interrupt report prepared
		usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
		}
	}
}
Пример #10
0
void ofxGameCamera::updateRotation(){
	
	if(!applyRotation) return;
	
//	cout << "update rotation!" << endl;
	if(dampen){
		rotationX += (targetXRot - rotationX) *.2;
		rotationY += (targetYRot - rotationY) *.2;
		rotationZ += (targetZRot - rotationZ) *.2;
	}
	else{
		rotationX = targetXRot;
		rotationY = targetYRot;
		rotationZ = targetZRot;
	}
	
	setOrientation(ofQuaternion(0,0,0,1)); //reset
	setOrientation(getOrientationQuat() * ofQuaternion(-rotationZ, getZAxis()));
	setOrientation(getOrientationQuat() * ofQuaternion(-rotationX, getYAxis()));
	setOrientation(getOrientationQuat() * ofQuaternion(-rotationY, getXAxis()));
		
	targetNode.setOrientation(getOrientationQuat());
}
Пример #11
0
//----------------------------------------
glm::vec3 ofNode::getUpDir() const {
	return getYAxis();
}
Пример #12
0
//----------------------------------------
void ofNode::panRad(float radians) {
	rotateRad(radians, getYAxis());
}
Пример #13
0
//----------------------------------------
void ofNode::panDeg(float degrees) {
	rotateDeg(degrees, getYAxis());
}
Пример #14
0
//----------------------------------------
void ofNode::boom(float amount) {
	move(getYAxis() * amount);
}
Пример #15
0
//----------------------------------------
ofVec3f ofNode::getUpDir() const {
    return getYAxis();
}
Пример #16
0
//----------------------------------------
void ofNode::pan(float degrees) {
    rotate(degrees, getYAxis());
}
Пример #17
0
//----------------------------------------
void ofEasyCamExt::updateTranslation()
{
	move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ));
}
Пример #18
0
//----------------------------------------
void ofEasyCamExt::update(ofEventArgs & args)
{
	if( isDoingMove )
	{
		float tmpFraction = ofMap( ofGetElapsedTimef(),
								   moveStartEndTimeParameters.getMin(), moveStartEndTimeParameters.getMax(),
								  0.0f, 1.0f );
		
		if( tmpFraction >= 1.0f )
		{
			isDoingMove = false;
		}
		
		tmpFraction = ofClamp( tmpFraction, 0.0f, 1.0f );
		tmpFraction = EasingEquations::ease( tmpFraction, easeType );
		
		ofVec3f newPos = positionEaseParameters.getMin().interpolate( positionEaseParameters.getMax(), tmpFraction );
		//ofVec3f newLookAtDir = lookAtEaseParameters.getMin().interpolate( lookAtEaseParameters.getMax(), tmpFraction );
		
		ofQuaternion newOrientation;
		newOrientation.slerp( tmpFraction, orientationEaseStart, orientationEaseEnd );
		
		//resetTransform();
		setPosition(newPos);
		
		//target.resetTransform();
		//target.setPosition(newLookAtDir);
		//lookAt(target, getUpDir() );
		setOrientation( newOrientation );
		
		moveX = 0;
		moveY = 0;
		moveZ = 0;
	}
	else
	{
			
		if(!bDistanceSet && bAutoDistance)
		{
			setDistance(getImagePlaneDistance(viewport), true);
		}
		
		if(bMouseInputEnabled)
		{
			rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height);
			if (bMouseInputEnabled)
			{
				updateMouse();
			}
			
			if (bDoRotate)
			{
				updateRotation();
			}
			else if (bDoTranslate)
			{
				updateTranslation(); 
			}
		}
		
		if( dollyForwardKey != 0 )
		{
			if( ofGetKeyPressed(dollyForwardKey) ) { dollyImpulse( -dollyImpulseAmount ); }
		}
		
		if( dollyBackwardKey != 0 )
		{
			if( ofGetKeyPressed(dollyBackwardKey) ) { dollyImpulse( dollyImpulseAmount ); }
		}
		
	//	if (bApplyInertia) {
			moveX *= drag;
			moveY *= drag;
			moveZ *= drag;
			if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) {
				//bApplyInertia = false;
				bDoTranslate = false;
			}
	//	}
		
		move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ));
	}

}
Пример #19
0
void ofEasyFingerCam::updateRotation()
{
    rotationX += (targetXRot - rotationX) *.1;
    rotationY += (targetYRot - rotationY) *.1;
    rotationZ += (targetZRot - rotationZ) *.1;
    target.setOrientation(ofQuaternion(0,0,0,1)); //reset
    ofQuaternion p = ((getOrientationQuat() * ofQuaternion(-rotationY, getXAxis())) * ofQuaternion(-rotationX, getYAxis())) * ofQuaternion(-rotationZ, getZAxis());
    target.setOrientation(p);
}