PDA

View Full Version : Helpm Required for 3rd Person Camera Collision!!!!



Mr.Mark
07-12-2008, 03:13 AM
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))
{
vOffset = GetCollisionOffset(vNormal, m_radius, distance);
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_camer a_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_camer a_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_camer a_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_camer a_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_camer a_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_camer a_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

Zengar
07-12-2008, 05:43 AM
This question is in no means related to OpenGL. You seem to have some problems with the 3d math library you use (no idea what kind of library it is). Also, your inability to compile the code shows that you are beginner to programming in general: you just use wrong data types. You should read the documentation of your library carefully and change your code to use correct types. If you are unable to do this alone, please ask at a C++ forum or a forum devoted to your library.

Mr.Mark
07-13-2008, 09:12 PM
yup I'm very new in programming
any ways thanks for the suggestion

Regards,
Mark

Zengar
07-14-2008, 04:47 AM
If you are new to programming you should also start with simple things... get a beginners book and work your way through. You can't do bodybuilding by starting with 100kg lifts...