Поднимите «верхнюю» сторону SCNNode из ориентацииIOS

Программируем под IOS
Ответить
Anonymous
 Поднимите «верхнюю» сторону SCNNode из ориентации

Сообщение Anonymous »

У меня есть SCNBox в SCNScene. После анимации сцены SCNBox меняет ориентацию, которую можно увидеть, проверив егоpresentationNode.orientation. Это значение возвращается в SCNVector4. Как определить, какая сторона SCNBox является стороной вверх по значениям, возвращаемым в SCNVector4?

Я пытался нормализовать данные и пришел есть следующие данные

Side 1 = (-x, 0, 0, +x)
Side 2 = (0, -x, 0 +y)
Side 3 = (-x, +x, -y, y)
Side 4 = (x, x, y, y)
Side 5 = (-x, 0, +y, 0)
Side 6 = (-x, -y, +y, -x)


К сожалению, это не всегда так, и проверка на это иногда возвращает неверные стороны.

Есть ли надежный способ определить верхнюю сторону SCNBox по свойству ориентации его геометрии?

Изменить:
Основываясь на ответе Toyos, я пришел со следующим кодом, который не работает. Надеюсь, это поможет приблизиться к конечной цели. Я также использовал код, найденный в разделе «Извлечение вершин из набора сцен», чтобы получить вершины моего SCNBoxNode.

- (NSNumber *)valueForRotation:(SCNVector4)rotation andGeometry:(SCNGeometry*)geometry {
SCNVector4 inverse = SCNVector4Make(rotation.x, rotation.y, rotation.z, -rotation.w);

CATransform3D transform = CATransform3DMakeRotation(inverse.w, inverse.x, inverse.y, inverse.z);

GLKMatrix4 matrix = GLKMatrix4Make(transform.m11, transform.m12, transform.m13, transform.m14, transform.m21, transform.m22, transform.m23, transform.m24, transform.m31, transform.m32, transform.m33, transform.m34, transform.m41, transform.m42, transform.m43, transform.m44);

GLKVector4 vector = GLKVector4Make(rotation.x, rotation.y, rotation.z, rotation.w);

GLKVector4 finalVector = GLKMatrix4MultiplyVector4(matrix, vector);

NSArray *vertexSources = [geometry geometrySourcesForSemantic:SCNGeometrySourceSemanticVertex];

SCNGeometrySource *vertexSource = vertexSources[0]; // TODO: Parse all the sources

NSInteger stride = vertexSource.dataStride; // in bytes
NSInteger offset = vertexSource.dataOffset; // in bytes

NSInteger componentsPerVector = vertexSource.componentsPerVector;
NSInteger bytesPerVector = componentsPerVector * vertexSource.bytesPerComponent;
NSInteger vectorCount = vertexSource.vectorCount;

SCNVector3 vertices[vectorCount]; // A new array for vertices

// for each vector, read the bytes
NSLog(@"vetor count %i",vectorCount);
float highestProduct = 0;
int highestVector = -1;
NSMutableArray *highVectors;
for (NSInteger i=0; i highestProduct) {
highestProduct = product;
highestVector = i;
}

}

NSLog(@"highestProduct = %f",highestProduct);
NSLog(@"highestVector = %i",highestVector);
NSLog(@"top verticy = %f, %f, %f",vertices[highestVector].x,vertices[highestVector].y,vertices[highestVector].z);

return [NSNumber numberWithInt:highestVector];
}


Подробнее здесь: https://stackoverflow.com/questions/241 ... rientation
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»