原文地址链接
这个例子演示了在不使用高级粒子引擎的情况下,如何创建烟雾效果。主要是使用一些透明纹理精灵(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[num_point_sprites-1].start();
}
public void update(){
trans.setidentity();
trans.mul(lookat);
}
public void draw(graphics3d g3d){
ticks++;
for(int i=0; i
}
}
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){
if(texture[0] < 80){
// make the size of the sprite bigger.
texture[0]++;
texture[1]++;
}
}
mod = fps.fps/10;
mod = mod <1?1:mod;
if(ticks%mod==0){
point[1] ++; // add 1 to the y position.
if(point[1] == 180){
reset(); // start over.
}
if(point[1] > 18 && next != null){
next.start(); // start moving the next sprite
}
}
texture[2] += rot;
}
// render the sprite.
g3d.renderprimitives(texture, 0, 0, layout, effect, command,
1, point,
}
}
}
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 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器