Swing/AWT/SWT :: How To Rotate 2D Square Using Maths Equations Through OpenGL

Feb 23, 2015

So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.

Code for square:

package lab2;
public class Square {
public double [][] vertices = new double[4][2]; //not good to make this public
public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
vertices[0][0]=x1;
vertices[0][1]=y1;
vertices[1][0]=x2;

[Code] ....

In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: How To Turn On Light Through ActionPerformed With OpenGL Java

Apr 29, 2015

I'm writing a java program with opengl and I'm trying to get it where the user would select something like lighting on in a JMenu and then it would turn the lighting on in the house/barn... I have a method called LightOn that I put gl.glEnable(gl.GL_LIGHT0); but it just doesn't seem to turn on when I call it from the action performed... Is there something I'm missing from my code that I'm supposed to use instead since I have tried it with a boolean.. So the boolean starts off as false and when the JMenuItem is clicked the actionPerformed will turn the boolean to true and call the method LightOn. In the display method I have what the light is supposed to be

Snippet of code in display method for lighting:

float [] whiteLight = {1.0f, 1.0f, 1.0f, 1.0f};
float [] ambientLight = {0.1f, 0.1f, 0.1f, 1.0f}; //default
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambientLight,0);
float [] lightPosition = {25, 25, 25, 1};

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Rotate Arrow

Mar 11, 2015

i want to rotate this shape using AffineTransform without changing its position and its size. i want the arrow to be in a straight line. how can i proceed??

I have use this but the place of the arrow is changing.

AffineTransform at = new AffineTransform();
at.rotate(Math.toRadians(45));
c.transform(at);

here is my code for arrow

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

[Code]....

View Replies View Related

Swing/AWT/SWT :: How To Rotate JLabel

Jul 21, 2014

I have written a code to rotate a Jlabel but i am facing some problems.

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;

[Code] ....

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

Maths Root Function Code

May 8, 2014

PET HG = (0.0023 * Ra * ( MTC + 17.8 ) * ...................? how to write formula/value under the root (maths) function ?

View Replies View Related

How To Compare Square Of The Square Root Of Any Number

Feb 20, 2014

How would I compare the square of the square root of any number. The difference in these values is due to the rounding error in Java.

Example: Enter number 2

The answer I should get is: 2.000000000000004
Round off error: -4.440892

View Replies View Related

Textures And OpenGL With Java

Mar 7, 2014

I was trying to understand Textures and OpenGL with Java. but the tutorials I find cover such a horribly broad area X_x.Basically I can get a window up, initialize openGL, and draw many repeating blocks on my screen.

I dont specifically care about minecraft. but I would like to learn how to get Many many blocks on the screenand how to apply more than one texture to a block. I cant seem to load two textures at a time without errors. I have a dumb while loop that includes a few For loops that repeat the blocks.I guess I should learn how to use Arrays to automate the block process ? Im not sure. I started reading about object buffers, but im not sure.

public static void initDisplay()
{
try {
Display.setFullscreen(true);
Display.setVSyncEnabled(true); // Drastically effects updates per second, Camera movement lowers by 98%

[code]....

View Replies View Related

Unexpected OpenGL Simple Movement

May 28, 2014

I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).

Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).

It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.

On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).

What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....

My problem: Can't move my camera even tho it was working before.

package com.Hydroque.OpenGlTest;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

[Code] ....

View Replies View Related

JavaFX 2.0 :: Multiple Display Using OpenGL-ES2

Jul 15, 2014

I would like to know whether multiple displays are supported under (Windows/Linux/mac) when we use opengl-es2 pipeline?

View Replies View Related

JavaFX 2.0 :: Force Prism To Use OpenGL Version 4.1

Jun 25, 2014

Setting VM argument prism.verbose=true gives some insight of what happens.

There i see an old openGL version is used on OSX 10.9:
 
Graphics Vendor: ATI Technologies Inc.
Renderer: AMD Radeon HD 6630M OpenGL Engine
Version: 2.1 ATI-1.22.28
 
How do i force prism to a newer openGL version?

View Replies View Related

How To Attach OpenGL Display To JFrame And Dispose Off It Properly

Nov 12, 2014

How can i attach the OpenGl display to a JFrame and so that when i close the JFrame is destroys the display? Here is my code so far:

package test.core;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.WindowAdapter;

[Code] .....

I had the opengl display attach to the JFrame before i did the runnable. But after adding the runnable the display now shows up the same size as my screen size. I have tried rearranging the

canvas.setSize();
and the
frame.setSize();

but nothing changes the opengl display is still the same size and when i try to close the JFrame first rather then close the display first i get this error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[main,5,main] already has the context current

which points me to my

Display.destroy();

which im guessing is telling me that i am not properly disposing the display? How to attach the opengl display to the JFrame and fix the error above?

