用户操作
[即时聊天] [发私信] [加为好友]
曾巧ID:numenZQ
42207次访问,排名2821,好友0人,关注者0人。
numenZQ的文章
原创 29 篇
翻译 16 篇
转载 2 篇
评论 16 篇
最近评论
xh:不推荐修改web.xml,设置java_options更好
numenZQ:补充说明一点,使用java.util.zip包时,是以UTF-8编码格式读取的文件名,因此在中文windows操作系统(Windows操作系统默认字符集为:GBK)中使用时会导致文件名解析错误,因此需要使用org.apache.tools.zip.ZipEntry和 org.apache.tools.zip.ZipOutputStream类来解决这一问题。
numenZQ:这个是需要明确知道字符串的成分,该方法只是为了满足读取不同字符集相应字符串,还是以“多哈亚运会”为例:如果字符集为GBK,截取前6个字节,结果为:“多哈亚”;当字符集为UTF-8时,截取前6个字节,结果则为:“多哈”,这是因为GBK是双字节编码,而UTF-8是三字节变长编码,如果不分字符集来读取对应长度的字串,则会出现字串内容与预期不符,长度错误等问题。
lyazure:仔细看了你的代码,作用是从一个字符串中获取指定字节数的字符,不知道你要这么做的最终目的是用来做什么。除非明确知道字符串的成分,否则这种做法很难做到完美,比如你的代码中,假如出现要从“多哈亚运会”这样的字符串中截取7个字节,最终会截得3个字符。
Alexandre:ab8e44bc75204d49bf0c9fe68a2b2176 matura foto amatoriale
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    翻译 精通Micro3D v3基础技术收藏

    新一篇: 赛车游戏(一)通过蓝牙实现两个手机交互 | 旧一篇: 创建Mascot Capsule v3烟雾效果

    原文地址链接

     

    现在将带领你使用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类是用来处理所有变换的,例如:移动和旋转。程序在XY轴上移动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);
    ...
    }

    发表于 @ 2006年03月03日 22:46:00|评论(loading...)|编辑

    新一篇: 赛车游戏(一)通过蓝牙实现两个手机交互 | 旧一篇: 创建Mascot Capsule v3烟雾效果

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © numenzq