# Helpm Required for 3rd Person Camera Collision!!!!

Hi all,
I’m new to this forum

I’m a beginner in OpenGL.

I tried to develop a scene with 3rd person Camera
but Im not able implement the Collison

``````
``````

#include “main.h”
void CCamera::Position_Camera(float pos_x, float pos_y, float pos_z,
float view_x, float view_y, float view_z,
float up_x, float up_y, float up_z)
{
mPos = tVector3(pos_x, pos_y, pos_z ); // set position
mView = tVector3(view_x, view_y, view_z); // set view
mUp = tVector3(up_x, up_y, up_z ); // set the up vector
}
void CCamera::Move_Camera(float speed)
{
tVector3 vVector = mView - mPos; // Get the view vector
mPos.x = mPos.x + vVector.x * speed;
mPos.z = mPos.z + vVector.z * speed;
mView.x = mView.x + vVector.x * speed;
mView.z = mView.z + vVector.z * speed;
}
void CCamera::Rotate_View(float speed)
{
tVector3 vVector = mView - mPos; // Get the view vector

mView.z = (float)(mPos.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
mView.x = (float)(mPos.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
}
void CCamera::Rotate_Position(float speed)
{
tVector3 vVector = mPos - mView;

mPos.z = (float)(mView.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
mPos.x = (float)(mView.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
}
void CCamera::Mouse_Move( int wndWidth, int wndHeight )
{
POINT mousePos;
int mid_x = wndWidth >> 1;
int mid_y = wndHeight >> 1;
float angle_y = 0.0f;
float angle_z = 0.0f;
GetCursorPos(&mousePos); // Get the mouse cursor 2D x,y position
if( (mousePos.x == mid_x) && (mousePos.y == mid_y) ) return;
SetCursorPos(mid_x, mid_y); // Set the mouse cursor in the center of the window
angle_y = (float)( (mid_x - mousePos.x) ) / 1000;
angle_z = (float)( (mid_y - mousePos.y) ) / 1000;
mView.y += angle_z * 2;
if(mView.y > 3.5f) mView.y = 3.5f;
if(mView.y < 0.4f) mView.y = 0.4f;
Rotate_Position(-angle_y);
}
void CCamera::CheckCameraCollision(tVector3 *pVertices, int numOfVerts)
{
for(int i = 0; i < numOfVerts; i += 3)
{
tVector3 vTriangle[3] = { pVertices[i], pVertices[i+1], pVertices[i+2] };
tVector3 vNormal = Normal(vTriangle);
float distance = 0.0f;
int classification = ClassifySphere(mPos, vNormal, vTriangle[0], m_radius, distance);
if(classification == INTERSECTS)
{
tVector3 vOffset = vNormal * distance;
tVector3 vIntersection = mPos - vOffset;
if(InsidePolygon(vIntersection, vTriangle, 3) ||
EdgeSphereCollision(mPos, vTriangle, 3, m_radius / 2))
{
mPos = mPos + vOffset;
mView = mView + vOffset;
}
}
}
}

The following are the errors which i get

1>c:\documents and settings\sunilkumar.k\desktop\gl_camera_4\gl_camera_4\camera.cpp(54) : error C2664: ‘Normal’ : cannot convert parameter 1 from ‘tVector3 [3]’ to ‘CVector3 []’
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\sunilkumar.k\desktop\gl_camera_4\gl_camera_4\camera.cpp(56) : error C2664: ‘ClassifySphere’ : cannot convert parameter 1 from ‘tVector3’ to ‘CVector3 &’
1>c:\documents and settings\sunilkumar.k\desktop\gl_camera_4\gl_camera_4\camera.cpp(61) : error C2664: ‘InsidePolygon’ : cannot convert parameter 1 from ‘tVector3’ to ‘CVector3’
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\sunilkumar.k\desktop\gl_camera_4\gl_camera_4\camera.cpp(62) : error C2664: ‘EdgeSphereCollision’ : cannot convert parameter 1 from ‘tVector3’ to ‘CVector3 &’
1>c:\documents and settings\sunilkumar.k\desktop\gl_camera_4\gl_camera_4\camera.cpp(64) : error C2664: ‘GetCollisionOffset’ : cannot convert parameter 1 from ‘tVector3’ to ‘CVector3 &’
1>Build log was saved at “file://c:\Documents and Settings\sunilkumar.k\Desktop\gl_camera_4\gl_camera_4\Debug\BuildLog.htm”
1>APRON - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I will be thank full if any one can help me out!!!

Regards,
Mr.Mark

That’s a really good reason to post in the advanced forum and not the beginner one.

I tried really hard but could not find any OpenGL calls in your code. So your problem is clearly not OpenGL related.
Perhaps you should check out a C/C++ forum (beginners section I would think) and post your problem there. Or you could carefully read the error messages and try to figure out what the compiler complains about.