AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problem in writing rendering engine

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> 3D Graphics API's for Java
View previous topic :: View next topic  
Author Message
CAFxX
Guest





PostPosted: Tue Mar 02, 2004 6:13 am    Post subject: problem in writing rendering engine Reply with quote



i'm attempting to write a rendering engine but i'm stuck.
what i can't figure out is how to compute where a ray hits the visual
screen.
for example:
the finished image should be 800x400. that's 2:1. so somewhere in the 3d
space there will be my rectangular visual screen (with proportions 2:1).
when a light ray hits it I want to know which pixel (of the final image) I
have to add the ray to. how can I do this?
thank you in advanced for helping, CAFxX.

p.s. the engine i'm writing is open source and available at
http://sourceforge.net/projects/lightstorm



Back to top
Peter Ashford
Guest





PostPosted: Tue Mar 02, 2004 10:11 am    Post subject: Re: problem in writing rendering engine Reply with quote



CAFxX wrote:

Quote:
i'm attempting to write a rendering engine but i'm stuck.
what i can't figure out is how to compute where a ray hits the visual
screen.
for example:
the finished image should be 800x400. that's 2:1. so somewhere in the 3d
space there will be my rectangular visual screen (with proportions 2:1).
when a light ray hits it I want to know which pixel (of the final image) I
have to add the ray to. how can I do this?
thank you in advanced for helping, CAFxX.

p.s. the engine i'm writing is open source and available at
http://sourceforge.net/projects/lightstorm

"Rendering engine" sounds realtime, but casting rays sounds like Ray
Tracing. Which are you doing?

Back to top
CAFxX
Guest





PostPosted: Tue Mar 02, 2004 8:59 pm    Post subject: Re: problem in writing rendering engine Reply with quote



absolutely not real-time. it's a sort of radiosity algo.
yeah i know. maybe i'm completely OT here. i just hoped someone could help.

"Peter Ashford" <me (AT) here (DOT) there.com> ha scritto nel messaggio
news:L5Z0c.7949$SZ.158041 (AT) news (DOT) xtra.co.nz...
Quote:
CAFxX wrote:

i'm attempting to write a rendering engine but i'm stuck.
what i can't figure out is how to compute where a ray hits the visual
screen.
for example:
the finished image should be 800x400. that's 2:1. so somewhere in the 3d
space there will be my rectangular visual screen (with proportions 2:1).
when a light ray hits it I want to know which pixel (of the final image)
I
have to add the ray to. how can I do this?
thank you in advanced for helping, CAFxX.

p.s. the engine i'm writing is open source and available at
http://sourceforge.net/projects/lightstorm

"Rendering engine" sounds realtime, but casting rays sounds like Ray
Tracing. Which are you doing?



Back to top
Peter Ashford
Guest





PostPosted: Tue Mar 02, 2004 9:58 pm    Post subject: Re: problem in writing rendering engine Reply with quote

CAFxX wrote:
Quote:
absolutely not real-time. it's a sort of radiosity algo.
yeah i know. maybe i'm completely OT here. i just hoped someone could help.


Ive written a ray tracer in java, but nothing using radiosity. I would
assume that the idea with radiosity is to use the radiosity passes to
colour the objects in the world then use a simple raycast through the
image plane to sample the viewed world. Are you trying to do something
like that or something else?

I might be able to help, but I'm not sure what exactly you're having
problems with (and Ive never done radiosity, so I might not understand Smile )

Peter


Back to top
CAFxX
Guest





PostPosted: Tue Mar 02, 2004 10:18 pm    Post subject: Re: problem in writing rendering engine Reply with quote

well, radiosity is very similar to what you imagined. but what i'm actually
trying to do is quite different. indeed, even in radiosity you need
ray-tracing as the final step.
i was trying to create an engine that won't need it at all.
what i needed to understand was: "ok, i have a ray and a 3d plane (the
screen). i also have the intersection of the ray and the plane. that's
(x,y,z). now, which pixel do i have to color in the output bitmap?"

"Peter Ashford" <me (AT) here (DOT) there.com> ha scritto nel messaggio
news:ls71c.63$Nc3.1855 (AT) news (DOT) xtra.co.nz...
Quote:
CAFxX wrote:
absolutely not real-time. it's a sort of radiosity algo.
yeah i know. maybe i'm completely OT here. i just hoped someone could
help.


