Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075795 Posts in 44145 Topics- by 36116 Members - Latest Member: Bhuiya

December 29, 2014, 05:13:43 AM
  Show Posts
Pages: 1 ... 14 15 [16] 17 18 ... 70
301  Developer / Technical / Re: GL ortho center of screen mousePicking on: May 28, 2013, 06:17:41 AM
yeah, I have that talent..

what I don't get in your example (thanks btw)
is the use of matrix.

apart from filling it, you don't use it ?
302  Developer / Technical / GL ortho center of screen mousePicking on: May 28, 2013, 05:04:41 AM
So after a long day of hacking my own subprime camera class, I went for openGL routines instead.
within minutes I had the behaviour I was after (zooming in on the mouse position)

I did it like this
Code:
GL.Viewport(0, 0, ClientRectangle.Width, ClientRectangle.Height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(     
        centerX - ( width / 2.0 ),
        centerX + ( width / 2.0 ),
        centerY - ( height / 2.0 ),
        centerY + ( height / 2.0 ),
        -1,
        1     
       );

    GL.MatrixMode(MatrixMode.Modelview);



the actual zooming in on te center is done in this fuction
Code:
void HandleWheelChanged (object sender, OpenTK.Input.MouseWheelEventArgs e)
{


var my = 600 - e.Y;
var mx = e.X;

double x = (mx / (double)(WIDTH)) - 0.5;
double y = (my / (double)(HEIGHT)) - 0.5;

double preX = (x * width);
double preY = (y * height);

double zoomFactor = 1.5;
if (e.Delta > 0) {
width/=zoomFactor;
height/=zoomFactor;
}
if( e.Delta < 0 )
        {
            // zoom out
            width *= zoomFactor;
            height *= zoomFactor;
        }

double postX = ( x * width );
double postY = ( y * height );
centerX += ( preX - postX );
centerY += ( preY - postY );

scaleX = 1.0/(width/WIDTH);
scaleY = 1.0/(height/HEIGHT);
Console.WriteLine("width:{0}, scaleX:{1}",width,scaleX);
OnResize(null);

        }

all of this is fine and dandy, bu now my mousepicking routines are not working anymore.
I had thought I just needed to plug in the centreX, centreY and scaleX, scaleY to get it working.
but the output is changing radically.

Code:
public float[] ScreenToLocal (float x, float y, Camera cam)
{

ms.Vector2 point =  new ms.Vector2(x, y);

var cx = (float)cam.CenterX;
var cy = (float)cam.CenterY;
var sx = (float)cam.ScaleX;
var sy = (float)cam.ScaleY;


ms.Matrix viewMatrix = ms.Matrix.CreateTranslation(-source.Width/2,-source.Height/2, 0f ) *
ms.Matrix.CreateRotationZ((float)GM.DegreeToRadian(source.Rotation)) *
ms.Matrix.CreateScale(sx,sy, 1f) *
ms.Matrix.CreateTranslation(source.Position.X+source.Width/2, source.Position.Y+source.Height/2, 0f );


viewMatrix =  ms.Matrix.Invert(viewMatrix);

ms.Vector2 rotatedPoint = ms.Vector2.Transform(point, viewMatrix);

return new float[]{rotatedPoint.X, rotatedPoint.Y};
}

as you can see I hacked a little in the CreateTranslation call; but I don't really get it, I've tried swapping around all vaiables and am pulling out hairs here.

Am I missing something or just pain silly?
303  Developer / Technical / Re: rotating and zooming on: May 27, 2013, 05:14:07 PM
So I got it working

whole day I was fiddling, I tried  making the world move added gazillion of crap everywhere, deleted it after  the whole day.

played some more, decide to try it with openGL instead of the crap I built on top of it .
So I changed this
 
Code:
 
        GL.Ortho(0, ClientRectangle.Width, ClientRectangle.Height, 0, -1, 1);
 
 
into that
   
Code:
     
GL.Ortho(     
        centerX - ( width / 2.0 ),
        centerX + ( width / 2.0 ),
        centerY - ( height / 2.0 ),
        centerY + ( height / 2.0 ),
        -1,
        1     
        );


and its perfect.
on the flipside, other stuff is broken now (like my screenToWorld functions but hey)
304  Developer / Technical / Re: Beautiful fails. on: May 27, 2013, 12:42:50 PM
got one



someone knows what it is... I am glad to hear, it's only very occasionaly though
305  Developer / Technical / Re: Which os do you run while developing games? on: May 26, 2013, 09:46:42 PM
windows and linux

because of adobe
306  Developer / Technical / Re: rotating and zooming on: May 26, 2013, 11:16:14 AM
yep that what I am after

http://www.gasi.ch/blog/examples/2008/02/05/zooming/
is pretty clear too
307  Developer / Technical / Re: rotating and zooming on: May 26, 2013, 11:04:36 AM
getting there (my day of being unclear it seems)

when I zoom in, the world coord my mouse is over is differnt before and after.
to fix that is the aim of this thread Wink

trying translate some affine flash matrix stuff atm.

edit: good question! its 2d
308  Developer / Technical / Re: rotating and zooming on: May 26, 2013, 10:53:38 AM
yes yes
I use a camera class with a Matrix (the xna one) .
the actual scaling is not the problem either.

it's the specific behaviour that makes you zoom to the mouse location, and not to the
centre of the camera thats giving me problems.



309  Developer / Technical / Re: rotating and zooming on: May 26, 2013, 10:16:34 AM
yeah that's basically what I have been trying but that doesn't work.
because the xy differences are world space.

I have tried to get that differnce tranlated back for my camera to use but I am failing.

310  Developer / Technical / rotating and zooming on: May 26, 2013, 09:56:36 AM

My camera has a matrix, and can be translated, rotated, scaled freely.
When I zoom in (by wheeling) I want the worldposition under the mouse to remain the same.
that means I'll have to do some tranlating.

Now it just in-/decreases its scaleX scaleY parts and not translates a thing thus the position under the mouse changes.

I think i need to make another Matrix that describes the differnces and do some other Matrix magic with it.

but I don't know my Matrix magic...




311  Player / General / Re: I'm 32 today.. on: May 26, 2013, 06:19:33 AM
so you're dirty too.
Before you've been the dirty one.
312  Developer / Technical / Re: c# and casting on: May 23, 2013, 03:47:28 PM
got it
Code:
public T GetComponent<T> ()
{
if (! components.ContainsKey (typeof(T).Name)) {
return default(T);
}

var comp = components[ typeof(T).Name ];

return Cast<T>(comp);
}

public static T Cast<T>(object o)
{
    return (T)o;
}

Now i can do
var dc = item.GetComponent<DoorComponent>();
and it's working, off to remove a gazillion unneeded crappy casts whoohoo
313  Developer / Technical / Re: c# and casting on: May 23, 2013, 03:25:25 PM
more like:
Code:
var dc = item.GetComponent<DoorComponent>();
vs
DoorComponent doorComponent = item.GetComponent<DoorComponent>() as DoorComponent;

I am hoping to stumble onto some handy generics thing that might do the trick or T rick Wink

edit: dc for Richard
314  Developer / Technical / Re: c# and casting on: May 23, 2013, 02:44:58 PM
well the GetComponent function just returns a Component, it uses the DoorComponent in the <> for lookin it up in a Dictionary.
anyway a Component will not fit in a DoorComponent (other way around only)

so when I do this
Code:
DoorComponent doorComponent = item.GetComponent<DoorComponent>();

c# just does
Code:
Cannot implicitely convert type Component to DoorComponent An explicit conversion exists (are you missing a cast?)

I think I have read something somewhere about permitting of casting up and down, can't remember really though
315  Developer / Technical / c# and casting on: May 23, 2013, 02:19:27 PM
I have a line of code like this
Code:
var doorComponent = (DoorComponent)item.GetComponent<DoorComponent>();

I'd be much happier if it where:
Code:
var doorComponent = item.GetComponent<DoorComponent>();

how do I change my GetComponent method to handle that ?
316  Developer / Technical / Re: How is procedural terrain generated and stored in large scale game development? on: May 23, 2013, 06:31:05 AM
"there must exist some kind of software that lets you run and tweak terrain generation. Maybe something that lets you specify a rough heightmap,"

http://planetside.co.uk/products/terragen2 comes to mind.

Quote
Terragen 2 allows you to create and manipulate highly realistic terrains, both heightfield and procedural. You can load existing heightfields to replicate real-world terrains and gain additional control by using a 3rd party terrain editor, or leverage the powerful built-in procedural functions to achieve global-scale terrains of nearly infinite detail, from the smallest pebble, to the largest mountains. You can combine the benefits of both terrain types in one scene, seamlessly. Even your heightfield terrains can be enhanced with the power and flexibility of procedurals.
317  Developer / Technical / Re: How is procedural terrain generated and stored in large scale game development? on: May 23, 2013, 04:48:48 AM
I would think you would try to store as little as possible, since it's procedural one could just save the random seed and thats it.
then you just have to re-generate.

But I don't know if that is THE common way.

and offcourse when a player can change things in the world you would have to save the changes explicit because you wouldn't be able to generate those.
318  Developer / Technical / on using Lua next to your engine on: May 23, 2013, 02:07:49 AM
So I am at the part where most of my (component entity)engine is done, I have tested it with many little hardcoded levels.

As an afterthough I looked into Lua (for cutscene scripting) and then it got me thinking.

My original intention was to write little one actor scripts and some actor group scripts. 
Then in my main update loop I run all my systems including a scriptrunner that would update the individual lua scripts per actor

an other approach would be to open up the systems lo Lua instead and run them from Lua.
so I would have to move some code to Lua that lives in my main code now (the round/turns/planning/execution states )
but it would open up many more possibilities for modding down the line I think.


what are your thoughts ?
what responsibilities would you give Lua ?

319  Developer / Technical / Re: [HELP] (AS3) Periodic Timer to repeat sound on: May 22, 2013, 06:15:17 AM
In this sort of case I usually break the problem down.
This problem can be broken down in 2 parts

- the timerEvent part

- the soundplaying part


to test if the individual parts are working you could
 - put a
trace("it worked");
call in your onTitleWhooshFinished() event handler.
does it trace "it worked", and does it trace again after X seconds ?
if not why not? get it working.


to test if the soundplaying is working just make a simple function that'll play a the sound.
did it work ? why not ? get it working. I always forget about channels/sounds so http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html


after both parts work you should be able to combine them again.



sorry if I could point you to the exact line your problem lies on, I have no Flash available atm .
that said; why the .play() in your init function? I think it is not needed there.
320  Hidden / Unpaid Work / Re: voxel game on: May 22, 2013, 05:13:41 AM
just remembered

Craftstudio might be a good tool for you
http://craftstud.io/



Pages: 1 ... 14 15 [16] 17 18 ... 70
Theme orange-lt created by panic