Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Go Back  Xtreme Visual Basic Talk > > > > Camera Movement and Look To (mouselook)


Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2013, 07:21 AM
KiltedNinja's Avatar
KiltedNinja KiltedNinja is offline
Centurion
 
Join Date: May 2009
Posts: 120
Question Camera Movement and Look To (mouselook)


Hi folks,

I could really use some help here, if anyone has time.

I'm trying to move my camera around, and make it look at a certain position by using the mouse. (like you use in a first-person-shooter game)

So I have the movement all done; I can use keys to move forward/back/left/right, and it works depending on the direction the camera is facing.

My problem is positioning the "look to" coordinates. Essentially, I want to move the "Look To" position to be on the surface of 'an invisible sphere' surrounding the Camera - Giving me total use of moving the mouse and changing where I look (like FPS).

I can find out easily which direction the mouse is going, and I have two variables which change depending on the direction (Rotation X and Rotation Y). So, mouse moves left, Rotation X = Rotation X - 1, if mouse moves right, it's +1. That's fine, and I can read these variables and see that it works. I have 'locked' them both into being >=0 and <=360.

So here's the tricky part. I've written this code (with help on wikipedia's article on spherical coordinates) :

Code:
'(first bit)
    dxCAMERAto.X = (RADIUS * Sin(ROTATION_Y * gRAD) * Cos(TEMP_ROTATION_X * gRAD))
    dxCAMERAto.Y = (RADIUS * Sin(ROTATION_Y * gRAD) * Sin(TEMP_ROTATION_X * gRAD))
    dxCAMERAto.z = (RADIUS * Cos(ROTATION_Y * gRAD))

'(second bit)
    dxCAMERAto.X = dxCAMERAfrom.X + dxCAMERAto.X
    dxCAMERAto.Y = dxCAMERAfrom.Y + dxCAMERAto.Y
    dxCAMERAto.z = dxCAMERAfrom.z + dxCAMERAto.z

'(gRAD = PI / 180)
The 'First bit' takes two angles, Rotation X and Rotation Y, and a Radius, then translates that to X/Y/Z (cartesian coordinates)

The 'Second bit' then adds this position to the Camera's position.

When I test this with a random object (a cube), and I have it placed in the center of the world, I can see the cube move around on this 'invisible sphere' when I move the mouse. It looks almost perfect, like it's working correctly.

When I then try to apply this *exact same* code to the Camera's 'To' position, it fails dramatically.

Logic tells me that this should work. It doesn't work. It's driving me crazy.

Has anyone here ever tried to do anything like this and succeeded? Any assistance would be really helpful.

Thanks for your time,
KiltedNinja
Reply With Quote
Reply

Tags
camera, directx, lookat, mouse


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook) Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
 
Camera Movement and Look To (mouselook)
Camera Movement and Look To (mouselook)
 
-->