Ive written a ray tracer in java, but nothing using radiosity. I would
assume that the idea with radiosity is to use the radiosity passes to
colour the objects in the world then use a simple raycast through the
image plane to sample the viewed world. Are you trying to do something
like that or something else?

I might be able to help, but I'm not sure what exactly you're having
problems with (and Ive never done radiosity, so I might not understand
Smile )

Peter




Back to top
Peter Ashford
Guest





PostPosted: Tue Mar 02, 2004 11:26 pm    Post subject: Re: problem in writing rendering engine Reply with quote

CAFxX wrote:
Quote:
well, radiosity is very similar to what you imagined. but what i'm actually
trying to do is quite different. indeed, even in radiosity you need
ray-tracing as the final step.
i was trying to create an engine that won't need it at all.
what i needed to understand was: "ok, i have a ray and a 3d plane (the
screen). i also have the intersection of the ray and the plane. that's
(x,y,z). now, which pixel do i have to color in the output bitmap?"


Okay, well that's quite simple - you have the plane in 3D space, you
need to translate back into pixels. You do that parametrically. You
have the intersection (P) of the ray and the plane (VP) so convert the
offset of P relative to VP into a pair of x,y values in the VP frame of
reference (in the range 0-1) and multiply these values by the screen
dimensions to get to pixels.

To convert P,VP into an x,y cordinates:

Your plane is (A,B,C,D)

The point is P

x,y are the unknowns


A | B
Quote:
y
--------P

x


D C


The distance AP calculated using vector math (distance between A and P
is the magnitude of (A-P))

The angle between AP and AB can be calculated using the dot product.
The general rule is:

r.q = |r| |q| cos(theta)

so we can get the angle from the dot product by rearanging:

cos(theta) = r.q / (|r| |q|)

Once you have the angle of BAP and the length of AP you can find out the
Y cordinate using trig:

sin(theta) = y / |AP|
..: y = sin(theta) * |AP|

You can calculate x in a similar way (angle PAD is 90 - BAP) so:

sin(90-theta) = x / |AP|
..: x = sin(90-theta) * |AP|


Thats how I figure it anyway, hopefully I haven't made any mistakes.
Don't forget to normalise the vectors before using the dot product to
get angles.

HTH

Peter.







Back to top
Peter Ashford
Guest





PostPosted: Tue Mar 02, 2004 11:42 pm    Post subject: Re: problem in writing rendering engine Reply with quote

This might be obvious, but I forgot to mention: those x,y values relate
to the VP frame, they need to be normalised to lie in [0..1]

Back to top
CAFxX
Guest





PostPosted: Sun Mar 07, 2004 7:52 pm    Post subject: Re: problem in writing rendering engine Reply with quote

Quote:
Your plane is (A,B,C,D)

The point is P

x,y are the unknowns


A | B
| y
--------P
x


D C


The distance AP calculated using vector math (distance between A and P
is the magnitude of (A-P))

I really can't understand the drawing. Morover, in the "distance between A
and P" i can't figure out what A is. The plane? Wasn't it VP? Something
else?



Back to top
Peter Ashford
Guest





PostPosted: Sun Mar 07, 2004 10:45 pm    Post subject: Re: problem in writing rendering engine Reply with quote

CAFxX wrote:
Quote:
Your plane is (A,B,C,D)

The point is P

x,y are the unknowns


A | B
| y
--------P
x


D C


The distance AP calculated using vector math (distance between A and P
is the magnitude of (A-P))


I really can't understand the drawing.

(A,B,C,D) is the plane VP. The formatting got stuffed up in posting,
I'm afraid.

Just use a proprtional font and push points B and C out to the right.
There is a horizontal line to point P and a vertical line (using the |
characters) from the top of the rectangle to P.


Morover, in the "distance between A
Quote:
and P" i can't figure out what A is. The plane? Wasn't it VP?

A is the top left coordinate of the plane. Points A,B,C,D are the four
corners of the plane.

Sorry its taken me so long to reply - I've been out of town on business.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> 3D Graphics API's for Java All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.