গতি যোগ করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
পর্দায় অবজেক্ট অঙ্কন করা OpenGL-এর একটি চমত্কার মৌলিক বৈশিষ্ট্য, কিন্তু আপনি Canvas
এবং Drawable
বস্তু সহ অন্যান্য অ্যান্ড্রয়েড গ্রাফিক্স ফ্রেমওয়ার্ক ক্লাসের সাথে এটি করতে পারেন। OpenGL ES টানা বস্তুগুলিকে তিনটি মাত্রায় বা অন্য অনন্য উপায়ে বাধ্যতামূলক ব্যবহারকারীর অভিজ্ঞতা তৈরি করার জন্য সরানো এবং রূপান্তর করার জন্য অতিরিক্ত ক্ষমতা প্রদান করে।
এই পাঠে, আপনি কীভাবে ঘূর্ণন সহ একটি আকৃতিতে গতি যোগ করতে হয় তা শিখে OpenGL ES ব্যবহারে আরও একটি ধাপ এগিয়ে যান।
একটি আকৃতি ঘোরান
OpenGL ES 2.0 দিয়ে একটি অঙ্কন বস্তু ঘোরানো তুলনামূলকভাবে সহজ। আপনার রেন্ডারারে, অন্য একটি রূপান্তর ম্যাট্রিক্স (একটি ঘূর্ণন ম্যাট্রিক্স) তৈরি করুন এবং তারপর এটিকে আপনার অভিক্ষেপ এবং ক্যামেরা ভিউ ট্রান্সফরমেশন ম্যাট্রিক্সের সাথে একত্রিত করুন:
কোটলিন
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)
}
জাভা
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 আকৃতিটিকে শুধুমাত্র একটি বৃদ্ধি ঘোরায় এবং তারপর requestRender()
জন্য একটি কলের জন্য অপেক্ষা করে। requestRender()
GLSurfaceView
কন্টেইনার থেকে:
কোটলিন
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
}
}
জাভা
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);
}
যদি না আপনি কোনো ব্যবহারকারীর ইন্টারঅ্যাকশন ছাড়াই বস্তু পরিবর্তন না করেন, তাহলে সাধারণত এই পতাকাটি চালু করা ভালো ধারণা। এই কোডটি আনকমেন্ট করার জন্য প্রস্তুত থাকুন, কারণ পরবর্তী পাঠ এই কলটিকে আবারও প্রযোজ্য করে।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 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-29 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."]]