Jump to content

  • Log In with Google      Sign In   
  • Create Account

Raycasting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 !Null   Members   -  Reputation: 380

Like
0Likes
Like

Posted 19 August 2012 - 06:20 PM

Hey guys. just before I ask my question, I'm a software engineering student, I'm super comfortable with java and not too comfortable with c++.

A fellow student got me into games design and its only within the last year odd that I've decided to try game programming, so I'm mega n00b.

So I looked up these ancient tutorials on Raycasting and implementing voxel engines. it doesn't seem to standardised.

I kind of understand the theory behind Raycasting but It wont go into my head until I can see some working code that I can mess around with.

can any of you help me out here.

Thanks :)
/********************************************************************************\
/**********************He Who Dares, Wins**********************************\
/********************************************************************************\

Sponsor:

#2 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 19 August 2012 - 07:25 PM

you will never need to implement raycasting yourself, unless you want to write your own physics engine.
in ancient times programmer used raycasting to determine what player sees.
nowadays raycasting is only used in game logic level, like did bullet hit player and where.

here is an nvidia physx raycasting code:
NxRay worldRay;
worldRay.orig= cstart;
worldRay.dir= cend - cstart; 
worldRay.dir.normalize(); // direction of the ray
NxU32 nbShapes = gScene->raycastAllShapes(worldRay, gMyReport, NxUserRaycastReport::ALL_SHAPES); // use filters to determine which objects are to catch


#3 !Null   Members   -  Reputation: 380

Like
0Likes
Like

Posted 19 August 2012 - 07:31 PM

I should clarify myself a bit. My friend made a game:

http://soharix.homestead.com/gotk.html

and I wanted to try and achieve something similar, so I would need to write my own raycasting engine
/********************************************************************************\
/**********************He Who Dares, Wins**********************************\
/********************************************************************************\

#4 Exessuz   Members   -  Reputation: 141

Like
1Likes
Like

Posted 23 August 2012 - 01:42 PM

I think you should try with ray / plane collision , for example an Axis Aligned box or a OOB

the idea is to cast a ray from the eye or from a click point and check if the ray intersect the plane


a ray is defined by

P= Ro + (Rd*t)

Ro = camera eye for example
Rd = ray dir;
t = distance or time

and a plane (P - Po). n = 0

n = plane normal

(Ro + Rd.t - Po).n = 0
Rd.t.n + (Ro - Po).n = 0

t = (Po - Ro)n / Rd.n

If the line starts outside the plane and is parallel to the plane, there is no intersection. In this case, the above denominator will be zero and the numerator will be non-zero. If the line starts inside the plane and is parallel to the plane, the line intersects the plane everywhere. In this case, both the numerator and denominator above will be zero. In all other cases, the line intersects the plane once and t represents the intersection as the distance along the line from Ro




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS