Duke4.net Forums: EDuke32 Scripting - Duke4.net Forums

Jump to content

  • 115 Pages +
  • « First
  • 61
  • 62
  • 63
  • 64
  • 65
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

EDuke32 Scripting  "CON coding help"

#1861

Hello everybody. I need a guru. I need to be able to select objects on the screen with the mouse.
I need a function that takes parameters: camerax,cameray,cameraz,camerasect,camerahoriz,cameraang, screenx,screeny (xd,yd) and return x,y,z in build coordinates.
Posted Image
Can somebody help with programming such functions for non classic modes?
0

#1862

Well, I found a solution algorithm!
Now we need to translate it into the CON

input: x, y, Fov, pan, tilt, w, h
output: panRes, tiltRes

pan = tofloat( get("camera","pan") ); 
tilt = tofloat( get("camera","tilt") ); 
fov = tofloat( get("camera","fov") );

w = tofloat( get( "applet", "width" ) ); 
h = tofloat( get( "applet", "height" ) );

x = tofloat( x ); 
y = tofloat( y );


r = (sqrt(w*w + h*h) / 2.0) / tan( gradToRad(fov/2.0) );


vx = r; vy = w/2.0 - x; vz = h/2.0 - y; 
pan = gradToRad( pan ); tilt = gradToRad( -tilt ); 
cosp = cos( pan ); sinp = sin( pan ); 
cost = cos( tilt ); sint = sin( tilt );

/*My * Mz*/ 
vx2 = vx*cost*cosp - vy*sinp + vz*cosp*sint; 
vy2 = vx*cost*sinp + vy*cosp + vz*sint*sinp; 
vz2 = -vx*sint + vz*cost;


sinRes = vy2 / sqrt(vx2*vx2 + vy2*vy2);

panRes = radToGrad( asin(sinRes) ); 
if( vx2 <= 0 && vy2 > 0 ) 
panRes = 180 - panRes; 
else if( vx2 < 0 && vy2 <= 0 ) 
panRes = -180 - panRes;

sinRes = vz2 / sqrt(vx2*vx2 + vy2*vy2 + vz2*vz2); 
tiltRes = radToGrad( asin(sinRes) );


Where:
w, h - width and height of Java Applet (pixels);
Fov - current field of view angle (degrees);
pan, tilt - camera direction point (degrees).
panRes, tiltRes - model coordinates of clicked (x, y) point (degrees).
x, y - screen clicked point coordinates (pixels);
r - panorama model sphere radius;
vx, vy, vz - coordinates of vector from origin to picked point in projection plane;
vx2, vy2, vz2 - transformed vector of picked point.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1863

http://wiki.eduke32.com/wiki/Hitscan
0

#1864

View PostFox, on 01 March 2016 - 12:35 AM, said:


Thank you captain! Hitscan does not take into account the position of the cursor on the screen. I need the ability to select objects on the screen by mouse cursor

This post has been edited by Mr. Alias Nameless: 01 March 2016 - 05:06 AM

0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1865

You would have to code your own cursor.
0

#1866

View PostFox, on 01 March 2016 - 05:21 AM, said:

You would have to code your own cursor.

Yes, of course I have coded a cursor. But how to use the cursor position in the hitscan function?
0

User is offline   Mblackwell 

  • Evil Overlord

#1867

See, what you need to do is complicated. You likely need to translate the cursor coordinates from a 320x200 pixel grid, take into account the renderer used and the resulting fov, and then translate the x coordinate into an ang and the y coordinate into a zvel (with z at screen center).... or perhaps the other way around, you'd need to experiment I guess. You'll probably need to shift up to very large number and down again for precision reasons since there's no floats or even fixed point decimal. You'll get inaccuracies.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1868

View PostMr. Alias Nameless, on 01 March 2016 - 06:17 AM, said:

Yes, of course I have coded a cursor. But how to use the cursor position in the hitscan function?

Use getangle to determine the angle in relation to the screen cordinates (320px = 90º). Remember that when you are looking up or down the view differs drastically between classic and OpenGL modes.
0

User is online   Danukem 

  • Duke Plus Developer

#1869

Doesn't mapster already have code for this which could be translated into CON?
0

#1870

