Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Calculate 3D Object movements in c?

Tags:

ios

opencv

iphone

I am new to 3D programming, Creating 3D objects from Blender and pass into my Project in iOS.

Now I am able to render object on my screen. Even I am able to apply gesture like pinch to zoom in/out.

Now I want to implement as I swipe left from one position toward left Object should rotate with its y axis. I have implement Slop Formulate As:

float angle =atan2f((y2 - y1),(x2 - x1));

but it gives more difference in angle. Shortly The 3D object is not moving the actual direction. And the angle should be rotate in small value.(below 45 degrees) with respect to x,y and z axis.

I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow

  1. how to calculate the angles?
  2. how to rotate it when I know the angles?
like image 788
Swatee Salunkhe Avatar asked Nov 13 '22 02:11

Swatee Salunkhe


1 Answers

Just check the cocos3d sample projects .New project it self contains action to rotate. Or create a new project as sample by yourself.

  1. Create a New Project.

  2. Open the Classes folder in navigator pane on the left side.

  3. Then Select Classes Folder.

  4. Select the scene.m file.

    There you can see in initializeScene(). It contains the code to create a new cc3meshnode and actions to rotate it.

like image 171
Karan Alangat Avatar answered Nov 15 '22 05:11

Karan Alangat