Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2009, 10:21 PM
tsy tsy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 8 tsy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 14 sec
Reputation Power: 0
How to make image 2D to 3D in j2me

I have tried to make image 2D to 3D in j2me,
I think my code is correct n there isn't false. but the image is not change,,.

Can you help me to get the solution.>??

Reply With Quote
  #2  
Old June 24th, 2009, 10:23 PM
tsy tsy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 8 tsy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 14 sec
Reputation Power: 0
this is my code

<code>
public class TestBufferedImage extends Canvas {
private HttpFileGetter httpWrapper;

//image 3D
private Graphics3D iG3D;
private Camera iCamera;
private Light iLight;
private float iAngle = 0.0f;
private Transform iTransform = new Transform();
private Background iBackground = new Background();
private VertexBuffer iVb; // positions, normals, colors, texcoords
private IndexBuffer iIb; // indices to iVB, forming triangle strips
private Appearance iAppearance; // material, texture, compositing, ...
private Material iMaterial = new Material();
private Image iImage;
private Graphics b;





public TestBufferedImage() {
httpWrapper = new HttpFileGetter("http://khm.google.com/maptilecompress/t=1&c=10&hl=en&x=2&y=5&z=4&s=Gal.png");
try {
init();
} catch (Exception ex) {
ex.printStackTrace();
}
}

/* protected void paint(Graphics g) {
paintWhiteBackground(g);
showPicture(g);

}*/

public void commandAction(Command c, Displayable d) {
throw new UnsupportedOperationException("Not supported yet.");
}

private Image getStaticMapImage() throws IOException {
byte[] imageData = httpWrapper.getContent();
return Image.createImage(imageData, 0, imageData.length);
}

private void paintWhiteBackground(Graphics g) {
g.setColor(255);
g.fillRect(0, 0, getWidth(), getHeight());
}

private void showPicture(Graphics g) {
try {
ImageManipulator imageManipulator = new ImageManipulator(g, getStaticMapImage());
imageManipulator.resizeImage(125, 155);
imageManipulator.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}

/**
* Component initialization.
*/
private void init() throws Exception{
//get the singleton Graphics3D instance
iG3D = Graphics3D.getInstance();

//create a camera
iCamera = new Camera();
iCamera.setPerspective(60.0f, (float)getWidth()/(float)getHeight(),1.0f, 1000.0f);

//create a light
iLight = new Light();
iLight.setColor(0xffffff);
iLight.setIntensity(1.25f);

// The ASCII diagram above represents the vertices in the first line
// (the first tri-strip)
short[] vert = {
10, 10, 10, -10, 10, 10, 10,-10, 10, -10,-10, 10, // front
-10, 20,-10, 10, 20,-10, -10,-10,-10, 20,-10,-10, // back
-10, 20, 10, -10, 20,-10, -10,-10, 20, -10,-10,-10, // left
10, 10,-10, 10, 10, 10, 10,-10,-10, 10,-10, 10, // right
10, 10,-10, -10, 10,-10, 10, 10, 10, -10, 10, 10, // top
10,-10, 10, -10,-10, 10, 10,-10,-10, -10,-10,-10 }; // bottom

// create a VertexArray to hold the vertices for the object
VertexArray vertArray = new VertexArray(vert.length / 3, 3, 2);
vertArray.set(0, vert.length/3, vert);

// The per-vertex normals for the cube; these match with the vertices
// above. Each normal is perpendicular to the surface of the object at
// the corresponding vertex.
byte[] norm = {
0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
0, 0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127,
-127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0, 0,
127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0 };

// create a vertex array for the normals of the object
VertexArray normArray = new VertexArray(norm.length / 3, 3, 1);
normArray.set(0, norm.length/3, norm);

// per vertex texture coordinates
short[] tex = {
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1 };

// create a vertex array for the texture coordinates of the object
VertexArray texArray = new VertexArray(tex.length / 2, 2, 2);
texArray.set(0, tex.length/2, tex);

// the length of each triangle strip
int[] stripLen = { 4, 4, 4, 4, 4, 4 };

// create the VertexBuffer for our object
VertexBuffer vb = iVb = new VertexBuffer();
vb.setPositions(vertArray, 1.0f, null); // unit scale, zero bias
vb.setNormals(normArray);
vb.setTexCoords(0, texArray, 1.0f, null); // unit scale, zero bias

// create the index buffer for our object (this tells how to
// create triangle strips from the contents of the vertex buffer).
iIb = new TriangleStripArray( 0, stripLen );

// load the image for the texture
//iImage = Image.createImage( "/texture.png" );
byte[] imageData;
try {
imageData = httpWrapper.getContent();
//iImage = getStaticMapImage();
iImage = Image.createImage(imageData, 0, imageData.length);
} catch (IOException ex) {
ex.printStackTrace();
}
// create the Image2D (we need this so we can make a Texture2D)
Image2D image2D = new Image2D( Image2D.RGB, iImage );

// create the Texture2D

// texture color is to be modulated with the lit material color
Texture2D texture = new Texture2D( image2D );
texture.setFiltering(Texture2D.FILTER_NEAREST,
Texture2D.FILTER_NEAREST);
texture.setWrapping(Texture2D.WRAP_CLAMP,
Texture2D.WRAP_CLAMP);
texture.setBlending(Texture2D.FUNC_MODULATE);

// create the appearance
iAppearance = new Appearance();
iAppearance.setTexture(0, texture);
iAppearance.setMaterial(iMaterial);
iMaterial.setColor(Material.DIFFUSE, 0xFFFFFFFF); // white
iMaterial.setColor(Material.SPECULAR, 0xFFFFFFFF); // white
iMaterial.setShininess(100.0f);

iBackground.setColor(0xffffcc); // set the background color

}
/**
* Paint the scene.
*/
protected void paint(Graphics g) {

// Bind the Graphics of this Canvas to our Graphics3D. The
// viewport is automatically set to cover the entire clipping
// rectangle of the Graphics object. The parameters indicate
// that z-buffering, dithering, and true color rendering are
// enabled, but antialiasing is disabled.
//paintWhiteBackground(g);

//iG3D = Graphics3D.getInstance();
iG3D.bindTarget(g, true,
Graphics3D.DITHER |
Graphics3D.TRUE_COLOR);

// clear the color and depth buffers
iG3D.clear(iBackground);

// set up the camera in the desired position
Transform transform = new Transform();
transform.postTranslate(0.0f, 0.0f, 30.0f);
iG3D.setCamera(iCamera, transform);

// set up a "headlight": a directional light shining
// from the direction of the camera
iG3D.resetLights();
iG3D.addLight(iLight, transform);

// update our transform (this will give us a rotating cube)
iAngle += 1.0f;
iTransform.setIdentity();
iTransform.postRotate(iAngle, // rotate 1 degree per frame
1.0f, 1.0f, 1.0f); // rotate around this axis

// Render our cube. We provide the vertex and index buffers
// to specify the geometry; the appearance so we know what
// material and texture to use; and the transform to tell
// where to render the object
iG3D.render(iVb, iIb, iAppearance, iTransform);

// flush
iG3D.releaseTarget();
}
}



</code>

Reply With Quote
  #3  
Old June 25th, 2009, 12:49 PM
jzd's Avatar
jzd jzd is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2007
Posts: 933 jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 13 m 6 sec
Reputation Power: 792
Could you elaborate on the exact problem? And if you could define what "correct" code should do that would be nice as well.

Thanks

Reply With Quote
  #4  
Old June 26th, 2009, 05:57 AM
tsy tsy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 8 tsy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by jzd
Could you elaborate on the exact problem? And if you could define what "correct" code should do that would be nice as well.

Thanks


I say like that because there isn't error when I run it, so I think there isn't wrong code.

Btw, my image has sucsessed, but the problem now,
how I can panning it..???
can you help me...??

Reply With Quote
  #5  
Old June 26th, 2009, 07:35 AM
jzd's Avatar
jzd jzd is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2007
Posts: 933 jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level)jzd User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 13 m 6 sec
Reputation Power: 792
Quote:
Originally Posted by tsy
I say like that because there isn't error when I run it, so I think there isn't wrong code.

Btw, my image has sucsessed, but the problem now,
how I can panning it..???
can you help me...??
Might be able to help, but like I said I am little confused as to your problem, please be very specific.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > How to make image 2D to 3D in j2me


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT