الرئيسية / مقرر الوسائط المتعددة / الفصل 2 الجزء 2

الفصل 2 (الجزء 2): Inverse kinematics, 3D effects and the Deco tool

Bone structures, 3D translation and rotation, perspective, and pattern effects

إزاي تحرّك شخصية بمفاصل، وإيه أدوات الـ 3D والمنظور على المسرح، وأداة Deco اللي بترسم بيئات كاملة بسرعة.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

ذراع بمفصلين

أمثلة كود

أمثلة قصيرة وبسيطة

كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.

المثال ١: نص المسرح

const stageW = 550, stageH = 400;const cx = stageW / 2, cy = stageH / 2;console.log("center: (" + cx + ", " + cy + ")");

    

المثال ٢: إسقاط المنظور

const f = 300;                 // focal lengthconst near = 120 * f / (0 + f);   // point at z = 0const far  = 120 * f / (200 + f); // same point at z = 200console.log("near: " + near);console.log("far: " + far);

    

المثال ٣: طرف الذراع

const L1 = 100, L2 = 50;const a1 = 0, a2 = Math.PI / 2;   // first bone flat, second turns 90 degreesconst x = L1 * Math.cos(a1) + L2 * Math.cos(a1 + a2);const y = L1 * Math.sin(a1) + L2 * Math.sin(a1 + a2);console.log("end: (" + x.toFixed(1) + ", " + y.toFixed(1) + ")");

    

اختبار قصير

اختبر فهمك

1. Inverse kinematics animates an image by:

2. The bone structure created by the bone tool is called:

3. The default stage size in the notes is:

4. The perspective angle property is used for:

5. The Deco tool is used to:

تمارين

جرّب بإيدك

التمرين 1

نقطة في مكان (80, 60) على المسرح. طبّق عليها translation بمقدار (20, -10) واطبع مكانها الجديد بالصيغة (x, y).

A point sits at (80, 60) on the stage. Apply a translation of (20, -10) and print its new place as (x, y).

Starter code:

const p = { x: 80, y: 60 };// TODO: move p by (20, -10)// TODO: print "(" + p.x + ", " + p.y + ")"

التمرين 2

اكتب دالة project(x, z, f) بترجّع الإسقاط المنظوري x * f / (z + f)، واطبع project(150, 100, 300).

Write project(x, z, f) returning the perspective projection x * f / (z + f), and print project(150, 100, 300).

Starter code:

function project(x, z, f) {  // TODO: return x * f / (z + f)}console.log(project(150, 100, 300));

مشروع صغير في آخر المحاضرة

ذراع بمفصلين بترسم قوس

الداتا: arm-2bones: عظمتين من عندنا، الأولى 100 والتانية 50، والمفصل الثاني بيلف من 0 لـ 90 درجة.

License / source: Our own arm; Math reference by MDN (link only, nothing copied). Reference page

الخطوات

  1. خلي أول عظمة ثابتة على المحور الأفقي، والتانية بتزيد زاويتها 30 درجة كل مرة من 0 لـ 90.
  2. احسب مكان طرف الذراع كل مرة: x و y بمجموع الإسقاطات.
  3. اطبع الزاوية ومكان الطرف، وشوف الطرف بيرسم قوس.

Starter code:

const L1 = 100, L2 = 50, a1 = 0;// TODO: for a2 in 0, 30, 60, 90 degrees://   x = L1*cos(a1) + L2*cos(a1+a2), y = L1*sin(a1) + L2*sin(a1+a2)//   print the angle and the end point with 1 decimal

مشروع نهاية الفصل

ملف المشروع العملي للفصل 2

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

Credits: the topic order follows the course notes "Multimedia and Computer Graphics" by Dr. Muhammad Kashif Saeed (Applied College, Muhayil, King Khalid University), shared by the course owner. The explanations, diagrams, data and code in this lecture are our own; we copy nothing from the notes. Extra reference: Multimedia and Computer Graphics notes, Dr. Muhammad Kashif Saeed, King Khalid University (elc.kku.edu.sa) - own text, structure follows the notes.