国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

精通Micro3D v3基礎技術

2019-11-18 16:14:23
字體:
來源:轉載
供稿:網友

原文地址鏈接

 

現在將帶領你使用Mascot Capsule Micro 3D v3進行3D開發,這里有十個簡單的例子將一步一步的向你介紹你必須掌握的基本技術。所有例子都基于同一個核心代碼去展示一個簡單的3D模型。下面是這些例子的基本組織和內容:

 

例1 簡單的顯示這是3D模型

例2 按下數字鍵‘2’,’8’,’4’,’6’)實現3D模型上下左右移動

例3 按下數字鍵’7’和’9’實現3D模型的縮放效果(注意:縮放模型不是讓該模型在Z軸上移動)

例4 按下”Light”鍵實現在3D場景中添加燈光效果

例5 按下”Perspective”鍵實現3D模型在平行投影和透視投影之間切換

例6 使用手機的方向鍵實現3D模型的旋轉

例7 給3D模型添加動畫效果

例8 添加兩個動畫,使用數字鍵’1’進行切換

例9 顯示多個3D模型

例10 顯示如何在屏幕上繪制一個原始模型

 

所有的例子可以通過下面的鏈接下載:

下載源代碼

 

注意:這些程序是使用的Micro3D技術,但并不是很好的編碼實踐。例如,程序并沒有編碼實現處理中斷退出該程序時正常的軟鍵,只得一直按住”back”鍵來退出程序

       大多數代碼都很容易理解,并不需要更多的解釋,不過下面還是有些要點需要論述。

 

例1 簡單的顯示這是3D模型

下面幾行是基本的3D模型和紋理的導入和設置:

figure = new Figure("/example/DemoMIDP/test_model_robo.mbac");
mainTexture = new Texture("/example/DemoMIDP/tex_001.bmp", true);
figure.setTexture(mainTexture);

下面是在Canvas里繪制3D世界

PRivate Graphics3D g3 = new Graphics3D();

protected void paint(Graphics g) {
 ...
  g3.bind(g);
   g3.renderFigure(figure, 0, 0, layout, effect);
    //Flush to screen
    g3.flush();
            //Release the Graphics 3D object
            g3.release(g);

}

例2 移動模型

AffineTrans類是用來處理所有變換的,例如:移動和旋轉。程序在X和Y軸上移動3D模型只需要改變AffineTrans矩陣的兩個變量。

affineTrans.m03 += moveX;
affineTrans.m13 += moveY;

例3 縮放模型

要實現3D模型的縮放,我們應該先用比例因數創建一個矩陣,然后添加這個矩陣到AffineTrans矩陣中。

AffineTrans scaleTrans = new AffineTrans();
scaleTrans.set(scaleX,0,0,0,0,scaleY,0,0,0,0,scaleZ,0);
// Scaling the model
affineTrans.mul(scaleTrans);

例4 添加燈光

燈光非常容易設置。一個方向向量和一個亮度值就足夠了

private Vector3D dir = new Vector3D(-3511, 731, 878); // Light vector
private final int dirIntensity = 4096; // Light intensity
private final int ambIntensity = 1755; // Ambient light intensity
...
light = new Light(dir,dirIntensity,ambIntensity);
effect = new Effect3D( light, Effect3D.NORMAL_SHADING, true, null);
g3.renderFigure(figure, 0, 0, layout, effect);
...

例5 投影

你可以3D模型上使用透視或平行投影。通過簡單的調用實現兩者間轉換。

// Camera distance
private final static int persNear = 1; // Minimum distance to the camera
private final static int persFar = 4096; // Maximum distance to the camera
private final static int persAngle = 682; // Angle
...
//Setting the projection method
if(persEnabled){
 layout.setPerspective(persNear, persFar, persAngle);
}else{
 layout.setParallelSize(800, 800);
}

例6 旋轉模型

旋轉3D模型與例3中的縮放模型是用的同樣的技術。你創建一個AffineTrans對象來控制你的旋轉數據,并把它的矩陣添加到模型的主AffineTrans里。