View Replies View Related

Algebra 2x2 Linear Equations?

Mar 15, 2015

Design a class named LinearEquation for a 2 X 2 system of linear equations:

ax + by = e
cx + dy = f
Where
x =
ed − bf/ad − bc
y =
af − ec/ad − bc

The class contains:

- Private data fields a, b, c, d, e, and f.
- A constructor with the arguments for a, b, c, d, e, and f.
- Six get methods for a, b, c, d, e, and f.
- A method named isSolvable() that returns true if ad−bc is not 0.
- Methods getX() and getY() that return the solution for the equation.

[code].....

how to display the information I need to display. Also I am not so sure that I wrote the code properly, I do not get any errors when I compile it.

View Replies View Related

Roots Of Nonlinear System Of Equations

Oct 10, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y)

[URL] .....

How to use this library or find a library that can be used in an android application would be amazing.

View Replies View Related

Solve Quadratic Equations With Arrays

Feb 14, 2014

I am suppose to write a method for solving a quadratic equation using the following header:

public static int solveQuadratic(double[] eqn, double[] roots)

I have entered 1, -3 and -4. The answer I get is "The solution is:0.0" .

import java.util.Scanner;
public class QuadratilEq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[3];
double[] roots = new double[4];

[Code] .....

View Replies View Related

Writing A Program For System Of Linear Equations

Sep 22, 2013

So i was assigned to write a program that would print the answer to the system of two linear equation. the form of ax+by=c and dx+ey=f..I wrote this program, but it is incorrect since I tried it out on my terminal and I keep getting incorrect values.

import java.util.Scanner;
public class Quest4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Solving Roots Of Nonlinear System Of Equations

Oct 10, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y)
www(.)math.colostate(.edu)/~benoi...s/solvers.html

How to use this library or find a library that can be used in an android application.

View Replies View Related

Rotate Through JTabbedPanels At 5 Second Intervals

Apr 5, 2014

I have a list of Tabs which are dynamic depending on how many cars are in a database. If there are 10 cars there will be 10 tabs called car 1, car 2, car 3, etc. Each tab simply displays a photo and details of the car.

I have a JMenuItem that says start SlideShow and end SlideShow

What i would like to do is automatically slide through tabs when the start Slideshow is clicked.

View Replies View Related

Way To Rotate JPanel In Java

Jul 28, 2014

Is there any way to Rotate jPanel in java (without using Paint Function).

View Replies View Related

Rotate Image In Java?

May 23, 2014

I have been trying to rotate an image on a certain degree, and still remain on the same position. I have tried g.rotate, but it just rotate around a center, and it does not keep the same position as before.

View Replies View Related

BufferedImage Auto Rotate JPG

Apr 11, 2015

I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.

BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this

int orientation = ???;
BufferedImage newImage = oldImage;
if (orientation>1){
newImage = rotate(oldImage);
}

View Replies View Related

Splitting Numbers From TXT File In Order To Create Equations

Nov 7, 2014

I have a .txt file which i am currently using Scanner to input into the console, the text file contains the names of football games followed by their scores:

E.g. Man U : Liverpool : 2 : 1

I need to create an equation to add together all scores to create a string reading something like "total goals: 28" ....

View Replies View Related

Rotate Left Bitwise Shift?

May 13, 2014

I'm trying to replicate the rol(rotate left) instruction in assembly though can only get as far as shifting the bits with '<<' or doing Long.rotateLeft(var, 5). Both of these method don't wrap around the bits as the rol instruction does.

View Replies View Related

Solving / Roots Of Nonlinear System Of Equations - Java / Android

Oct 11, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y) Page Not Found

How to use this library or find a library that can be used in an android application would be amazing.

View Replies View Related

Physics Calculator - Manipulate Equations To Find Unknown Variable

May 4, 2014

There are a lot of variables in physics and it is easy to manipulate equations to find the unknown variable. Well, in my program I have the problem of determining which equation to solve for an unknown. You can see I have a timeF, timeI, time, distanceI, distanceF, distance...etc...variables. The way that I have written the code, it will scan for an empty() JTF and assign it as the unknown variable (not sure I can do it this way anymore). At that point, the value is passed into the correct calculation method to process the equation based on a series of case statements in each method...

I know the button arrays I have set up will process correctly in the checkJTF method...and I will need to account for that...but right now my focus is on getting the program to properly calculate the kinematics equations and display the result in the JPanel.

public class PhysicsFrame extends JFrame {
//Kinematic variables
private static float distanceI, distanceF, velocityI, velocityF,
velocityAverage, acceleration, time, timeF, timeI, result;
//Power variables

[Code] .....

View Replies View Related

How To Rotate Object And Give Colour Inside

Mar 13, 2014

package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved