Java 3D

Java 3D

View Answers

April 1, 2009 at 3:17 PM

hi Sivaraman,

Create Java Applet.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;

class Point3D {
public int x, y, z;
public Point3D(int X, int Y, int Z) {
x = X;
y = Y;
z = Z;
}
}
class Edge {
public int a, b;
public Edge(int A, int B) {
a = A;
b = B;
}
}
public class DrawCube3D extends Applet implements MouseListener, MouseMotionListener {
private static final long serialVersionUID = 1L;
int width, height;
int mx, my;
Image imag;
Graphics graph;
int azimuth = 35, elevation = 30;
Point3D[] vertices;
Edge[] edges;

public void init() {
setSize(640, 480);
width = getSize().width;
height = getSize().height;
vertices = new Point3D[8];
vertices[0] = new Point3D(-1, -1, -1);
vertices[1] = new Point3D(-1, -1, 1);
vertices[2] = new Point3D(-1, 1, -1);
vertices[3] = new Point3D(-1, 1, 1);
vertices[4] = new Point3D(1, -1, -1);
vertices[5] = new Point3D(1, -1, 1);
vertices[6] = new Point3D(1, 1, -1);
vertices[7] = new Point3D(1, 1, 1);
edges = new Edge[12];
edges[0] = new Edge(0, 1);
edges[1] = new Edge(0, 2);
edges[2] = new Edge(0, 4);
edges[3] = new Edge(1, 3);
edges[4] = new Edge(1, 5);
edges[5] = new Edge(2, 3);
edges[6] = new Edge(2, 6);
edges[7] = new Edge(3, 7);
edges[8] = new Edge(4, 5);
edges[9] = new Edge(4, 6);
edges[10] = new Edge(5, 7);
edges[11] = new Edge(6, 7);
imag = createImage(width, height);
graph = imag.getGraphics();
drawWireFrame(graph);
addMouseListener(this);
addMouseMotionListener(this);
}
void drawWireFrame(Graphics g) {
double theta = Math.PI * azimuth / 180.0;
double phi = Math.PI * elevation / 180.0;
float cosT = (float) Math.cos(theta), sinT = (float) Math.sin(theta);
float cosP = (float) Math.cos(phi), sinP = (float) Math.sin(phi);
float cosTcosP = cosT * cosP, cosTsinP = cosT * sinP, sinTcosP = sinT * cosP, sinTsinP = sinT * sinP;
Point[] points;
points = new Point[vertices.length];
int scaleFactor = width / 4;
float near = 3;
int i;
float nearToObj = 1.5f;

for (i = 0; i < vertices.length; i++) {
int x0 = vertices[i].x;
int y0 = vertices[i].y;
int z0 = vertices[i].z;
float x1 = cosT * x0 + sinT * z0;
float y1 = -sinTsinP * x0 + cosP * y0 + cosTsinP * z0;
float z1 = cosTcosP * z0 - sinTcosP * x0 - sinP * y0;
x1 = x1 * near / (z1 + near + nearToObj);
y1 = y1 * near / (z1 + near + nearToObj);
points[i] = new Point((int) (width / 2 + scaleFactor * x1 + 0.5),(int) (height / 2 - scaleFactor * y1 + 0.5));
}
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
g.setColor(Color.green);
for (i = 0; i < edges.length; ++i) {
g.drawLine(points[edges[i].a].x, points[edges[i].a].y,
points[edges[i].b].x, points[edges[i].b].y);
}
}

April 1, 2009 at 3:19 PM

cont....
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
mx = e.getX();
my = e.getY();
e.consume();
}
public void mouseReleased(MouseEvent e) {
}
public void mouseDragged(MouseEvent arg0) {
int new_mx = arg0.getX(), new_my = arg0.getY();
azimuth -= new_mx - mx;
elevation += new_my - my;
drawWireFrame(graph);
mx = new_mx;
my = new_my;
repaint();
arg0.consume();
}
public void update(Graphics g) {
g.drawImage(imag, 0, 0, this);
System.out.println("azimuth: " + azimuth + ", elevation: " + elevation);
}
public void paint(Graphics g) {
update(g);
}
public void mouseMoved(MouseEvent arg0) {
}
}

Then call it by using applet tag of html page like this:

<applet code=DrawCube3D.class width=500 height=400>
</applet>

Thanks









