选择显示字体大小

精通micro3d v3基础技术

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 移动模型

aff.netrans类是用来处理所有变换的,例如:移动和旋转。程序在x和y轴上移动3d模型只需要改变aff.netrans矩阵的两个变量。

aff.netrans.m03 += movex;
aff.netrans.m13 += movey;

例3 缩放模型

要实现3d模型的缩放,我们应该先用比例因数创建一个矩阵,然后添加这个矩阵到aff.netrans矩阵中。

aff.netrans scaletrans = new aff.netrans();
scaletrans.set(scalex,0,0,0,0,scaley,0,0,0,0,scalez,0);
// scaling the model
aff.netrans.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中的缩放模型是用的同样的技术。你创建一个aff.netrans对象来控制你的旋转数据,并把它的矩阵添加到模型的主aff.netrans里。

// 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;
}

...
aff.netrans rottrans = new aff.netrans();
//x roll
rottrans.setidentity();
rottrans.setrotationx(spinx);
aff.netrans.mul(rottrans);

//y roll
rottrans.setidentity();
rottrans setrotationy(spiny);
aff.netrans.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, &#125;;
...

protected void paint(graphics g) &#123;
...
g3.drawcommandlist( maintexture, 0, 0, layout, effect, command);
...
&#125;


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons