13 Replies - 1054 Views - Last Post: 13 August 2011 - 11:43 AM Rate Topic: -----

#1 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

rotating camera from the mouse

Posted 08 August 2011 - 12:12 PM

hey, as the title says, ill need to rotate a game camera from the mouse mouvement
the game is gta 4
i have the mouse movement coords(X, Y)
i have the camera lookat coords
and the camera position coords
all i need is a simple way to rotate the camera using the mouse coords
i've already tried adding x mouse mouvement coord to the X coord of the camera lookat, but at some place it stops rotation(cuz it needs to change the Y instead of the X)


so could anyone give me an easy sample/guide on how to apply the camera rotation porperly from the mouse
any help will be appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: rotating camera from the mouse

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 01:49 PM

well what i would do is take the difference between 2 frames mouse concordats and rotate by some factor along the respective axes.

so say you are rotating in degrees, you have an 800x600 screen and you want 1 swipe of the mouse across the screen to do a 360. so along you x-axis you have 800 pixels so 800 pixels of mouse movement should translate to 360 degrees of rotation about the camera. to get this factor we divide 360 by 800. so say the mouse moves 40 pixels, that is 40*(360/800) degrees of rotation, or 18 degrees.

if your issue is with the code itself then post the code so we can help :)
Was This Post Helpful? 1
  • +
  • -

#3 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 02:45 PM

thanks for your reply, it was helpful on how to move the camera from the mouse mouvement
but thats not what im exactly looking for
what i wants is someway to change the camera axis(X, Y) coords to camera angle, change the angle from mouse
then change it back to X, Y lookat coords

so lets say i have the camera looking at coords (-20, 15)
then i move the mouse, so i need these coords to change to camera rotation (ex: 120)
then i add the X mouse mouvement to the rotation(ex: 122)
then change back to coords ex(-17, 15)

considering i have the camera position coords

my probleme is not with the code, just a way/guide/sample on how to it
or any other camera rotating method
Was This Post Helpful? 0
  • +
  • -

#4 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 03:03 PM

is this 3D or 2D? i was under the impression that this was 3D becuase of the camera.
Was This Post Helpful? 0
  • +
  • -

#5 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 03:38 PM

View Postishkabible, on 08 August 2011 - 03:03 PM, said:

is this 3D or 2D? i was under the impression that this was 3D becuase of the camera.

its 3D
sry forgot to talk about the Z angle cuz its not my probleme right now
i have no probleme in moving the camera on the Z angle
Was This Post Helpful? 0
  • +
  • -

#6 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 03:44 PM

well you left out the whole z axis when describing what the camera is looking at. a 3D camera can't just look at a 2D coordinate, that doesn't even make sense. can you reference a game that works the way you want this to? im having a hard time understanding what you want if not to translate mouse movement to camera rotation like in an FPS

also, this may be better suited for the game devolpment lounge sense your issue is math.

This post has been edited by ishkabible: 08 August 2011 - 03:45 PM

Was This Post Helpful? 0
  • +
  • -

#7 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

Re: rotating camera from the mouse

Posted 08 August 2011 - 04:10 PM

View Postishkabible, on 08 August 2011 - 03:44 PM, said:

well you left out the whole z axis when describing what the camera is looking at. a 3D camera can't just look at a 2D coordinate, that doesn't even make sense. can you reference a game that works the way you want this to? im having a hard time understanding what you want if not to translate mouse movement to camera rotation like in an FPS

also, this may be better suited for the game devolpment lounge sense your issue is math.

sorry for posting in the wrong section then, and sorry also for not explaining my probleme correctly
what i mean is if the camera is looking at (-341, 1144, 16), and the mouse has moved of (2, 3)
the new coordinates should look something like that (-339, 1144, 19)
but my probleme is not adding mouse moving coords to the lookat coords
my probleme is when should i add the mouse X move to the lookat X and when to the lookat Y
i know it has something to do with the camera rotation checking, but i cant really figure out how
Was This Post Helpful? 0
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: rotating camera from the mouse

Posted 08 August 2011 - 06:04 PM

Moved to Game Programming.

Can you post your source please. :)
Was This Post Helpful? 0
  • +
  • -

#9 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: rotating camera from the mouse

Posted 08 August 2011 - 09:44 PM

When posting, please try and use correct grammar and punctuation in your posts, this will help us make sense of your question :) Camera Operations are one of my weak points as a newbie game programmer, but once you know and understand how they work, then all will be revealed to be quite simple (Or simpler than other attempts)
Was This Post Helpful? 0
  • +
  • -

#10 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

Re: rotating camera from the mouse

Posted 12 August 2011 - 09:52 PM

moving camera is fixed, thanks for everyone who replied above
but there still a very little thing i wanna do
i wanna check if an object exists in my camera line of sight

i have like always the
- camera position coords
- camera lookat coords
- object coords
- object dimensions

i need just a simple way to check if the object exists in the camera line of sight
thanks in advance
Was This Post Helpful? 0
  • +
  • -

#11 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 999
  • View blog
  • Posts: 4,176
  • Joined: 14-February 08

Re: rotating camera from the mouse

Posted 13 August 2011 - 01:28 AM

Please post your code as already mentioned. :code:
Was This Post Helpful? 0
  • +
  • -

#12 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: rotating camera from the mouse

Posted 13 August 2011 - 02:05 AM

To check that you can calculate your camera's view frustum (look it up if you don't know what it is/how it's done) and then check whether your objects bounding box intersects it.

That's one of the ways anyway.
Was This Post Helpful? 0
  • +
  • -

#13 James_Alex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 156
  • Joined: 21-August 09

Re: rotating camera from the mouse

Posted 13 August 2011 - 08:57 AM

here is my code
	for(int i = 0; i < MAX_VEHICLES; i++)
	{
		if(pVehiclePool->IsVehicleCreated(i))
		{
			pVehiclePool->GetVehicle(i)->GetPosition(&fVX, &fVY, &fVZ);
			float fCX, fCY, fCZ;
			pCamera->GetCameraPos(&fCX, &fCY, &fCZ);
			if(GetDistanceBetweenPoints3D(fCX, fCY, fCZ, fVX, fVY, fVZ) < 50.0f)
			{
                            // This is the function i need
                            // NOTE: fCX, fCY ... are camera pos, fX, fY ... are camera lookat
                            IsVehicleInLOS(i, fCX, fCY, fCZ, fX, fY, fZ) ? return i : continue;
			}
		}
	}
	return -1;


Was This Post Helpful? 0
  • +
  • -

#14 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: rotating camera from the mouse

Posted 13 August 2011 - 11:43 AM

View PostJames_Alex, on 13 August 2011 - 08:57 AM, said:

here is my code


well done, but by being brief I was expecting you to perform the work, not me.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1