Related Tutorials/Questions & Answers:
java or 3d
java or 3d  can we use of 3d in core java? if yes pls tell me a demo example of 3d java. thanks...   Have a look at the following link: (adsbygoogle = window.adsbygoogle || []).push({}); http
3D JButton in java?
3D JButton in java?  how we can create 3D button in java. thanks
Advertisements
java 3d code - Java3D
java 3d code  can u please send source code, how to clear canvas3d in java 3d. In my project if i click on clear button in awt frame then canvas must be clear, please send code
Java 3D - Java3D
Java 3D  Hi can u tell me how can i write the code to develop the 3Dimension figure in java  hi Sivaraman, Create Java Applet. import java.applet.*; import java.awt.*; import java.awt.event.
3D PASSWORD
3D PASSWORD  HI i would like to know abt where the 3d password in india used and also few info about the 3d password pls rply some1 as soon as possible
Difference between 3d and 4d
Difference between 3d and 4d  what is the difference between 3d and 4d
How to make a 3D text, make a 3D text, a 3D text
How to make a 3D text       The 3d text can be made by the photoshop, this example... > Layer style > Drop shadow and use these settings. This is your 3D
3d pie chart - Java3D
3d pie chart  Dear Sir, i want to create 3d pie chart using jsp, i have some code for 2d pie chart in jsp and 3d pie chart in applet. for 2d pie chart my jsp page is running properly but for 3d i used some code from applet
how to create 3d chart in dojox charting - XML
how to create 3d chart in dojox charting  Please provide some example for 3d charting in dojox chart
How to make a reflected a 3D text, make a reflected a 3D text, reflected a 3D text
How to make a reflected a 3D text       In this example you will learn a simple way to make a 3D reflection text effect, It has very simple steps to make it easy for the beginners so
What is 3D Printing?
3D printing is one of those technologies that made manual job with the objects... and in the meantime we lose the erstwhile sense of solid sensory reality. 3D printing... is manufactured meticulously following the design, look and feel of a digital 3D
3D Pie Chart
3D Pie Chart       In this section we are providing you an example to create a 3D Pie Chart. Description of Program :    For creating a 3D Pie Chart we use
3D Bar Chart
3D Bar Chart       In this section we are providing you an example to create a 3D Bar Chart. Description of Program  For creating a 3D Bar chart we use the object
JFree 3D Bar Chart not displaying in JSP - Java3D
JFree 3D Bar Chart not displaying in JSP  Hi I am trying to run JFree 3D bar chart written in your site under link: http://www.roseindia.net/chartgraphs/3Dbarchart-in-jsppage.shtml This is not working. PNG file
JavaFX 3D Effect Example
JavaFX 3D Effect Example       We can create an Object in JavaFX and can give him 3D Effect (like Creating Sphere with Circle and 3D text by blurring Text in background
All New HP 3D Printer: Specs, Features and Expectations Explained
All New HP 3D Printer: Specs, Features and Expectations Explained After more... 3D printer market, the ace printer maker Hewlett-Packard just a week before unveiled two brand new models of 3D printers. The new HP 3D printer is named as HP
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score...;demo =     new StackedBarChart3D("Stacked 3D 
Create a 3D bar chart in JSP page using JFreeChart
Create a 3D bar chart in JSP page using JFreeChart       This Example shows you how to create a 3D bar chart in jsp page using JFreeChart. Code given below creates a bar
Java Questions - Java Beginners
Java Questions  Can we make 3d games in java
Java - Java Beginners
Java   HOW TO MAKE 3D GAMES IN JAVA
JavaFX 3D Effect Example
JavaFX 3D Effect Example       Working with java Collections class In this section... java collections framework is a set of classes and interfaces that are used
JavaFX
JavaFX       JavaFX 3D Effect Example We can create an Object in JavaFX and can give him 3D Effect (like Creating Sphere with Circle and 3D text
java graphics - Design concepts & design patterns
java graphics  i dont wanna use Java3D but put solid 3D objects on screen, use z-buffering, ray-casting etc. to make realistic images...this will help build 3D fractals etc...Where must i begin reading
Open Source Game Engine
and others. JOAL gives Java technology developers access to hardware-accelerated 3D... is a real-time 3D rendering environment for all of your real-time 3D needs... world-class, real-time 3D applications today. If you are new to developing
JavaFX Scripting Language
UIs leveraging Java Swing, Java 2D and Java 3D for developers and content... content for deployment on Java environments. Since JavaFX Script is statically... that make it possible to create and maintain very large programs using Java technology
Ajax3D
Ajax3D       Fostering the development of web-based 3D applications and online virtual worlds using Ajax and X3D-based open technologies. Read full DescriptionADS_TO_REPLACE_1
trafic site statistics - Java Server Faces Questions
trafic site statistics  Hello, Does the framework JSF work for creating web pages containing 3D entities (like 3DCharts)and displaying web trafic... correspond the balises d:chartItem to a java class (Bean)? Thanks for any
Java Runtime
Java Runtime       In this section, you will learn about Java Runtime Environment (JRE), it also known as Java Runtime. This is a part of Java Development Kit (JDK). It is a set
java
the world, Banking Application, view 3D image and Shopping Cart. Java find its...java  what is java   java is a programing langauge   Java is an objected oriented programming language. It is designed to work
Lytro Light Field Camera, a Breakthrough Camera with Unmatched Editing Possibilities
software shows a 3D map of the image and as per the requirement of the viewer
game
game  How to make 3D game in java Applet
Chart & Graphs Tutorials in Java
Chart & Graphs Tutorials in Java  ... in Java. Our Chart and Graphs tutorials will help learn everything you need to learn about chart and graphs programming in Java. We have provided many examples
Java API
mail and messaging application. Java 3D A scene graph based 3D API. Java...Java API what is Java API? API stands for Application Programming Interface... of code. Java Application Programming Interface is a library of classes
10 Unusual Technologies to Come in a Big Way
in a big way in the time to come. From 3D printing to, controlling brain impulses... forward towards that trend. 3D printed Simulation 3D printing as well know just..., dimension and size. As 3D printing is continuing to be more hi-tech
Java Download
online games, chat around the world and 3D images. Java makes these types... Java Download       In this section, you will learn about java download. Before downloading it you
Java API
for speech synthesis   Java 3D J3D A scene graph -based 3D API. available here Java OpenGL... Java API      
What is Java API?
. Java 3D ADS_TO_REPLACE_9 A scene graph based 3D API...To understand the term Java api, first of all you should know exactly what... programming. Now it will be easy to understand what is java api as our topic
JFreeChart Tutorial
JFreeChart Tutorials, examples and articles The JFreeChart is Java based library which is used for generating charts and graphs in Java application... to visualize your business data in Java based applications. This library is very popular
java - Java3D
java  example of 3d  Hi Friend, Try the following code: import java.applet.*; import java.awt.*; import java.awt.event.*; import....... To load an applet, create applet.html: Java Applet Demo Hope
about java1
about java1  Sir, i want to know how we develop 3d button ,lable,textfield etc. in java . sir plz give one program as well Thank you
Flex Java Developers
Flex Java Developers Adobe Flex is a standards-based programming methodology... RIA.ADS_TO_REPLACE_1 Flex uses Sun's Java Environment for developing Rich... is very similar to develop an interactive website on Java, and Flex uses Java
java - Java Beginners
{ int day=d.get(Calendar.DAY_OF_MONTH); System.out.printf("%3d
What are the prerequisites for learning Java?
Glossary O - Java Glossary P - Java Glossary Q - Java Terms...Learning Java: What are the prerequisites for learning Java? In this article we will see the pre-requisites for learning the Java programming language
What are the prerequisites for learning Java?
- Examples of various JavaFX 3D effects.   Java 5.0 - Learn... Glossary Q - Java Terms R - Java Terms S - Java Terms T...Learning Java: What are the prerequisites for learning Java? In this article
Waltido
Waltido  How do i create 3D interfaces
Open Source Charting and Reporting Tools in Java
Open Source Charting and Reporting Tools in Java... of them are given below : JfreeChart: This is a free java library for creating... and 3D) bar charts (regular and stacked, with an optional 3D effect
What is the use of java?
Application, view 3D image and Shopping Cart. Java find its extensive use... What is the use of Java?   ... and non-industrial uses of Java programming language. Java Programming
Java XML Books
and experience writing simple Java programs is required.Learn how to create 3D models... Java XML Books         Java and XML Books One night
Where is Java being Used?
Where is Java being Used?       The programming language Java was developed by Sun... programming language. The most important feature of Java is its byte code that can
Displaying calendars - Java Interview Questions
) System.out.println(); System.out.printf("%3d ", j

Ads