网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > J2EE/J2ME
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.J2EE中的异常管理及错误跟踪.
.保护自己的MIDlet程序之二:Time.
.JBosseclipseEJB学习体会.
.JBOSS4数据源配置大全.
.Spring 系列:当 Hibernate 遇上.
.如何成为一个成功的Jsp程序员?.
.介绍J2ME可选包FileConnection.
.如何写自己的Type3JDBC驱动.
.JNDI 常见问题.
.Java ME应用设计指南之联网重定向.
.使用Filter记录日志、来访IP、UR.
.推荐2本学J2ME的书~(新手必看).
.对J2EE中的DAO组件编写单元测试.
.选择:J2EE还是.NET,这是一个问.
.J2ME网络程序中移动资费页面的处.
.hibernate的中文问题的解决方案.
.J2ME内存优.
.BlueTooth探索系列(一)---JSR0.
.MIDlet国际化——JSR238.
.Velocity用户手册.

精通Micro3D v3基础技术

发表日期:2007-12-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);
...
}


 

(出处:)


上一篇:创建Mascot Capsule v3烟雾效果 人气:573
下一篇:JSR-184里封装照相机的look-at方法 人气:615
浏览全部J2EE/J2ME的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