Log in or register to post comments

rotate 3D with Button

January 27, 2013 - 11:13pm #1

how to rotate 3d with button in ImageTarget?

rotate 3D with Button

January 29, 2013 - 6:00am #15

Great, you're welcome!

rotate 3D with Button

January 29, 2013 - 4:54am #14

SOLVED

 

thank you AlessandroB

rotate 3D with Button

January 29, 2013 - 3:10am #13

OK, then a possible simple solution is to use only one script, attaching it to ARCamera (instead of attaching them to each teapot model), and then modify the code so to retrieve all your trackables in the "start()" method and then rotate them all in the "Update()" method, as shown in this example:

public class RotateButtonBheaviour : MonoBehaviour {
	
	private bool mIsRotated = false;
	private bool mMustRotate = false;
	
	private GameObject chipsTarget;
	private GameObject stonesTarget;
	
	// Use this for initialization
	void Start () {
		chipsTarget = GameObject.Find ("ImageTargetChips");
		stonesTarget = GameObject.Find ("ImageTargetStones");
	}
	
	// Update is called once per frame
	void Update () {
		if (mMustRotate && !mIsRotated) {
			//Rotate all models 90 degrees around Y
			if (chipsTarget != null) {
				GameObject modelUnderChipsTrackable = chipsTarget.transform.GetChild(0).gameObject;
				modelUnderChipsTrackable.transform.RotateAround(new Vector3(0,1,0), Mathf.PI / 2);
				
			}
			if (stonesTarget != null) {
				GameObject modelUnderStonesTrackable = stonesTarget.transform.GetChild(0).gameObject;
				modelUnderStonesTrackable.transform.RotateAround(new Vector3(0,1,0), Mathf.PI / 2);
			}
			mIsRotated = true;
			mMustRotate = false;
		}
	}
	
	void OnGUI() {
		if (GUI.Button(new Rect(0,0,100,50), "Rotate")) {
			if (!mIsRotated) {
				mMustRotate = true;
			}
		}
	}
}
Note that you will need to adjust the names of your trackables (in the example I am using the ImageTargetChips and ImageTargetStones names which work with the ImageTarget sample).

 

rotate 3D with Button

January 29, 2013 - 1:59am #12

yess, I need single button for rotate all 3D models. 

rotate 3D with Button

January 29, 2013 - 1:45am #11

Thanks for the script (which looks fine, by the way);

I think the problem is just the fact that you use the same Button (the "Rotate" button) for all your models, but in practice when you touch the button, there is only one button touch event generated and this is consumed by only one model.

So, just for confirmation, do you need a single button to rotate all your 3D models at the same time with a single click ?

 

rotate 3D with Button

January 29, 2013 - 1:30am #10
using UnityEngine;
using System.Collections;

public class RotateButtonBheaviour : MonoBehaviour {
	private bool mIsRotated = false;
    private bool mMustRotate = false;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	 void Update () {
        if (mMustRotate && !mIsRotated) {
            //Rotate 45 degrees around Y 
            this.gameObject.transform.RotateAround(new Vector3(0,1,0), Mathf.PI / 4);
            mIsRotated = true;
            mMustRotate = false;
			
        }
    }
     
    void OnGUI() {
        if (GUI.Button(new Rect(0,0,100,50), "Rotate")) {
            if (!mIsRotated) {
                mMustRotate = true;
				
            }
			else
			{
				if(mMustRotate = true)
				{
					mIsRotated = false;
				}
			}
			
			
}
		if (GUI.Button( new Rect (0,60,100,50),"object description"))
		{
			//belum diisi
		}
		if (GUI.Button(new Rect (0,120,100,50),"Exit"))
		{
				Application.Quit();
				
		}
	}
	
}

 

this the script code.

This works only for the last object I attach

rotate 3D with Button

January 29, 2013 - 1:18am #9

Weird, this should not happen. Can you post the script code here (if you modified it somehow ) ?

rotate 3D with Button

January 28, 2013 - 7:31pm #8

I attach the script to each teapot model of each target, but the only one model that works?

rotate 3D with Button

January 28, 2013 - 6:21am #7

You're welcome.

rotate 3D with Button

January 28, 2013 - 6:20am #6

Thank You AlessandroB

Its Work. 

 

rotate 3D with Button

January 28, 2013 - 3:15am #5

Hi, based on your inputs via PM,

I can suggest the following as a basic example showing the key concepts:

  1. create a script and attach it to the "teapot" model (or your own model)
  2. if you have multiple targets, attach the script to each teapot model of each target
  3. implement OnGUi and Update() methods in the script so to trigger your rotations

As a basic example, here is one which will rotate your teapot by 90 degrees around Y:

public class RotateButtonBheaviour : MonoBehaviour {
	
	private bool mIsRotated = false;
	private bool mMustRotate = false;
	
	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
		if (mMustRotate && !mIsRotated) {
			//Rotate 90 degrees around Y 
			this.gameObject.transform.RotateAround(new Vector3(0,1,0), Mathf.PI / 2);
			mIsRotated = true;
			mMustRotate = false;
		}
	}
	
	void OnGUI() {
		if (GUI.Button(new Rect(0,0,100,50), "Rotate")) {
			if (!mIsRotated) {
				mMustRotate = true;
			}
		}
	}
}

You wil need to extend / adjust the script code for your specific application needs.

I hope this helps.

rotate 3D with Button

January 28, 2013 - 2:20am #4

Hi, can you provide a few more details ?

for instance, do you want to display a Button somewhere on your view and then rotate the 3D model associated to an ImageTarget (for instance the Teapot model) when you press that button ?

 

rotate 3D with Button

January 28, 2013 - 2:12am #3

I modification from ImageTarget.unityPackage

I want rotate 3D with button. 

rotate 3D with Button

January 28, 2013 - 2:03am #2

Hi diwan,

can you be a bit more specific ? are you aiming to do that in Android ? iOS ? or in Unity ?

 

Log in or register to post comments