J'ai un objet C++ que je reçois la référence dans mon contrôleur de vue comme celui-ci:Appeler une classe C++ à partir d'un contrôleur de vue crashes
m_applicationEngine = (ApplicationEngine *)[(GLView *)[self.parentViewController view] m_applicationEngine];
Dans mon délégué emplacement que j'appelle un methid dans la classe comme ceci:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D coordinate = [newLocation coordinate];
NSLog(@"Location acquired %f, %f", coordinate.latitude, coordinate.longitude);
myLocation = new Location(coordinate.latitude, coordinate.longitude);
m_applicationEngine->GotoLoc(myLocation);
}
il n'appelle la fonction GotoLoc, mais il se bloque la première fois la fonction accède à une variable de membre public de l'instance m_applicationEngine. Je suis certain que le membre a déjà été initialisé. Quelqu'un a des idées? M_applicationEngine est un objet C++ initialisé dans initWithFrame() dans GLView: UIView.
m_applicationEngine = new ApplicationEngine(m_renderingEngine, self);
Voici le code de GotoLoc(). La première fois qu'il fait référence à m_rotation, qui est une variable membre de la classe, il se bloque. Je peux appeler GotoLoc() dans d'autres zones du code, mais pas dans la fonction de délégué Obj-C ci-dessus.
void ApplicationEngine::GotoLoc(Location *location) {
vec3 eye = vec3(0, 0, 1);
vec3 end = location->loc;
// Compute the difference between where we're looking at now vs. where we want to point
mat4 transpose;
MatrixTranspose(transpose, m_rotation);
MatrixVec3Multiply(eye, eye, transpose);
//cout << "Inverse. I was here x:" << relativeVec.x << " y:" << relativeVec.y << " z:" << relativeVec.z << endl;
// bring vectors down to the equator to measure x angle
vec3 relativeX = vec3(eye.x, 0, eye.z);
// reference vector is the rotation axis for the sign to be correct
float xAngle = signed_angle(relativeX, vec3(end.x, 0, end.z), vec3(0,-1,0));
mat4 rotationX;
MatrixRotationY(rotationX, -1 * xAngle);
MatrixMultiply(m_rotation, rotationX, m_rotation);
// need to rotate eye vector to line up on y with new target to measure y angle
MatrixTranspose(transpose, rotationX);
MatrixVec3Multiply(eye, eye, transpose);
float yAngle = signed_angle(eye, end, vec3(1,0,0));
cout << "Went to difference of: ANGLE x: " << RADIANS_TO_DEGREES(xAngle) << " y:" << RADIANS_TO_DEGREES(yAngle) << endl;
mat4 rotationY;
MatrixRotationX(rotationY, -1 * yAngle);
MatrixMultiply(m_rotation, m_rotation, rotationY);
}
Quel est le code de Location and m_applicationEngine – Mark