Initial
This commit is contained in:
commit
c94e8f43f4
83
build.xml
Normal file
83
build.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<project name="Mobi3DSpaceLocation" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project .</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
pre-init: called before initialization of project properties
|
||||
post-init: called after initialization of project properties
|
||||
pre-preprocess: called before text preprocessing of sources
|
||||
post-preprocess: called after text preprocessing of sources
|
||||
pre-compile: called before source compilation
|
||||
post-compile: called after source compilation
|
||||
pre-obfuscate: called before obfuscation
|
||||
post-obfuscate: called after obfuscation
|
||||
pre-preverify: called before preverification
|
||||
post-preverify: called after preverification
|
||||
pre-jar: called before jar building
|
||||
post-jar: called after jar building
|
||||
pre-build: called before final distribution building
|
||||
post-build: called after final distribution building
|
||||
pre-clean: called before cleaning build products
|
||||
post-clean: called after cleaning build products
|
||||
|
||||
Example of pluging a my-special-task after the compilation could look like
|
||||
|
||||
<target name="post-compile">
|
||||
<my-special-task>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</my-special-task>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
Other way how to customize the build is by overriding existing main targets.
|
||||
The target of interest are:
|
||||
|
||||
preprocess: preprocessing
|
||||
extract-libs: extraction of libraries and resources
|
||||
compile: compilation
|
||||
create-jad: construction of jad and jar manifest source
|
||||
obfuscate: obfuscation
|
||||
preverify: preverification
|
||||
jar: jar archive building
|
||||
run: execution
|
||||
debug: execution in debug mode
|
||||
build: building of the final distribution
|
||||
javadoc: javadoc generation
|
||||
|
||||
Example of overriding the target for project execution could look like
|
||||
|
||||
<target name="run" depends="init,jar">
|
||||
<my-special-exec jadfile="${dist.dir}/${dist.jad}"/>
|
||||
</target>
|
||||
|
||||
Be careful about correct dependencies when overriding original target.
|
||||
Again, for list of available properties which you can use check the target
|
||||
you are overriding in nbproject/build-impl.xml file.
|
||||
|
||||
A special target for-all-configs can be used to run some specific targets for
|
||||
all project configurations in a sequence. File nbproject/build-impl.xml
|
||||
already contains some "for-all" targets:
|
||||
|
||||
jar-all
|
||||
javadoc-all
|
||||
clean-all
|
||||
|
||||
Example of definition of target iterating over all project configurations:
|
||||
|
||||
<target name="jar-all">
|
||||
<property name="target.to.call" value="jar"/>
|
||||
<antcall target="for-all-configs"/>
|
||||
</target>
|
||||
|
||||
-->
|
||||
</project>
|
1247
nbproject/build-impl.xml
Normal file
1247
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -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
|
8
nbproject/private/private.properties
Normal file
8
nbproject/private/private.properties
Normal file
@ -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
|
4
nbproject/private/private.xml
Normal file
4
nbproject/private/private.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
|
||||
</project-private>
|
143
nbproject/project.properties
Normal file
143
nbproject/project.properties
Normal file
@ -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
|
10
nbproject/project.xml
Normal file
10
nbproject/project.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.kjava.j2meproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2me-project">
|
||||
<name>Mobi3DSpaceLocation</name>
|
||||
<minimum-ant-version>1.6</minimum-ant-version>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
110
src/AccelUtil.java
Normal file
110
src/AccelUtil.java
Normal file
@ -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<info.length; i++) {
|
||||
//Узнаём тип устройства
|
||||
String quantity = info[i].getQuantity().toLowerCase();
|
||||
//Нам нужен acceleration
|
||||
if(quantity.startsWith("accel")) {
|
||||
//Нашли девайс
|
||||
SensorInfo s = info[i];
|
||||
//Получаем URL для коннекта с ним
|
||||
URL = s.getUrl();
|
||||
//Получаем каналы приёма данных
|
||||
ChannelInfo[] ci = s.getChannelInfos();
|
||||
//Получаем количество каналов
|
||||
numChannels = ci.length;
|
||||
//Инициализируем переменные
|
||||
channels = new int[numChannels];
|
||||
channelNames = new String[numChannels];
|
||||
//Получаем тип приёма данных (TYPE_DOUBLE = 1, TYPE_INT = 2, TYPE_OBJECT = 4)
|
||||
dataType = ci[0].getDataType();
|
||||
MeasurementRange mr = ci[0].getMeasurementRanges()[0];
|
||||
//Получаем минимальное значение
|
||||
minValue = mr.getSmallestValue();
|
||||
//Получаем максимальное значение
|
||||
maxValue = mr.getLargestValue();
|
||||
//Получаем названия каналов (axis_x, axis_y, axis_z)
|
||||
for (int j = 0; j < numChannels; j++) {
|
||||
channelNames[j] = ci[j].getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
//Для того, чтобы подключить DataListener, нужно соединение
|
||||
try {
|
||||
//Открываем соединение, по раннее полученному URL
|
||||
sensor = (SensorConnection) Connector.open(URL);
|
||||
sensor.setDataListener(this, 1); //1 - размер буфера
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setPositions(int x, int y, int z);
|
||||
|
||||
public void dataReceived(SensorConnection sensor, Data[] data, boolean isDataLost) {
|
||||
//Обработка данных
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
//Получаем имя канала и сравниваем с сохраненными раннее
|
||||
//Данные получаем в виде int от -1024 до 1024
|
||||
for(int j = 0; j < numChannels; j++) {
|
||||
String name = data[i].getChannelInfo().getName();
|
||||
if (name.equals(channelNames[j])) {
|
||||
channels[j] = getValue(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numChannels == 3) setPositions(channels[0], channels[1], channels[2]);
|
||||
else if (numChannels == 2) setPositions(channels[0], channels[1], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразование в int [-1024...+1024]
|
||||
*/
|
||||
private int getValue(Object o) {
|
||||
int value;
|
||||
double doublevalue = 0;
|
||||
if(dataType == ChannelInfo.TYPE_INT) {
|
||||
doublevalue = ((Data) o).getIntValues()[0];
|
||||
} else if(dataType == ChannelInfo.TYPE_DOUBLE) {
|
||||
doublevalue = ((Data) o).getDoubleValues()[0];
|
||||
}
|
||||
if(doublevalue>=0) value = (int) (doublevalue * 1024 / maxValue);
|
||||
else value = (int) (doublevalue * (-1024) / minValue);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
300
src/Canv.java
Normal file
300
src/Canv.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
49
src/Main.java
Normal file
49
src/Main.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/figure.mbac
Normal file
BIN
src/figure.mbac
Normal file
Binary file not shown.
BIN
src/logo.mdat
Normal file
BIN
src/logo.mdat
Normal file
Binary file not shown.
187
src/mc.java
Normal file
187
src/mc.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user