选择显示字体大小

创建mascot capsule v3烟雾效果

原文地址链接

 

       这个例子演示了在不使用高级粒子引擎的情况下,如何创建烟雾效果。主要是使用一些透明纹理精灵(sprite)来实现的。并让这些精灵向上移动,顺时针或逆时针旋转。这样用的好处为了使精灵始终正对这照相机。虽然这个例子是在mascot capsule v3实现的,不过同样的技术可以用于jsr-184中。

 

下载源代码

 

html/uploadpic/2005-12/200512233180841.gif" width=176 onload=javascript:resizepic(this) border=0>  html/uploadpic/2005-12/200512233180315.gif" width=128 onload=javascript:resizepic(this) border=0>

程序截图,用烟雾纹理来生成的烟雾效果 

 

下面是smoke类的代码:

import com.mascotcapsule.micro3d.v3.*;
import java.util.*;

public class smoke extends v3object{

    private figurelayout layout;
    private effect3d effect;
    private aff.netrans trans;

    // the point sprite command used when rendering the smoke.
    private final int command = graphics3d.primitve_point_sprites
                                graphics3d.pdata_point_sprite_params_per_cmd
                                graphics3d.pattr_blend_add
                                graphics3d.pattr_colorkey;

    // the number of sprites used.
    private final int num_point_sprites = 10; 
    private smokeitem []smokeitem = new smokeitem[num_point_sprites];

    // randomize the sprite rotation.
    private random r;

    // the smoke texture.
    private texture texture = null;
    private long ticks = 0; // frame counter.

    public smoke(int w, int h){
        try{
            texture = new texture("/res/smoke.bmp", true);
        }catch(exception e){
            e.printstacktrace();
        }

        layout = new figurelayout();
        effect = new effect3d();
        trans = new aff.netrans();
        trans.setidentity();

        effect.setshadingtype(effect3d.normal_shading);
        effect.setsemitransparentenabled(true);

        layout.setaff.netrans( trans );
        layout.setperspective(1, 4096, 512);
        layout.setcenter(w/2, h/2);

        trans.mul(lookat); // the lookat is from the super class.

        // create the smoke sprites.
        smokeitem[0] = new smokeitem(null);
        for(int i=1; i            smokeitem[i] = new smokeitem(smokeitem[i-1]);
        }
        smokeitem[num_point_sprites-1].start();
       
    }

    public void update(){
        trans.setidentity();
        trans.mul(lookat);
    }

    public void draw(graphics3d g3d){

        ticks++;
        for(int i=0; i            smokeitem[i].render(g3d);
        }

    }


    private class smokeitem{
// each item has a reference to the next item so it can
// be started after a certain time or in this case when the item // reaches a certain point.
         private smokeitem next = null;

         private int [] point = { 0, 0, 0 }; // position of the sprite
         private int [] texture = {10, 10, 512, 0, 0, 128, 128,
graphics3d.point_sprite_perspective};
         private int rot; // the rotation of the point sprite,
     // this is randomized
    //   w0, h0, a0, x00, y00, x01, y01, f0,
    //   w1, h1, a1, x10, y10, x11, y11, f1, ...

        private int []normal = new int[] {4096};
        private int []color = new int[] {0x00};

        private boolean started = false;
        private random r = new random();
        private int mod;
       
        public smokeitem(smokeitem next){
            this.next = next;
           
            reset();
        }

        public void start(){
            started = true;
        }

        /*
         * reset the size and position of the sprite
         */
        private void reset(){
            texture[0] = 10;
            texture[1] = 10;
            point[1]  = 0;

            rot = -16 + r.nextint(32);
        }

        /*
         * the sprite is scaled and moved before rendered to the screen.
         */
        protected void render(graphics3d g3d){
            if(started && fps.fps > 0){
               
                mod = fps.fps/5;
                mod = mod <1?1:mod;
                   
                if(ticks%mod==0)&#123;
                    if(texture[0] < 80)&#123;
                        // make the size of the sprite bigger.
                        texture[0]++;
                        texture[1]++;
                    &#125;
                &#125;
               
                mod = fps.fps/10;
                mod = mod <1?1:mod;
               
                if(ticks%mod==0)&#123;
                    point[1] ++; // add 1 to the y position.
                    if(point[1] == 180)&#123;
                        reset(); // start over.
                    &#125;
                    if(point[1] > 18 && next != null)&#123;
                        next.start(); // start moving the next sprite
                    &#125;
                &#125;

                texture[2] += rot;
            &#125;
            // render the sprite.
            g3d.renderprimitives(texture, 0, 0, layout, effect, command,
1, point, normal, texture, color);
               
        &#125;
       
    &#125;
   
&#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