Jump to content
Iris3D Games

GetMousePosition().z ( Zoom ) Move Camera.

Recommended Posts

I have a problem, I wish that when moving the wheel of the mouse the camera gets closer or further away from the character. 

This I want to do with the mouse wheel, and is a kind of zoom, but I can not set things to work. 

I welcome any possible suggestions, and if possible a simple script code. 

	zoomCamara = ventana:GetMousePosition().z /500.0

	--zoomCamara ~= zoomCamara then
	
	
	-- Zoom / Se mueve el pivote de la cámara.
	if self.pivoteCamara:GetPosition(false).z < -2 then
		
		self.pivoteCamara:Move(0,0,zoomCamara)
	end

 

Share this post


Link to post

This is my RTS project's mouse zoom code. I hope this c++ code can give you idea.

float cameraDistance = 15.0f;
float smoothness = 15.0f;
float zoomRangeMin = 8.0f;
float zoomRangeMax = 20.0f;;
Vec3 playerCameraPos;
Vec3 playerCameraNewPos;
float scrollSpeedFPS;
float mouseWheel;

int getMouseWheelDirection() {
	int wheelReturn = 0;
	float mouseWheelPos = Window::GetCurrent()->GetMousePosition().z;

	if (mouseWheel != mouseWheelPos) {
		if (mouseWheelPos < mouseWheel) {
			wheelReturn = 2; //Wheel Down
		}
		else if (mouseWheelPos > mouseWheel) {
			wheelReturn = 1; //Wheel Up
		}
		mouseWheel = mouseWheelPos;
	}
	return wheelReturn;
}

void mouseMovement()
{
    playerCameraPos = playerCamera->GetPosition();
    playerCameraNewPos = playerCameraPos;
    scrollSpeedFPS = scrollSpeed * Time::GetSpeed();
    
    if (playerCameraNewPos.y != cameraDistance) {
		playerCameraNewPos.y = Math::Curve(cameraDistance, playerCameraNewPos.y, smoothness / Time::GetSpeed());
	}

	int mouseWheelDirection = getMouseWheelDirection();
	if (mouseWheelDirection) {
		if (mouseWheelDirection == 1) {
			if (cameraDistance < zoomRangeMax) {
				cameraDistance = cameraDistance + 2;
			}		
		}
		else if(mouseWheelDirection == 2){
			if (cameraDistance > zoomRangeMin) {
				cameraDistance = cameraDistance - 2;		
			}	
		}
	}

	playerCamera->SetPosition(playerCameraNewPos);
}

 

  • Confused 1

Share this post


Link to post
	
	if ventana:KeyHit(Key.F1) then
		zoom = 4
	elseif ventana:KeyHit(Key.F2) then
		zoom = 2 
	elseif ventana:KeyHit(Key.F3) then
		zoom = 0
	end


	

	self.PivoteCamara:SetPosition(0,0,zoom)
	self.PivoteCamara:Move(0,0,-5)

It's the easiest thing I can do. I guess it's not that bad.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...