On the imode platform, there are two ways to create a 3D model: 1. Import the model from an external. mbac file; 2. Create a 3D model using native data. The following is a program that uses native data to create a triangle cone and can rotate around X and Y axes. Import com. nttdocomo. UI .*;
Import com. nttdocomo. Opt. UI. j3d .*;//
/**
* @ Author ppby
* Rotate 3D
*/
Public class rotate extends iapplication {
Private canvas3d canv; Public void start (){
Try {
Canv = new canvas3d ();
Display. setcurrent (canv );
Thread thread = new thread (canv );
Thread. Start ();
} Catch (illegalthreadstateexception ITSE ){
ITSE. printstacktrace ();
} Catch (exception e ){
E. printstacktrace ();
}
}
}/**
* Canvas class
*/
Class canvas3d extends canvas implements runnable {
// Command list Array
Private int [] Using listfunc _;
Private int [] Using listprim _;
// 3D affine transformation matrix
Private affinetrans viewt = new affinetrans ();
Private affinetrans affinet = new affinetrans ();
Private affinetrans rotatet = new affinetrans (); Private int rotx, roty; // variable for object rotation public canvas3d (){
// Set a camera :( eye position, look at position, UP direction)
Viewt. lookat (
New vector3d (0, 0,800 ),
New vector3d (0, 0, 0 ),
New vector3d (0, 4096, 0)
);
// Set a command list
Setupcmdlistfunc ();
Setupcmdlistprim ();
} Public void run (){
While (true ){
Updateaffinetrans ();
Repaint ();
Try {
Thread. Sleep (100); // wait 100 ms
} Catch (interruptedexception IE ){
}
}
} Public void updateaffinetrans ()
{
Affinet. setidentity ();
// Rotate Y axis
Rotatet. setidentity ();
Rotatet. setrotatey (roty );
Affinet. Mul (rotatet );
// Rotate X axis
Rotatet. setidentity ();
Rotatet. setrotatex (rotx );
Affinet. Mul (rotatet, affinet );
}
/**
* Rendering method.
*/
Public void paint (Graphics g ){
If (G = NULL)
Return;
Try {
G. Lock ();
// Background clear
G. setcolor (graphics. getcolorofrgb (0, 0, 0 ));
G. fillrect (0, 0, getwidth (), getheight (); G. setcolor (graphics. getcolorofrgb (150,150,120 ));
Graphics3d g3d = (graphics3d) g;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.