rotating camera from the mouse

Page 1 of 1

13 Replies - 1599 Views - Last Post: 13 August 2011 - 11:43 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=242780&amp;s=f9d7aa7550d87269fd23db2f025c0d58&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 James_Alex

Reputation: 7
• 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

• spelling expret

Reputation: 1747
• Posts: 5,898
• 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

#3 James_Alex

Reputation: 7
• 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

#4 ishkabible

• spelling expret

Reputation: 1747
• Posts: 5,898
• 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.

#5 James_Alex

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

Re: rotating camera from the mouse

Posted 08 August 2011 - 03:38 PM

ishkabible, 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

#6 ishkabible

• spelling expret

Reputation: 1747
• Posts: 5,898
• 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

#7 James_Alex

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

Re: rotating camera from the mouse

Posted 08 August 2011 - 04:10 PM

ishkabible, 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

#8 anonymous26

• D.I.C Lover

Reputation: 2
• Posts: 3,638
• Joined: 26-November 10

Re: rotating camera from the mouse

Posted 08 August 2011 - 06:04 PM

Moved to Game Programming.

#9 aaron1178

• Dovakiin, Dragonborn

Reputation: 169
• Posts: 1,308
• 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)

#10 James_Alex

Reputation: 7
• 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

#11 stayscrisp

• フカユ

Reputation: 1040
• Posts: 4,325
• Joined: 14-February 08

Re: rotating camera from the mouse

Posted 13 August 2011 - 01:28 AM

#12 bonyjoe

Reputation: 178
• 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.

#13 James_Alex

Reputation: 7
• 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;

```

#14 bonyjoe

Reputation: 178
• Posts: 548
• Joined: 08-September 10

Re: rotating camera from the mouse

Posted 13 August 2011 - 11:43 AM

James_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.