Skip to content
Snippets Groups Projects
Commit 56dfcaf8 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

Set x/y/z view with quaternion (iOS)

parent f6c93d1b
No related branches found
No related tags found
No related merge requests found
...@@ -94,6 +94,9 @@ void drawContext::load(std::string filename) ...@@ -94,6 +94,9 @@ void drawContext::load(std::string filename)
void drawContext::eventHandler(int event, float x, float y) void drawContext::eventHandler(int event, float x, float y)
{ {
this->_current.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y); this->_current.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y);
double xx[3] = {1.,0.,0.};
double yy[3] = {0.,1.,0.};
double q[4];
switch(event) switch(event)
{ {
case 0: // finger(s) press the screen case 0: // finger(s) press the screen
...@@ -121,6 +124,17 @@ void drawContext::eventHandler(int event, float x, float y) ...@@ -121,6 +124,17 @@ void drawContext::eventHandler(int event, float x, float y)
case 4: // release the finger(s) case 4: // release the finger(s)
// Do nothink ? // Do nothink ?
break; break;
case 5: // X view
axis_to_quat(xx, M_PI/2, q);
setQuaternion(q[0], q[1], q[2], q[3]);
break;
case 6: // Y view
axis_to_quat(yy, M_PI/2, q);
setQuaternion(q[0], q[1], q[2], q[3]);
break;
case 7: // Z view
setQuaternion(0., 0., 0., 1.);
break;
default: // all other reset the position default: // all other reset the position
setQuaternion(0., 0., 0., 1.); setQuaternion(0., 0., 0., 1.);
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
{ {
if (_detailItem != newDetailItem) { if (_detailItem != newDetailItem) {
_detailItem = newDetailItem; _detailItem = newDetailItem;
// Update the view. // Update the view.
[self configureView]; [self configureView];
} }
...@@ -39,17 +38,20 @@ ...@@ -39,17 +38,20 @@
- (void)configureView - (void)configureView
{ {
// Update the user interface for the detail item. // Update the user interface for the detail item.
if (self.detailItem) { if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description]; self.detailDescriptionLabel.text = [self.detailItem description];
} }
} }
-(void)viewDidAppear:(BOOL)animated
{
if(self.initialModel != nil) [self.glView load:self.initialModel];
}
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestRender) name:@"requestRender" object:nil];
[self configureView]; [self configureView];
scaleFactor = 1.; scaleFactor = 1.;
setObjCBridge((__bridge void*) self); setObjCBridge((__bridge void*) self);
...@@ -59,16 +61,16 @@ ...@@ -59,16 +61,16 @@
UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMore:)]; UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMore:)];
UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Load model" style:UIBarButtonItemStyleBordered target:self action:@selector(showModelsList)]; UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Load model" style:UIBarButtonItemStyleBordered target:self action:@selector(showModelsList)];
NSArray *btns = [[NSArray alloc] initWithObjects:settings, postpro, more, nil]; NSArray *btns = [[NSArray alloc] initWithObjects:settings, postpro, more, nil];
[self.navigationController.navigationItem setLeftBarButtonItems:btns]; [self.navigationItem setLeftBarButtonItems:btns];
[self.navigationController.navigationItem setRightBarButtonItem:model]; [self.navigationItem setRightBarButtonItem:model];
} }
else { else {
UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Models list" style:UIBarButtonItemStyleBordered target:self action:@selector(showModelsList)];
UIBarButtonItem *postpro = [[UIBarButtonItem alloc] initWithTitle:@"Post processing" style:UIBarButtonItemStyleBordered target:self action:@selector(showPostpro)]; UIBarButtonItem *postpro = [[UIBarButtonItem alloc] initWithTitle:@"Post processing" style:UIBarButtonItemStyleBordered target:self action:@selector(showPostpro)];
UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMore:)]; UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMore:)];
UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Load model" style:UIBarButtonItemStyleBordered target:self action:@selector(showModelsList)];
NSArray *btns = [[NSArray alloc] initWithObjects:postpro, more, nil]; NSArray *btns = [[NSArray alloc] initWithObjects:postpro, more, nil];
self.navigationItem.rightBarButtonItem = model; [self.navigationItem setLeftBarButtonItem:model];
self.navigationItem.leftBarButtonItems = btns; [self.navigationItem setRightBarButtonItems:btns];
} }
} }
...@@ -335,14 +337,13 @@ ...@@ -335,14 +337,13 @@
else if([text isEqualToString:@"Show geometry"]) else if([text isEqualToString:@"Show geometry"])
glView->mContext->showGeom(); glView->mContext->showGeom();
else if([text isEqualToString:@"Set X view"]){ else if([text isEqualToString:@"Set X view"]){
/*glView->mContext->setRotation(0, 0, 0); glView->mContext->eventHandler(5);
glView->mContext->setRotation(90, 0, 0);*/
} }
else if([text isEqualToString:@"Set Y view"]){ else if([text isEqualToString:@"Set Y view"]){
//glView->mContext->setRotation(0, 90, 0); glView->mContext->eventHandler(6);
} }
else if([text isEqualToString:@"Set Z view"]){ else if([text isEqualToString:@"Set Z view"]){
//glView->mContext->setRotation(0, 0, 0); glView->mContext->eventHandler(7);
} }
[glView drawView]; [glView drawView];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment