Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Terrain Pointer Script #106332
01/10/07 15:52
01/10/07 15:52
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Someone asked about this in User Requests, so I'm posting it here as well for everyone. This version should be easy enough to just drop into your project.



Code:

///terrainPointer
///A.Russell 2007/1
///Maintains an entity at the position under the mouse pointer
///Ideal for point and click games
///
///View should be named "camera" for this to work un-edited,
///which is the default view name
///
///Now if someone can just make a projection shader that works
///with it, that would be ace.
///If you do, or if you have one please PM me on Conitec Forums

action terrainPointer()
{
var inView;
var traceTarget[3];
var distFromCamera;


my.push = 50; //trace through objects with lower push value,
//for example, you might want to ignore trees, rocks and
//anything else that gets in the way of the terrain/ level surface




//Set initial position
mouse_pos.x = screen_size/2;
mouse_pos.y = screen_size/2;

//This is the offset the pointer's hot spot
mouse_spot.x = 9;
mouse_spot.y = 1;


//Make the engine mouse pointer visible
//Set to 0 to make invisible
mouse_mode=1;


while(1) //You might want to put a better condition than this
{
//Move the mouse depending on whether it is fullscreen or not
//I find this method works pretty well for me
if(video_screen == 1) //If fullscreen
{
MOUSE_POS.X += mouse_force.x*60*time;
MOUSE_POS.Y -= mouse_force.y*60*time;
}else //If not fullscreen
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
}

//Find where that is in 3d co-ordinates
vec_set(temp, mouse_pos);
temp.z = 50;
inView = vec_for_screen(temp, camera);


//If in view, trace from that position until we hit something and put the pointer there.
if(inView)
{
//Do the vector calculations
//to find the direction for the trace.
vec_set(traceTarget, mouse_pos);
traceTarget.z= 5000; //trace up to 5000 quants from view
vec_for_screen(traceTarget, camera);


//Now we have the direction, do the trace
distFromCamera = c_trace(temp, traceTarget,IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_PUSH);
//distanceFrom Camera hasn't been used here, but you might find a use for it
//in your project


//Now you can update the position of the pointer model
vec_set(my.x, target); //Target is the position where the ray hits
//the surface of any obsticle it may have hit

//Position it a little bit above the surface
//You could change this to be in front or between
//the player and the intersection point
//depending on your needs
//Projecting an image onto the terrain would be even
//better if anyone can help with this
pointerMDL.z+=10;

}


wait(1);

}
}



Last edited by A.Russell; 01/10/07 16:50.
Re: Terrain Pointer Script [Re: A.Russell] #106333
01/10/07 16:05
01/10/07 16:05
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Good contribution, thanks


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Terrain Pointer Script [Re: DLively] #106334
01/10/07 17:19
01/10/07 17:19
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline
User
sheefo  Offline
User

Joined: Jul 2006
Posts: 783
London, UK
Just what I needed for my RTS, thanks a lot!

Re: Terrain Pointer Script [Re: A.Russell] #106335
01/11/07 11:50
01/11/07 11:50
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Thxn for posting and pointing this issue out A.Russell

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1