मोशन जोड़ें
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
स्क्रीन पर ऑब्जेक्ट ड्रॉइंग करना OpenGL की एक काफ़ी बेसिक सुविधा है, लेकिन आप इसे दूसरे
Android ग्राफ़िक फ़्रेमवर्क की क्लास, जिनमें Canvas
और
Drawable
ऑब्जेक्ट. OpenGL ES में
ड्रॉ किए गए ऑब्जेक्ट को तीन डाइमेंशन में या किसी दूसरे तरीके से मूव करना या बदलना
उपयोगकर्ताओं को बेहतरीन अनुभव देना.
इस लेसन में, OpenGL ES का इस्तेमाल करने की दिशा में एक और कदम उठाया गया है. इसके लिए, मोशन जोड़ने का तरीका सीखें
का आकार घुमाया जा सकता है.
आकार को घुमाना
OpenGL ES 2.0 की मदद से, ड्रॉइंग ऑब्जेक्ट को घुमाना बेहद आसान है. अपने रेंडरर में,
एक अन्य रूपांतरण आव्यूह (एक घूर्णन आव्यूह) और फिर इसे अपने प्रोजेक्शन के साथ मिलाएं और
कैमरा व्यू ट्रांसफ़ॉर्मेशन मैट्रिक्स:
Kotlin
private val rotationMatrix = FloatArray(16)
override fun onDrawFrame(gl: GL10) {
val scratch = FloatArray(16)
...
// Create a rotation transformation for the triangle
val time = SystemClock.uptimeMillis() % 4000L
val angle = 0.090f * time.toInt()
Matrix.setRotateM(rotationMatrix, 0, angle, 0f, 0f, -1.0f)
// Combine the rotation matrix with the projection and camera view
// Note that the vPMatrix factor *must be first* in order
// for the matrix multiplication product to be correct.
Matrix.multiplyMM(scratch, 0, vPMatrix, 0, rotationMatrix, 0)
// Draw triangle
mTriangle.draw(scratch)
}
Java
private float[] rotationMatrix = new float[16];
@Override
public void onDrawFrame(GL10 gl) {
float[] scratch = new float[16];
...
// Create a rotation transformation for the triangle
long time = SystemClock.uptimeMillis() % 4000L;
float angle = 0.090f * ((int) time);
Matrix.setRotateM(rotationMatrix, 0, angle, 0, 0, -1.0f);
// Combine the rotation matrix with the projection and camera view
// Note that the vPMatrix factor *must be first* in order
// for the matrix multiplication product to be correct.
Matrix.multiplyMM(scratch, 0, vPMatrix, 0, rotationMatrix, 0);
// Draw triangle
mTriangle.draw(scratch);
}
अगर ये बदलाव करने के बाद आपका त्रिभुज नहीं बदलता है, तो पक्का करें कि आपने
GLSurfaceView.RENDERMODE_WHEN_DIRTY
अभी तक किसी भी व्यक्ति ने चेक इन नहीं किया है
सेटिंग देखें, जैसा कि अगले सेक्शन में बताया गया है.
लगातार रेंडरिंग चालू करें
अगर आपने इस क्लास में, उदाहरण के तौर पर दिए गए कोड को सही से फ़ॉलो किया है, तो
आप उस लाइन पर टिप्पणी करेंगे जो रेंडर मोड को सिर्फ़ गंदी होने पर ही ड्रॉ करने के लिए सेट करती है, नहीं तो OpenGL
आकार को सिर्फ़ एक क्रम से घुमाता है और फिर GLSurfaceView
कंटेनर से requestRender()
को कॉल किए जाने का इंतज़ार करता है:
Kotlin
class MyGLSurfaceView(context: Context) : GLSurfaceView(context) {
init {
...
// Render the view only when there is a change in the drawing data.
// To allow the triangle to rotate automatically, this line is commented out:
// renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY
}
}
Java
public class MyGLSurfaceView(Context context) extends GLSurfaceView {
...
// Render the view only when there is a change in the drawing data.
// To allow the triangle to rotate automatically, this line is commented out:
//setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
जब तक उपयोगकर्ता के इंटरैक्शन के बिना ऑब्जेक्ट बदल जाते हैं, तब तक यह ज़रूरी है कि
फ़्लैग करने की सुविधा चालू की गई. इसलिए, इस कोड को हटाने के लिए तैयार रहें, क्योंकि अगले लेसन में यह कॉल लागू किया जा सकता है
एक बार फिर से.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया."],[],[],null,["# Add motion\n\nDrawing objects on screen is a pretty basic feature of OpenGL, but you can do this with other\nAndroid graphics framework classes, including [Canvas](/reference/android/graphics/Canvas) and\n[Drawable](/reference/android/graphics/drawable/Drawable) objects. OpenGL ES provides additional capabilities for\nmoving and transforming drawn objects in three dimensions or in other unique ways to create\ncompelling user experiences.\n\nIn this lesson, you take another step forward into using OpenGL ES by learning how to add motion\nto a shape with rotation.\n\nRotate a shape\n--------------\n\nRotating a drawing object with OpenGL ES 2.0 is relatively simple. In your renderer, create\nanother transformation matrix (a rotation matrix) and then combine it with your projection and\ncamera view transformation matrices: \n\n### Kotlin\n\n```kotlin\nprivate val rotationMatrix = FloatArray(16)\n\noverride fun onDrawFrame(gl: GL10) {\n val scratch = FloatArray(16)\n\n ...\n\n // Create a rotation transformation for the triangle\n val time = SystemClock.uptimeMillis() % 4000L\n val angle = 0.090f * time.toInt()\n Matrix.setRotateM(rotationMatrix, 0, angle, 0f, 0f, -1.0f)\n\n // Combine the rotation matrix with the projection and camera view\n // Note that the vPMatrix factor *must be first* in order\n // for the matrix multiplication product to be correct.\n Matrix.multiplyMM(scratch, 0, vPMatrix, 0, rotationMatrix, 0)\n\n // Draw triangle\n mTriangle.draw(scratch)\n}\n```\n\n### Java\n\n```java\nprivate float[] rotationMatrix = new float[16];\n@Override\npublic void onDrawFrame(GL10 gl) {\n float[] scratch = new float[16];\n\n ...\n\n // Create a rotation transformation for the triangle\n long time = SystemClock.uptimeMillis() % 4000L;\n float angle = 0.090f * ((int) time);\n Matrix.setRotateM(rotationMatrix, 0, angle, 0, 0, -1.0f);\n\n // Combine the rotation matrix with the projection and camera view\n // Note that the vPMatrix factor *must be first* in order\n // for the matrix multiplication product to be correct.\n Matrix.multiplyMM(scratch, 0, vPMatrix, 0, rotationMatrix, 0);\n\n // Draw triangle\n mTriangle.draw(scratch);\n}\n```\n\nIf your triangle does not rotate after making these changes, make sure you have commented out the\n[GLSurfaceView.RENDERMODE_WHEN_DIRTY](/reference/android/opengl/GLSurfaceView#RENDERMODE_WHEN_DIRTY)\nsetting, as described in the next section.\n\nEnable continuous rendering\n---------------------------\n\nIf you have diligently followed along with the example code in this class to this point, make\nsure you comment out the line that sets the render mode only draw when dirty, otherwise OpenGL\nrotates the shape only one increment and then waits for a call to [requestRender()](/reference/android/opengl/GLSurfaceView#requestRender()) from the [GLSurfaceView](/reference/android/opengl/GLSurfaceView) container: \n\n### Kotlin\n\n```kotlin\nclass MyGLSurfaceView(context: Context) : GLSurfaceView(context) {\n\n init {\n ...\n // Render the view only when there is a change in the drawing data.\n // To allow the triangle to rotate automatically, this line is commented out:\n // renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY\n }\n}\n```\n\n### Java\n\n```java\npublic class MyGLSurfaceView(Context context) extends GLSurfaceView {\n ...\n // Render the view only when there is a change in the drawing data.\n // To allow the triangle to rotate automatically, this line is commented out:\n //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);\n}\n```\n\nUnless you have objects changing without any user interaction, it's usually a good idea have this\nflag turned on. Be ready to uncomment this code, because the next lesson makes this call applicable\nonce again."]]