Beispiel #1
0
void GUI3DDirectionArrow::handleMsg( ZMsg *msg ) {
	if( zmsgIs(type,MouseClickOn) && zmsgIs(which,L) && zmsgIs(dir,D) ) {
		startDrag = FVec2( zmsgF(localX), zmsgF(localY) );
		startDragMat = mat;
		requestExclusiveMouse( 1, 1 );
		zMsgUsed();
		sendMsg();
	}
	else if( zmsgIs(type,MouseReleaseDrag) ) {
		requestExclusiveMouse( 1, 0 );
		zMsgUsed();
	}
	else if( zmsgIs(type,MouseDrag) ) {
		FVec2 mouseDelta( zmsgF(localX), zmsgF(localY) );
		mouseDelta.sub( startDrag );
		mouseDelta.mul( 0.03f );
		mat = startDragMat;
		FMat4 eye = mat;
		eye.setTrans( FVec3::Origin );
		eye.inverse();
		FVec3 yEye = eye.mul( FVec3::YAxisMinus );
		FVec3 xEye = eye.mul( FVec3::XAxis );
		mat.cat( rotate3D( yEye, mouseDelta.x ) );
		mat.cat( rotate3D( xEye, mouseDelta.y ) );
		zMsgUsed();
		sendMsg();
	}
	else if( zmsgIs(type,SetDir) ) {
		FVec3 xaxis( zmsgF(x), zmsgF(y), zmsgF(z) );
		xaxis.mul(-1.f);
		FVec3 yaxis( 0.f, 1.f, 0.f );
		yaxis.cross( xaxis );
		FVec3 zaxis = yaxis;
		zaxis.cross( xaxis );
		xaxis.normalize();
		yaxis.normalize();
		zaxis.normalize();
		mat.m[0][0] = xaxis.x;
		mat.m[0][1] = xaxis.y;
		mat.m[0][2] = xaxis.z;
		mat.m[0][3] = 0.f;
		mat.m[1][0] = yaxis.x;
		mat.m[1][1] = yaxis.y;
		mat.m[1][2] = yaxis.z;
		mat.m[1][3] = 0.f;
		mat.m[2][0] = zaxis.x;
		mat.m[2][1] = zaxis.y;
		mat.m[2][2] = zaxis.z;
		mat.m[2][3] = 0.f;
		mat.m[3][0] = 0.f;
		mat.m[3][1] = 0.f;
		mat.m[3][2] = 0.f;
		mat.m[3][3] = 1.f;
	}
}
void FirstPersonCamera::update(double elapsedTime)
{
	glm::vec2 movementAmount = glm::vec2(0.0f);
	bool changedPosition = false;
    
	if (mInput.isKeyDown(GLFW_KEY_W)) {
        movementAmount.y = 1.0f;
		changedPosition = true;
    }

    if (mInput.isKeyDown(GLFW_KEY_S)) {
        movementAmount.y = -1.0f;
		changedPosition = true;
    }

    if (mInput.isKeyDown(GLFW_KEY_A)) {
        movementAmount.x = 1.0f;
		changedPosition = true;
    }

	if (mInput.isKeyDown(GLFW_KEY_D)) {
        movementAmount.x = -1.0f;
		changedPosition = true;
    }

	const float fElapsedTime = static_cast<float>(elapsedTime);
	bool changedOrientation = false;
	glm::vec2 mouseDelta(0.0f);

	//if (mInput.isMouseButtonDown(GLFW_MOUSE_BUTTON_LEFT)) {
		const glm::vec2 mousePos = mInput.getMousePosition();
		mouseDelta = mousePos - mPrevMousePos;
		mPrevMousePos = mousePos;
		changedOrientation = (mouseDelta != glm::vec2(0.0f));
	//}

	if (changedOrientation) {
		const float pitch = mouseDelta.y * mMouseSensitivity * mRotationRate * fElapsedTime;
		const float yaw = -mouseDelta.x * mMouseSensitivity * mRotationRate * fElapsedTime;
		offsetOrientation(pitch, yaw);
	}

	if (changedPosition) {
		glm::vec2 movement = movementAmount * mMovementRate * fElapsedTime;
		glm::vec3 strafe = getRight() * movement.x;
		glm::vec3 forward = getForward() * movement.y;
		setPosition(getPosition() + strafe + forward);
	}

	Camera::update(elapsedTime);
}
Beispiel #3
0
// Check keypress and mouse position
void GameCore::checkKeyPress(){

	if((glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS) ){
			this->running = false;
	}

	if(glfwGetKey('W'))
		camera->updatePosition(delta * translateSpeed * camera->getForward());
	else if(glfwGetKey('S'))
		camera->updatePosition(delta * translateSpeed * camera->getBackward());

	if(glfwGetKey('A'))
		camera->updatePosition(delta * translateSpeed * camera->getLeft());
	else if(glfwGetKey('D'))
		camera->updatePosition(delta * translateSpeed * camera->getRight());

	int tempX, tempY;
	glfwGetMousePos(&tempX, &tempY);
	glm::vec2 mouseDelta(tempX - mouseX, tempY - mouseY);
	mouseX = tempX;
	mouseY = tempY;
	camera->updateRotation(delta * rotationSpeed * mouseDelta.y, delta * rotationSpeed * mouseDelta.x);
}
void  TInputLine::handleEvent( TEvent& event )
{
    TView::handleEvent(event);

    int delta, anchor, i;
    if( (state & sfSelected) != 0 )
        switch( event.what )
            {
            case  evMouseDown:
                if( canScroll(delta = mouseDelta(event)) )
                    do  {
                        if( canScroll(delta) )
                            {
                            firstPos += delta;
                            drawView();
                            }
                        } while( mouseEvent( event, evMouseAuto ) );
                else if (event.mouse.doubleClick)
                        selectAll(True);
                else
                    {
                    anchor =  mousePos(event);
                    do  {
                        if( event.what == evMouseAuto &&
                            canScroll( delta = mouseDelta(event) )
                          )
                            firstPos += delta;
                        curPos = mousePos(event);
                        if( curPos < anchor )
                            {
                            selStart = curPos;
                            selEnd = anchor;
                            }
                        else
                            {
                            selStart = anchor;
                            selEnd = curPos;
                            }
                        drawView();
                        } while (mouseEvent(event, evMouseMove | evMouseAuto));
                    }
                clearEvent(event);
                break;
            case  evKeyDown:
                switch( ctrlToArrow(event.keyDown.keyCode) )
                    {
                    case kbLeft:
                        if( curPos > 0 )
                            curPos--;
                        break;
                    case kbRight:
                        if( curPos < strlen(data) )
                            curPos++;
                        break;
                    case kbHome:
                        curPos =  0;
                        break;
                    case kbEnd:
                        curPos = strlen(data);
                        break;
                    case kbBack:
                        if( curPos > 0 )
                            {
                            strcpy( data+curPos-1, data+curPos );
                            curPos--;
                            if( firstPos > 0 )
                                firstPos--;
                            }
                        break;
                    case kbDel:
                        if( selStart == selEnd )
                            if( curPos < strlen(data) )
                                {
                                selStart = curPos;
                                selEnd = curPos + 1;
                                }
                        deleteSelect();
                        break;
                    case kbIns:
                        setState(sfCursorIns, Boolean(!(state & sfCursorIns)));
                        break;
                    default:
                        if( event.keyDown.charScan.charCode >= ' ' )
                            {
                            if( (state & sfCursorIns) != 0 )
                                strcpy( data + curPos, data + curPos + 1 );
                            else
                                deleteSelect();
                            if( strlen(data) < maxLen )
                                {
                                if( firstPos > curPos )
                                    firstPos = curPos;
                                memmove( data + curPos + 1, data + curPos,
                                         strlen(data+curPos)+1 );
                                data[curPos++] =
                                    event.keyDown.charScan.charCode;
                                }
                            }
                        else if( event.keyDown.charScan.charCode == CONTROL_Y)
                            {
                            *data = EOS;
                            curPos = 0;
                            }
                        else
                            return;
                    }
                    selStart = 0;
                    selEnd = 0;
                    if( firstPos > curPos )
                        firstPos = curPos;
                    i = curPos - size.x + 3;
                    if( firstPos < i )
                        firstPos = i;
                    drawView();
                    clearEvent( event );
                    break;
            }
}