New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple tutorial onTouchEvent #428
Comments
You will have to write this behavior on your own. Once you have onTouchEvent working its just a matter of capturing the values you want and applying them to the camera position. There are lots of tutorials around for handling mouse or touch events, and I think that's the best place to start. You can use the RajawaliExamples accelerometer example to get you going. |
onTouchEvent is not Rajawali exclusive, so the Android tutorials apply in most cases. The code I posted in #258 is complete, so you can also copy and paste that, tie in a few variables, and start picking that apart. Aside from those options you will have to research and test this on your own. There is no tutorial written up for this in Rajawali. |
I tried to use your code #258 but doesn't work for me. Was i wrong or your code is part of the renderer class? Or maybe should i implement the OnTouchListener and use the onTouch method still in the renderer class? |
Put my code in the renderer |
I have already done, but doesn't work! |
That implements touch handling and gestures. It is the same way you implement basic touch handling for wallpapers. |
@ToxicBakery I have not still tried your solution but i wonder way the solution of Davhed doesn't work, since for him it is ok. |
Without seeing your code we can only speculate. |
Since the only thing you need to do it "override" This is a complete example: import javax.microedition.khronos.opengles.GL10;
import rajawali.renderer.RajawaliRenderer;
import android.content.Context;
public class WallpaperRenderer extends RajawaliRenderer{
public WallpaperRenderer(Context context) {
super(context);
setFrameRate(60);
}
@Override
public void initScene() {
//Scene building happens here
}
@Override
public void onTouchEvent(MotionEvent me) {
//The MotionEvent "me" has all of the data you need to make animation based on touch
if (me.getAction() == MotionEvent.ACTION_DOWN) { //Called once at the start of the touch
System.out.println(me.getAction() + " -- " + me.getX() + ", " + me.getY());
}
if (me.getAction() == MotionEvent.ACTION_MOVE) { //Called repeatedly as touch point moves
System.out.println(me.getAction() + " -- " + me.getX() + ", " + me.getY());
}
if (me.getAction() == MotionEvent.ACTION_UP) { //Called once at the end of the touch
System.out.println(me.getAction() + " -- " + me.getX() + ", " + me.getY());
}
try {
Thread.sleep(15); //Small delay to keep touch events from overflowing and decreasing performance
} catch (Exception e) {
}
}
@Override
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
}
} And there is a ton of data you can get from the |
OK, the above code works fine, because it is simple. Now, the feat for me is to apply simple actions like move or rotate a camera or an object when the finger is moving. I'm trying to adapt your code #258 that is more articulated and little different then I would like but it's hard. |
Try something fresh and new. My code is hacked together cause I'm not a mathematician. |
Please. In the swipeCamera() method there is a variable call "numScreens". What it refers to? Maybe to the number of wallpaper's home screens. How can i get it? |
Its a preference I created. The user chooses from a list of three options. If you are looking to intimately tie your home screen animation to your scene animation you can try using |
This is how I used it in that same app - @Override //This method moves the camera using the Android home screen swipe output. It's a better way, but not always supported
public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) {
float zOffset = (50*xOffset)-25;
mCamera.setX(25-(-((curZPos + zOffset)/50)));
mCamera.setZ(curZPos + zOffset);
} |
I tried onOffsetsChanged but it moves the camera only in one way. |
Easy way to achieve it by using ArcballCamera
|
I would like a simple tutorial on how to move a camera or rotate an object when a touch event occurs.
Thanks!
The text was updated successfully, but these errors were encountered: