Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (652) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Calculating line intersection for a screen view  (Read 910 times) 0 Members and 1 Guest are viewing this topic.
wjp

Senior Newbie

Java games rock!

 « Posted 2005-04-12 05:53:54 »

Hi,

I have an issue when calculating the perspective view in my game. Most of the time it's fine, but sometimes I end up with a very large x or y value (-ve or +ve) and due to the limitations of java it flips the coordinates and I end up with a line drawing in the wrong direction.

What I would like to calculate (as part of my screen projection method) is if the point is outside the screen (lets say 600,800) I'd like to calculate the point on edge of the screen, so that the points are always between zero and the max dimension of the screen.

I thought about trying to calculate the line intersection depending which quadrant it is, but this seems messy. Is there a better way to do this?

Here's my code for reference:

public Point getScreenProjection(Coordinates a)
{

double f = (viewPoint.z - screenPlane.z) / (viewPoint.z - a.z);
Point p = new Point();
p.x = (int)(a.x * f + dimensions.x * .5);
p.y = (int)(dimensions.y * .5 - a.y * f) + (int)(m_yoffset);
return p;
}

The point 'dimensions' is the dimension of the screen view (ie 600,800).
wjp

Senior Newbie

Java games rock!

 « Reply #1 - Posted 2005-04-12 12:19:56 »

Hi,

just to add - what I'm essentially after is Clipping Operations.

A clipping algorithm to  identify portions of the picture that lie inside or outside of a specified region (ie clip window).

* Point Clipping - checking whether a single point is within the clip window
* Line Clipping  - eliminate lines entirely outside the clip window, and calculates new endpoints for lines only partially within the clip window
* Polygon Clipping  - calculate the boundary(s) for that part of a polygon which overlaps the clip window
CaptainJester

JGO Knight

Medals: 12
Projects: 2
Exp: 14 years

Make it work; make it better.

 « Reply #2 - Posted 2005-04-13 09:24:26 »

Instead of using Point, try Point2D.Double.  This should increase the available precision.  Point only uses int for the x,y value.

wjp

Senior Newbie

Java games rock!

 « Reply #3 - Posted 2005-04-18 12:59:59 »

Hi,

I used a Cohen-Sutherland algorithm to clip all the points in my polygons. This has worked perfectly. However I realise the issue is in fact the getScreenProjection algorithm.

This issue occurs the the point that needs to be mapped is either very close to the viewPoint or behind it. This gives a very laarge factor. This simple fix is to have a large viewPoint - however you then don't get the perspective look I'm after - you get a rather flat view.
Any suggestions or ideas? what do you do?

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (24 views) 2015-08-01 03:58:20 Jesse (19 views) 2015-07-29 04:35:27 Riven (39 views) 2015-07-27 16:38:00 Riven (21 views) 2015-07-27 15:35:20 Riven (24 views) 2015-07-27 12:26:13 Riven (14 views) 2015-07-27 12:23:39 BurntPizza (36 views) 2015-07-25 00:14:37 BurntPizza (46 views) 2015-07-24 22:06:39 BurntPizza (28 views) 2015-07-24 06:06:53 NoxInc (36 views) 2015-07-22 22:16:53
 theagentd 51x wessles 47x basil_ 35x KaiHH 26x orangepascal 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x CelestialCreator 11x princec 11x klaus 11x Jesse 11x pquiring 9x chrislo27 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org