commit c94e8f43f4b2cc609d56ca6860337d658fbf4b8d Author: Victor Date: Wed Nov 14 23:01:22 2018 +0200 Initial diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..ea9910e --- /dev/null +++ b/build.xml @@ -0,0 +1,83 @@ + + + + + + Builds, tests, and runs the project . + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..5aee582 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Classpath to J2ME Ant extension library (libs.j2me_ant_ext.classpath property) is not set. For example: location of mobility/modules/org-netbeans-mobility-antext.jar file in the IDE installation directory. + Platform home (platform.home property) is not set. Value of this property should be ${platform.active.description} emulator home directory location. + Platform boot classpath (platform.bootclasspath property) is not set. Value of this property should be ${platform.active.description} emulator boot classpath containing all J2ME classes provided by emulator. + Must set src.dir + Must set build.dir + Must set dist.dir + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preprocessed.dir + + + + + + + + + + + + + + + + + + Must set build.classes.dir + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must set obfuscated.classes.dir + + + + Must set obfuscated.classes.dir + Must set obfuscator.srcjar + Must set obfuscator.destjar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preverify.classes.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroEdition-Configuration: ${platform.configuration} + + MicroEdition-Configuration: ${platform.configuration} + + + + MicroEdition-Profile: ${platform.profile} + + MicroEdition-Profile: ${platform.profile} + + + + Must set dist.jad + + + + + + + + + + + + + + + + + + + + + + + + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.jad} + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.manifest} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Must set dist.javadoc.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${all.configurations} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property deployment.${deployment.method}.scriptfile not set. The property should point to an Ant script providing ${deployment.method} deployment. + + + + + + + + Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set. + + + + + + + + + Active project configuration: @{cfg} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property build.root.dir is not set. By default its value should be \"build\". + Property dist.root.dir is not set. By default its value should be \"dist\". + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..cc9b239 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +build.xml.data.CRC32=5a91fce0 +build.xml.script.CRC32=5c40033b +build.xml.stylesheet.CRC32=9c6a911d +nbproject/build-impl.xml.data.CRC32=5a91fce0 +nbproject/build-impl.xml.script.CRC32=93ea4cdb +nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..56bcf2c --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +#Sun, 08 Jan 2012 13:36:46 +0200 +#Sun Nov 29 18:25:33 EET 2009 +netbeans.user=C\:\\Users\\aNNiMON\\.netbeans\\7.1 +javadoc.preview=true +config.active= +deployment.counter=31 +app-version.autoincrement=true +deployment.number=0.0.30 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..0cdc92c --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,143 @@ +abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,SEMC_EXT_JP8=1.0,ColorScreen,OBEX=1.0,NokiaUI=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,lib/semc_ext_jp8.jar=1.0,MascotV3=1.0,JSR75=1.0,JSR184=1.1,SATSAPKI=1.0,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0, +all.configurations=\ +application.args= +application.description= +application.description.detail= +application.name= +application.vendor=Vendor +build.classes.dir=${build.dir}/compiled +build.classes.excludes=**/*.java,**/*.form,**/*.class,**/.nbintdb,**/*.mvd,**/*.wsclient,**/*.vmd +build.dir=build/${config.active} +build.root.dir=build +debug.level=debug +debugger.timeout= +deployment.copy.target=deploy +deployment.instance=default +deployment.jarurl=${dist.jar} +deployment.method=NONE +deployment.override.jarurl=false +dist.dir=dist/${config.active} +dist.jad=Mobi3DSpaceLocation.jad +dist.jar=Mobi3DSpaceLocation.jar +dist.javadoc.dir=${dist.dir}/doc +dist.root.dir=dist +extra.classpath= +file.reference.builtin.ks=${netbeans.user}/config/j2me/builtin.ks +filter.exclude.tests=false +filter.excludes= +filter.more.excludes=**/overview.html,**/package.html +filter.use.standard=true +jar.compress=true +javac.debug=true +javac.deprecation=false +javac.encoding=UTF-8 +javac.optimize=false +javac.source=1.3 +javac.target=1.3 +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +libs.classpath= +main.class= +main.class.class=applet +manifest.apipermissions= +manifest.file=manifest.mf +manifest.is.liblet=false +manifest.jad= +manifest.manifest= +manifest.midlets=MIDlet-1: MSL,,Main\n +manifest.others=MIDlet-Vendor: aNNiMON\nMIDlet-Name: Mobi3DSpaceLocation\nMIDlet-Version: 1.0\n +manifest.pushregistry= +name=Mobi3DSpaceLocation +no.dependencies=false +nokiaS80.application.icon= +nsicom.application.monitorhost= +nsicom.application.runremote= +nsicom.application.runverbose= +nsicom.remoteapp.location=\\My Documents\\NetBeans Applications +nsicom.remotevm.location=\\Windows\\creme\\bin\\CrEme.exe +obfuscated.classes.dir=${build.dir}/obfuscated +obfuscation.custom=@E:\\SETUPS\\Disk\\Programming\\Java\\annimon.pro +obfuscation.level=1 +obfuscator.destjar=${build.dir}/obfuscated.jar +obfuscator.srcjar=${build.dir}/before-obfuscation.jar +platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_ +platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator) +platform.apis=JSR234-1.0,J2ME-WS-1.0,JSR239-1.0,MascotV3-1.0,JSR238-1.0,MMAPI-1.1,JSR256-1.1,NokiaUI-1.0,JSR226-1.0,JSR75-1.0,JSR184-1.1,WMA-2.0,JSR211-1.0,JSR82-1.1 +platform.bootclasspath=${platform.home}/lib/mascotv3.jar:${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr256.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/nokiaext.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar +platform.configuration=CLDC-1.1 +platform.device=SonyEricsson_JP8_240x320_Emu +platform.fat.jar=true +platform.profile=MIDP-2.0 +platform.trigger=CLDC +platform.type=UEI-1.0.1 +preprocessed.dir=${build.dir}/preprocessed +preverify.classes.dir=${build.dir}/preverified +preverify.sources.dir=${build.dir}/preverifysrc +resources.dir=resources +ricoh.application.email= +ricoh.application.fax= +ricoh.application.icon= +ricoh.application.target-jar= +ricoh.application.telephone= +ricoh.application.uid=13736874 +ricoh.application.version= +ricoh.dalp.application-desc.auto-run=false +ricoh.dalp.application-desc.energy-save= +ricoh.dalp.application-desc.exec-auth= +ricoh.dalp.application-desc.visible=true +ricoh.dalp.argument= +ricoh.dalp.codebase= +ricoh.dalp.display-mode.color=true +ricoh.dalp.display-mode.is-4line-support=false +ricoh.dalp.display-mode.is-hvga-support=true +ricoh.dalp.display-mode.is-vga-support=false +ricoh.dalp.display-mode.is-wvga-support=false +ricoh.dalp.information.abbreviation= +ricoh.dalp.information.icon.basepath= +ricoh.dalp.information.icon.location= +ricoh.dalp.information.is-icon-used=true +ricoh.dalp.install.destination=hdd +ricoh.dalp.install.mode.auto=true +ricoh.dalp.install.work-dir=hdd +ricoh.dalp.is-managed=true +ricoh.dalp.resources.dsdk.version=2.0 +ricoh.dalp.resources.jar.basepath= +ricoh.dalp.resources.jar.version= +ricoh.dalp.version= +ricoh.icon.invert=false +ricoh.platform.target.version= +run.cmd.options= +run.jvmargs= +run.method=STANDARD +run.security.domain=trusted +run.use.security.domain=false +savaje.application.icon= +savaje.application.icon.focused= +savaje.application.icon.small= +savaje.application.uid=TBD +savaje.bundle.base= +savaje.bundle.debug=false +savaje.bundle.debug.port= +semc.application.caps= +semc.application.icon= +semc.application.icon.count= +semc.application.icon.splash= +semc.application.icon.splash.installonly=false +semc.application.uid=E9003756 +semc.certificate.path= +semc.private.key.password= +semc.private.key.path= +sign.alias=minimal +sign.enabled=false +sign.keystore=${file.reference.builtin.ks} +src.dir=src +use.emptyapis=true +use.preprocessor=true diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..72207e1 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,10 @@ + + + org.netbeans.modules.kjava.j2meproject + + + Mobi3DSpaceLocation + 1.6 + + + diff --git a/src/AccelUtil.java b/src/AccelUtil.java new file mode 100644 index 0000000..b63e5b1 --- /dev/null +++ b/src/AccelUtil.java @@ -0,0 +1,110 @@ + + +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +import java.io.IOException; +import javax.microedition.io.Connector; +import javax.microedition.sensor.*; + +/** + * + * @author aNNiMON + */ +public abstract class AccelUtil implements DataListener { + + private int[] channels; + private String[] channelNames; + private SensorConnection sensor; + private String URL; //URL для коннекта + private int numChannels; //количество каналов + private int dataType; //тип приёма данных + private double + minValue,//минимальное значение + maxValue; //максимальное значение + + public AccelUtil() { + getInfo(); + } + + private void getInfo() { + //Получаем список ВСЕХ сенсоров + SensorInfo[] info = SensorManager.findSensors(null, null); + if (info==null || info.length==0) return; //ничего не нашли, выходим + //Сканируем найденные сенсоры + for(int i=0; i=0) value = (int) (doublevalue * 1024 / maxValue); + else value = (int) (doublevalue * (-1024) / minValue); + + return value; + } +} diff --git a/src/Canv.java b/src/Canv.java new file mode 100644 index 0000000..48e12a4 --- /dev/null +++ b/src/Canv.java @@ -0,0 +1,300 @@ +import javax.microedition.lcdui.*; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author aNNiMON + */ +public class Canv extends Canvas implements Runnable { + + private int w,h; + + //Для визуалок + private int tcr; + private boolean exit;//выход - старт эффекта + private boolean right; + + // Глобальные Данные + private boolean run, record, standby; //режим проигрывания, записи макроса и ожидания + private int stx, sty, stz; + + private int vx, vy, vz; + private int lx, ly, lz; + private boolean lok = false; + private boolean st4 = false; + + private boolean lite = false; + private AccelUtil au; + private Image I, img; + private Graphics G; + private Thread thr; + private static final Font smallFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL); + + public Canv() { + setFullScreenMode(true); + tcr = 0; + standby = true; right = true; + exit = run = record = false; + thr = new Thread(this); + w = getWidth(); + h = getHeight(); + I = Image.createImage(w, h); + // Позиция просмотра + vx = 0; + vy = 100; + vz = 0; + G = I.getGraphics(); + au = new AccelUtil() { + + public void setPositions(int x, int y, int z) { + int sc = st4 ? 2 : 1; + x *= sc; + y *= sc; + z *= sc; + if(standby) { + stx=-z; + sty=y/2; + stz=x; + //mc.setViewLook(x, y, z); + mc.setRotationMDL(stx, sty, stz); + repaint(); + } + } + + }; + thr.start(); + } + + protected void paint(Graphics g) { + if(exit) { + g.setColor(0x00); + g.fillRect(-(w/2)+tcr-img.getWidth()/2, h/2-img.getHeight()/2, img.getWidth(), img.getHeight()); + g.drawImage(img, -(w/2)+tcr, h/2, 3); + g.drawImage(I, tcr, 0, 20); + } + else { + g.drawImage(I, 0, 0, 20); + drawCanvas(G); + } + } + + private void drawCanvas(Graphics g) { + int fh = smallFont.getHeight()+2; + g.setColor(0x00); + g.fillRect(0, 0, w, fh); + g.setColor(0xFFFFFF); + g.fillRect(0, fh, w, h-fh); + mc.setViewUp(vx, vy, vz); + mc.setViewPos(lx, ly, lz); + //mc.setLightPos(lx, ly, lz); + mc.drawModel(g); + g.setColor(0x006688); + g.drawString(""+stx+" "+sty+" "+stz, 5, 30, 20); + g.drawString(""+st4+" "+vx+" "+vy+" "+vz, 5, 60, 20); + g.drawString(""+lok+" "+lx+" "+ly+" "+lz, 5, 90, 20); + drawTitle(g, "Mobi3DSpaceLocation", tcr); + } + + public void keyPressed(int key) { + if(!lok) switch(key) { + + case KEY_NUM4: vx-=100; break; + case KEY_NUM6: vx+=100; break; + + case KEY_NUM2: vy-=100; break; + case KEY_NUM8: vy+=100; break; + + case KEY_NUM1: vz-=100; break; + case KEY_NUM3: vz+=100; break; + + case KEY_STAR: lok=!lok; break; + case KEY_NUM5: st4=!st4; break; + } else switch(key) { + + case KEY_NUM4: lx-=100; break; + case KEY_NUM6: lx+=100; break; + + case KEY_NUM2: ly-=100; break; + case KEY_NUM8: ly+=100; break; + + case KEY_NUM1: lz-=100; break; + case KEY_NUM3: lz+=100; break; + + case KEY_NUM5: st4=!st4; break; + case KEY_STAR: lok=!lok; break; + } + } + + public void keyRepeated(int key) { + keyPressed(key); + } + + public void run() { + initModel(); + while(true) { + if(exit) { + if(tcr>w-3) { + Main.midlet.destroyApp(true); + } + tcr = changeBar(tcr, w); + try { + Thread.sleep(20); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + repaint(); + } + } + } + + private void exitApp() { + tcr = 0; + img = load("/logo.mdat", 3407); + exit = true; + } + + private Image load(String str, int ii) { + try { + byte[] abyte0 = new byte[ii]; + java.io.DataInputStream dis = new java.io.DataInputStream(getClass().getResourceAsStream(str)); + dis.read(abyte0, 0, ii); + dis.close(); + int j; + if (ii < 100) { + j = 10 + ii % 10; + } else if (ii < 200) { + j = 50 + ii % 20; + } else if (ii < 300) { + j = 80 + ii % 20; + } else { + j = 100 + ii % 50; + } + for (int k = 0; k < j; k++) { + byte byte0 = abyte0[k]; + abyte0[k] = abyte0[ii - k - 1]; + abyte0[ii - k - 1] = byte0; + } + byte[] start = new byte[] {(byte) 0x89, (byte) 0x50, (byte) 0x4E, (byte) 0x47, + (byte) 0x0D, (byte) 0x0A, (byte) 0x1A, (byte) 0x0A, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0D, + (byte) 0x49, (byte) 0x48, (byte) 0x44, (byte) 0x52}; + byte[] end = new byte[] {(byte) 0x49, (byte) 0x45, (byte) 0x4E, (byte) 0x44, + (byte) 0xAE, (byte) 0x42, (byte) 0x60, (byte) 0x82}; + byte[] png = new byte[start.length+abyte0.length+end.length]; + int y = start.length; + System.arraycopy(start, 0, png, 0, y); + System.arraycopy(abyte0, 0, png, y, abyte0.length); + y+=abyte0.length; + System.arraycopy(end, 0, png, y, end.length); + start=null; + end=null; + abyte0=null; + //save(png); + return Image.createImage(png, 0, png.length); + } catch (Exception in) { + in.printStackTrace(); + return null; + } + } + + private void drawTitle(Graphics g, String text, int t) { + int fh = smallFont.getHeight()+2; + g.setColor(0x00AADD); + g.setFont(smallFont); + g.drawString(text, w/2, 1, 17); + drawRect(g, 0xFF242424, 0x87282828, 0, 0, w, fh/2); + drawRect(g, 0x87151515, 0xFF181818, 0, fh/2, w, fh/2); + drawRect(g, 0xA7151515, 0x77181818, 0, 0, t, fh); + } + + private int changeBar(int t, int w) { + if (right) t++; + else t--; + if(t>=w || t<=0) right=!right; + return t; + } + + /** + * Ортисовка непрозрачного градиента + * @param g контекст графики + * @param color1 верхний цвет градиента + * @param color2 нижний цвет градиента + * @param x1 X + * @param y1 Y + * @param w ширина + * @param h высота + */ + private void drawRect(Graphics g, int color1, int color2, int x1, int y1, int w, int h) { + // Если цвета одинаковы, то градиент нам не нужен + if(color1 == color2) { + g.setColor(color1); + g.fillRect(x1, y1, w, h); + } else { + drawVGradient(g, color1, color2, x1, y1, w, h); + } + } + + /** + * Отрисовка вертикального градиента + * @param graphics контекст графики + * @param rgb1 верхний цвет градиента + * @param rgb2 нижний цвет градиента + * @param xn X + * @param yn Y + * @param wdh ширина + * @param hgt высота + */ + private void drawVGradient(Graphics graphics, int rgb1, int rgb2, int xn, int yn, int wdh, int hgt) { + if (lite) { + graphics.setColor(rgb1); + graphics.fillRect(xn, yn, wdh, hgt); + return; + } + // Первый цвет + int r1 = acolor(rgb1, 'r'); + int g1 = acolor(rgb1, 'g'); + int b1 = acolor(rgb1, 'b'); + // Разница между вторым и первым цветом + int deltaR = acolor(rgb2, 'r') - r1; + int deltaG = acolor(rgb2, 'g') - g1; + int deltaB = acolor(rgb2, 'b') - b1; + try { + wdh += xn; + hgt += yn; + final int deltaHeight = hgt - yn - 1; + for (int i = yn; i < hgt; i++) { + int r = r1 + ((i - hgt + 1) * deltaR) / deltaHeight + deltaR; + int g = g1 + ((i - hgt + 1) * deltaG) / deltaHeight + deltaG; + int b = b1 + ((i - hgt + 1) * deltaB) / deltaHeight + deltaB; + graphics.setColor(r, g, b); + graphics.drawLine(xn, i, wdh - 1, i); + } + } catch (Exception ex) { + } + } + + /** + * Получить цвет нужного канала в пикселе + * @param argb пиксель + * @param c символьный параметр - название канала (a, r, g, b) + * @return + */ + private static int acolor(int argb, char c) { + if(c=='r') return ((argb >> 16) & 0xff); + else if(c=='g') return ((argb >> 8) & 0xff); + else if(c=='b') return (argb & 0xff); + else if(c=='a') return ((argb >> 24) & 0xff); + else return argb; + } + + private void initModel() { + mc.init(); + mc.setFLCenter(w/2, h/2); + mc.setScaleMDL(1024, 1024, 1024); + mc.setRotationMDL(0, 0, 0); + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..be28813 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,49 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import com.nokia.mid.ui.DeviceControl; +import java.io.*; +import javax.microedition.lcdui.*; +import javax.microedition.midlet.*; + +/** + * @author aNNiMON + */ +public class Main extends MIDlet implements CommandListener { + + public static Main midlet; + public Display dsp; + + public Main() { + midlet = this; + dsp = Display.getDisplay(this); + } + + public void startApp() { + String sensorVersion = System.getProperty("microedition.sensor.version"); + if (sensorVersion == null) { + Alert al = new Alert("Error", "Could not find any sensors", null, AlertType.ERROR); + al.setTimeout(Alert.FOREVER); + al.addCommand(Alert.DISMISS_COMMAND); + al.setCommandListener(this); + dsp.setCurrent(al); + } else { + dsp.setCurrent(new Canv()); + } + } + + public void pauseApp() { + } + + public void destroyApp(boolean un) { + notifyDestroyed(); + } + + public void commandAction(Command c, Displayable d) { + if (c.equals(Alert.DISMISS_COMMAND)) { + notifyDestroyed(); + } + } +} diff --git a/src/figure.mbac b/src/figure.mbac new file mode 100644 index 0000000..dbf4820 Binary files /dev/null and b/src/figure.mbac differ diff --git a/src/logo.mdat b/src/logo.mdat new file mode 100644 index 0000000..e6cfc86 Binary files /dev/null and b/src/logo.mdat differ diff --git a/src/mc.java b/src/mc.java new file mode 100644 index 0000000..a61133c --- /dev/null +++ b/src/mc.java @@ -0,0 +1,187 @@ +import com.mascotcapsule.micro3d.v3.*; +import java.io.IOException; +import javax.microedition.lcdui.*; + +/** + * + * @author aNNiMON + */ +public class mc { + + private static Graphics3D g3 = null; + private static Figure figure; + private static Effect3D effect; + private static AffineTrans viewTrans, modelTrans, tempTrans; + //Свет + private static Light light; + private static Vector3D lightdir = new Vector3D(-3511, 731, 878); // Позиция источника света + private static int dirIntensity = 4096; // Интенсивность света + private static int ambIntensity = 2048; // Интенсивность амбиент света + private static boolean lightEnabled; // использовать ли свет? + + private static FigureLayout layout; + private static int centerX, centerY;// центр вывода + private static boolean persEnabled; //использовать перспективу? + private static int persNear = 1; + private static int persFar = 4096; + private static int persAngle = 682; + + private static int spinx = 0; + private static int spiny = 0; + private static int spinz = 0; + + private static int scalex = 4096; + private static int scaley = 4096; + private static int scalez = 4096; + + private static int modelx = 0; + private static int modely = 0; + private static int modelz = 0; + + private static Vector3D Pos = new Vector3D(0, 120, 500); + private static Vector3D Look = new Vector3D(0, 0, -2000); + private static Vector3D Up = new Vector3D(0, 4096, 0); + + /* + * Свет + * */ + // Позиция источника света + public static void setLightPos(int x, int y, int z) { + lightdir = new Vector3D(x, y, z); + if (light != null) light.setDirection(lightdir); + } + //Интенсивность света + public static void setLightIntensity(int value) { + dirIntensity=value; + } + //Интенсивность амбиент света + public static void setAmbLightIntensity(int value) { + ambIntensity=value; + } + public static void setLight(boolean light) { + lightEnabled=light; + } + + /* + * FigureLayout + * */ + //центр FL + public static void setFLCenter(int cx, int cy) { + centerX=cx; + centerY=cy; + } + //Использовать ли перспективу + public static void setPerspective(boolean pers) { + persEnabled=pers; + } + // Параметры перспективы + public static void setPersPos(int near, int far, int angle) { + persNear = near; //коэфициент ближнего угла + persFar = far; // дальнего угла + persAngle = angle; // сам угол + } + // Параметры поворота модели + public static void setRotationMDL(int x, int y, int z) { + spinx=x; + spiny=y; + spinz=z; + } + // Параметры увеличения модели + public static void setScaleMDL(int x, int y, int z) { + scalex=x; + scaley=y; + scalez=z; + } + // Параметры трансформирования модели + public static void setTransMDL(int x, int y, int z) { + modelx=x; + modely=y; + modelz=z; + } + + + // Позиция камеры + public static void setViewPos(int x, int y, int z) { + Pos = new Vector3D(x, y, z); + } + // Позиция источника света + public static void setViewLook(int x, int y, int z) { + Look = new Vector3D(x, y, z); + } + // Позиция источника света + public static void setViewUp(int x, int y, int z) { + Up = new Vector3D(x, y, z); + } + + + public static void init() { + g3 = new Graphics3D(); + try { + figure = new Figure("figure.mbac"); + } catch (IOException ex) { + try { + figure = new Figure("/figure.mbac"); + } catch (IOException ex1) { + ex1.printStackTrace(); + } + } + effect = new Effect3D(null, Effect3D.NORMAL_SHADING, true, null); + layout = new FigureLayout(); + viewTrans = new AffineTrans(); + modelTrans = new AffineTrans(); + tempTrans = new AffineTrans(); + light = new Light(lightdir, dirIntensity, ambIntensity); + } + + /* + * Отрисовка модели + * */ + public static void drawModel(Graphics g) { + if (g3 == null) return; + //3D рендеринг + g3.bind(g); + viewTrans.lookAt(Pos, Look, Up); + + if (lightEnabled) effect.setLight(light); + else effect.setLight(null); + layout.setCenter(centerX, centerY); + if (persEnabled) { + layout.setPerspective(persNear, persFar, persAngle); + } else { + layout.setParallelSize(800, 800); + } + + // X + modelTrans.setIdentity(); + modelTrans.setRotationX(spinx); + modelTrans.m03 = modelx; + modelTrans.m13 = modely; + modelTrans.m23 = modelz; + viewTrans.mul(modelTrans); + + // Y + modelTrans.setIdentity(); + modelTrans.setRotationY(spiny); + modelTrans.m03 = modelx; + modelTrans.m13 = modely; + modelTrans.m23 = modelz; + viewTrans.mul(modelTrans); + + // Z + modelTrans.setIdentity(); + modelTrans.setRotationZ(spinz); + tempTrans.setIdentity(); + tempTrans.set(scalex, 0, 0, 0, 0, scaley, 0, 0, 0, 0, scalez, 0); + modelTrans.mul(tempTrans); + + modelTrans.m03 = modelx; + modelTrans.m13 = modely; + modelTrans.m23 = modelz; + viewTrans.mul(modelTrans); + layout.setAffineTrans(viewTrans); + g3.renderFigure(figure, 0, 0, layout, effect); + g3.flush(); + g3.release(g); + } +} +