在我的three.js场景中,我可以添加和编辑对象。 我最近添加了一个“旋转相机”复选框,效果很好。 但问题是附加到对象的transformControl似乎旋转不同:当我停止旋转时,控件与对象相比发生位移。 这是我的功能:
function optionCameraRotation() {
"use strict";
return {
ROTATION_Y_AXIS : false
};
}
var rotationOption = optionCameraRotation();
我的GUI.DAT按钮:
guiCamera.add(rotationOption, 'ROTATION_Y_AXIS').name('Rotation Active');
我的animate()函数:
function animate() {
requestAnimationFrame( animate );
THREE.AnimationHandler.update( 0.05 );
if (rotationOption.ROTATION_Y_AXIS) {
scene.rotation.y = (scene.rotation.y + 0.005 * 4) % (Math.PI * 2);
}
renderer.render( scene, camera );
update();
}
问题出在哪里?
答案 0 :(得分:0)
我只需要修改我的animate()函数中的if语句,如下所示:
@implementation MyVerticalLabel
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI_2);
CGContextConcatCTM(context, transform);
CGContextTranslateCTM(context, -rect.size.height, 0);
// The drawing rect should be applied with transform to.
CGRect newRect = CGRectApplyAffineTransform(rect, transform);
newRect.origin = CGPointZero;
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = self.lineBreakMode;
textStyle.alignment = self.textAlignment;
// Apply current label attributes for drawing function.
NSDictionary *attributeDict =
@{
NSFontAttributeName : self.font,
NSForegroundColorAttributeName : self.textColor,
NSParagraphStyleAttributeName : textStyle,
};
[self.text drawInRect:newRect withAttributes:attributeDict];
}
@end