// Rotation value
public final static int SPIN_X_PLUS = 100; // Increase or decrease value of the rotation around X axis
public final static int SPIN_Y_PLUS = 100; // Increase or decrease value of the rotation around Y axis
private static int spinX = 0; // X axis rotation value
private static int spinY = 0; // Y axis rotation value
...
kc = getGameAction(kc);
switch (kc) {
case Canvas.UP: // roll up
  setSpinX(-SPIN_X_PLUS);
  break;
 case Canvas.DOWN: // roll down
  setSpinX(SPIN_X_PLUS);
  break;
case Canvas.LEFT: // roll left
  setSpinY(-SPIN_Y_PLUS);
  break;
 case Canvas.RIGHT: // roll right
  setSpinY(SPIN_Y_PLUS);
  break;
 default:
  break;
}
...
AffineTrans rotTrans = new AffineTrans();
//X roll
rotTrans.setIdentity();
rotTrans.setRotationX(spinX);
affineTrans.mul(rotTrans);
//Y roll
rotTrans.setIdentity();
rotTrans setRotationY(spinY);
affineTrans.mul(rotTrans);

例7 模型中的動畫效果

這個例子為你演示如何導入.mtra文件里的動畫數據并應用于你的3D模型。

action = new ActionTable("/example/DemoMIDP/action_01.mtra");
...
frame += action.getNumFrames(0)/10;
if( frame >= action.getNumFrames(0) ){
 frame = 0;
}
figure.setPosture(action, 0, frame);
g3.renderFigure(figure, 0, 0, layout, effect);

例8 模型中的多個動畫效果

使用兩個不同的動畫文件比不比使用一個動畫文件難多少。僅僅是導入兩個文件并在每次3D模型繪制時選擇其中一個。

action[0] = new ActionTable("/example/DemoMIDP/action_01.mtra");
action[1] = new ActionTable("/example/DemoMIDP/action_02.mtra");
...  
case Canvas.KEY_NUM1: // action
 actNo = 1;
 frame = 0;
 break;
...
frame += action[actNo].getNumFrames(0)/10;
if( frame >= action[actNo].getNumFrames(0) ){
frame = 0;
 actNo = 0;
}
figure.setPosture(action[actNo], 0, frame);
g3.renderFigure(figure, 0, 0, layout, effect);

例9 顯示多個3D模型

使用多個3D模型同在一個模型中使用多個動畫一樣的簡單。從新從一個新的3D模型.mbac文件去創建一個新的figure實例與創建第一個實例的方法相同。

// One Figure created from a mbac file...
figure = new Figure("/example/DemoMIDP/test_model_robo.mbac");
mainTexture = new Texture("/example/DemoMIDP/tex_001.bmp", true);
figure.setTexture(mainTexture);

//... And another Figure created from another mbac file.
figureBg = new Figure("/example/DemoMIDP/test_model_haikei.mbac");

例10 用原型繪制

即使Micro3D v3主要是使用預先建立的模型進行3D建模編程,你也可以直接從原始的數組命令來創建3D圖形。

// Use this array of commands to show a triangle with texture....
static int[] command = {
 Graphics3D.COMMAND_LIST_VERSION_1_0,
Graphics3D.PRIMITVE_TRIANGLES
 Graphics3D.PDATA_NORMAL_PER_FACE
      Graphics3D.PDATA_TEXURE_COORD
 Graphics3D.PATTR_LIGHTING
      Graphics3D.PATTR_SPHERE_MAP
Graphics3D.PATTR_BLEND_HALF
 (1<<16),   // Nbr of primitives, in this case just one triangle
 0, 0, 0,           // The triangle's ccordinates
 200, 0, 0,
 0, 200, 0,
 0, 0, 4096,            // The Normal
      0,255,255,255, 0, 0,   // The coordinates for the texture
 Graphics3D.COMMAND_END, };
...
protected void paint(Graphics g) {
...
g3.drawCommandList( mainTexture, 0, 0, layout, effect, command);
...
}


 

(出處:http://m.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昔阳县| 襄城县| 祁东县| 南丰县| 江山市| 阜平县| 大冶市| 麟游县| 宣城市| 保定市| 响水县| 平安县| 察哈| 延长县| 怀来县| 林口县| 灵川县| 黄平县| 蚌埠市| 定结县| 巴林右旗| 瑞安市| 南康市| 精河县| 金湖县| 噶尔县| 澳门| 平舆县| 黔西| 古交市| 靖宇县| 福贡县| 石渠县| 新沂市| 如皋市| 壶关县| 铅山县| 钦州市| 崇州市| 始兴县| 扎兰屯市|