View PostFox, on 01 March 2016 - 07:47 AM, said:

Use getangle to determine the angle in relation to the screen cordinates (320px = 90º). Remember that when you are looking up or down the view differs drastically between classic and OpenGL modes.

thank you this is useful.

View PostTrooper Dan, on 01 March 2016 - 09:49 AM, said:

Doesn't mapster already have code for this which could be translated into CON?

It is very difficult, due to the fact that there is no floating-point numbers in CON. And there is always the risk of overflow.
0

User is online   Danukem 

  • Duke Plus Developer

#1871

I would like to replace the string "SELECT SKILL" with my own string. The string is not in USER.CON and apparently is hard-coded. My intent is to make the difficulty selection menu do something entirely different, such as allowing the player to pick an initial weapon loadout. I can do the rest but I can't get rid of that string. Please help!

Maybe I can draw a graphic on top of where the string appears? EDIT: Nope, it looks like it is only possible to detect whether the player is in a menu, but not which specific menu, unless I am missing something.

This post has been edited by Trooper Dan: 07 March 2016 - 02:05 PM

1

User is offline   Kyanos 

#1872

current_menu should do this
http://wiki.eduke32....ki/Current_menu
1

User is offline   Hendricks266 

  • Weaponized Autism

  #1873

gamevar screenx 0 0
gamevar screeny 0 0

defstate menuwhatever
    getuserdef .m_origin_x screenx
    getuserdef .m_origin_y screeny

    ifvare current_menu 110 // MENU_SKILL
    {
        // use screentext with the <<16 bit set, and *add* the coordinates you want to draw to screenx/y so it animates with the menu
    }
ends

onevent EVENT_DISPLAYMENUREST
    state menuwhatever
endevent

onevent EVENT_DISPLAYINACTIVEMENUREST
    state menuwhatever
endevent

3

User is online   Danukem 

  • Duke Plus Developer

#1874

Thanks, I wasn't expecting it to be a gamevar, so I only looked into the structs.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1875

I believe it should check for RETURN instead of current_menu, otherwise the previous menu sliding away won't display properly.
0

User is offline   Hendricks266 

  • Weaponized Autism

  #1876

D'oh! That's what I get for doing this from memory.

gamevar screenx 0 0
gamevar screeny 0 0

defstate menuwhatever
    getuserdef .m_origin_x screenx
    getuserdef .m_origin_y screeny

    ifvare RETURN 110 // MENU_SKILL
    {
        // use screentext with the <<16 bit set, and *add* the coordinates you want to draw to screenx/y so it animates with the menu
    }
ends

onevent EVENT_DISPLAYMENUREST
    state menuwhatever
endevent

onevent EVENT_DISPLAYINACTIVEMENUREST
    state menuwhatever
endevent

0

User is online   Danukem 

  • Duke Plus Developer

#1877

Is there a way to force a sprite to be rendered, even if it is behind a wall? I seem to remember someone saying so, but I don't recall how. Setting the sprite's sector to the same as the player's does not do it.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1878

You can just put it closer to the player view, then simulate the distance with the sprite scale, but it would lack precision.
0

User is offline   Jblade 

#1879

Would setting it's animatesprite x and y values work? You could have the sprite close to the player but change it's tsprite values so it's displayed where it should actually be in the level.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1880

Nope, animatesprites doesn't work with sprites that are not being rendered.
0

User is online   Danukem 

  • Duke Plus Developer

#1881

View PostFox, on 18 March 2016 - 03:43 PM, said:

You can just put it closer to the player view, then simulate the distance with the sprite scale, but it would lack precision.


Most of the sprites in question are pickable objects, such as ammo. Doing what you suggest would cause the player to pick them up in some cases. What I'm going for is a kind of X-ray vision that reveals objects in secret areas. But it's okay, I've decided I don't really need it, I can make do with something else.
0

User is offline   Jblade 

#1882

View PostFox, on 18 March 2016 - 06:06 PM, said:

Nope, animatesprites doesn't work with sprites that are not being rendered.

That's why I said move the sprite next to the player like you suggested but keep it's tspr x and y values at its original location. Anyways what I suggested is not what Dan was looking for, the ability to do that would be insanely useful though.

This post has been edited by Jblade: 18 March 2016 - 11:58 PM

0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1883

My bad. That would not work, moving it through the tsprite structure would have the same result as being in the original location, except that it would waste some memory processing a sprite that's not visible.

This post has been edited by Fox: 19 March 2016 - 12:07 AM

0

#1884

Hey guys. I have two problems.

1. I already created casings that drop on the ground. However, I would like the casings to be visible in first person as they leave the weapon (like the original sprite ones). I know I can modify the angle horizontally that they appear as such, but then the casings drop in front of Duke instead of next to him. I use code such as this:

 ifactor RIFLESHELL
{
move FORWARD
getactor[THISACTOR].ang TEMP
subvar TEMP -412
randvar TEMP2 128
addvarvar TEMP TEMP2
setactor[THISACTOR].ang TEMP
}



I know the fix is probably easy and I'm missing something obvious, but do help a brother out here.

2. Is it possible for the Eggs and Sharks to be counted in the overall tally count BEFORE killing them? (as in, the mid level enemy count that can be turned on in eDuke can show the proper number of enemies instead of an estimate)
0

User is offline   Jblade 

#1885

The best thing to do is to use rotatepoint at the time of spawning it and telling the actor to spawn a little bit to the diagonal right of Duke when firing. I have some ugly code here I've used in the AMC TC:
	move FORWARD
	getactor[THISACTOR].ang TEMP
	subvar TEMP -412
	randvar TEMP2 128
	addvarvar TEMP TEMP2
	setactor[THISACTOR].ang TEMP
	getactor[THISACTOR].owner TEMP8
		setvarvar TEMP3 sprite[TEMP8].x
		addvar TEMP3 256
		getactor[TEMP8].ang TEMP4
                addvar TEMP4 128
		rotatepoint sprite[TEMP8].x sprite[TEMP8].y TEMP3 sprite[TEMP8].y TEMP4 TEMP5 TEMP6
		setactor[THISACTOR].x TEMP5 
		setactor[THISACTOR].y TEMP6
		getactor[TEMP8].z TEMP
		subvar TEMP 8096
		ifspawnedby APLAYER
			{
			getplayer[THISACTOR].horiz TEMP2
			subvar TEMP2 100
			mulvar TEMP2 16
			subvarvar TEMP TEMP2
			}
		setactor[THISACTOR].z TEMP

Hopefully you can get a gist of what needs doing. I'm sure the code could be improved but I have a dozen other things that need working on at the same time.

This post has been edited by Jblade: 29 April 2016 - 12:35 PM

0

#1886

Thanks for the help!
1

#1887

View PostMr. Alias Nameless, on 21 February 2016 - 06:35 AM, said:

Hello everybody. I need a guru. I need to be able to select objects on the screen with the mouse.
I need a function that takes parameters: camerax,cameray,cameraz,camerasect,camerahoriz,cameraang, screenx,screeny (xd,yd) and return x,y,z in build coordinates.
Posted Image
Can somebody help with programming such functions for non classic modes?



I did it!


This post has been edited by Mr. Alias Nameless: 12 August 2016 - 02:23 AM

4

User is offline   Mblackwell 

  • Evil Overlord

#1888

But does it work in other aspect ratios?
0

#1889

View PostMblackwell, on 12 August 2016 - 12:46 PM, said:

But does it work in other aspect ratios?


What do you mean? Screen resolution - yes to all. Aspect setted up by setaspect function - halfway, it is necessary to choose the coefficients for each values of "viewingrange" and "yxaspect". Now I try to find a mathematical relationship.

This post has been edited by Mr. Alias Nameless: 15 August 2016 - 11:47 PM

0

User is offline   stumppy84 

#1890

A quick noob question, I'm trying to code a force-field for the trooper. it works but I cant get the TRANSPORTERSTAR to pallet to 7.. I have tried adding 'spritepal 7' before and after the TRANSPORTERSTAR but neither work..

below the ifwasweapon SHOTSPARK1:
	
sound SOMETHINGHITFORCE
spawn TRANSPORTERSTAR spritepal 7 



This post has been edited by stumppy84: 18 August 2016 - 05:20 PM

0

Share this topic:


  • 115 Pages +
  • « First
  • 61
  • 62
  • 63
  • 64
  • 65
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options