ScissorRectange and ScaleMatrix - xna

I have worked through the examples of turning on ScissorTestEnable and ScissorRectangle. It works fine. However, when I apply a ScaleMatrix the clipping no longer seems to work. Are these supposed to work together?

You're probably using SpriteBatch, correct? It seems to me that Shawn Hargreaves' comment on this page is probably the answer you're looking for. Have you tried moving the call that sets the scissor rectangle around to see if it starts working? I tried looking at the decompiled sources of Microsoft.Xna.Framework.Graphics - but I couldn't find any relation between GraphicsDevice.set_ScissorRectangle and SpriteBatch's flushing methods. :S
If it doesn't work, you could also try to replace the scale and scissor with a modified projection and viewport call and then render the objects in each player's screen.

Related

How to use globalCompositeOperation in Konva for multiple shapes with scaling

I'm trying to create polygons with an inner border in Konva.
I found this example of doing this with globalCompositeOperation which works well in Konva, as long as there is only one shape. As soon as I try to add a second shape, this obviously doesn't work anymore and the first shape disappears.
It would work if I were to use a different layer for every shape, but of course that's not a solution that scales well.
I tried using a temporary layer as is done in the example but couldn't get it to work.
So I found this example of using group.cache(), which works fine ... until I try to scale the stage, at which point I would have to refresh the cache, otherwise I only get the scaled up cache, which looks bad.
This codesandbox illustrates the problem. (Please note that this uses simple triangles, in reality I work with arbitray polygons)
So is there a way to use cache with scaling? Or alternatively a better way to use globalCompositeOperation with multiple shapes in the same layer? Or some alternative solution?
I found a solution: calling group.cache({pixelRatio: scaleFactor}). I updated the sandbox.
No idea, if this is the best solution, but it works.

Keeping track of an object and painting behind

I have been struggling with this problem for a time and being unable to solve it led me here. I'm recently new to Actionscript (2.0). I want to do something similar to:
http://gnarshmallow.com/
Were i want something to be painted behind a moving object in real time.
I would like some advice on how to approach the problem.
You need to use line drawing to do this. You will need two points, and it will draw a line from one to the next. I recommend having it run on every movement call. Have it draw the line between the racer's location in the previous frame, and his location in the current frame. For further reference, check out this page.
http://www.actionscript.org/resources/articles/730/1/Drawing-lines-with-AS2/Page1.html

I cannot get the note timing right - XNA

In XNA I've created a note sequence, and I'm trying to get the item to be drawn to the screen at a certain time? my check for this is a simple int that gets updated as the gametime does Convert.ToInt64(time)
is the code for that. However the only problem I got was it seemed that it kept drawing it which made the note lag? Could somebody please help?
Create a global variable that check if you draw it or not.
Once you draw it make it true.
In the update, do:
if(!variable&&time>"yourtime")
...

WebGL z-buffer artifacts?

We are working on a Three.js based WebGL project, and have trouble understanding how transparency is handled in WebGL. The image shows a doublesided surface drawn with alpha = 0.7, which behaves correctly on its right side. However closer to the middle strange artifacts appear, and on the left side the transparency does not seem to work at all.
http://emilaxelsson.se/sandbox/vis1/alpha.png
The problem can also be seen here:
http://emilaxelsson.se/sandbox/vis1/
Has anyone seen anything similar before? What could the reason be?
Your problem is that transparent objects needs to be sorted and rendered in a back-to-front order (if you try to change the opacity of your mesh from 0.7 (transparent) to 1.0 (opaque), you can see that the z-buffer works just fine).
See:
http://www.opengl.org/wiki/Transparency_Sorting
http://www.opengl.org/archives/resources/faq/technical/transparency.htm (15.050)
In your case it might be less trivial to solve, since I assume that you only have one mesh.
Edit: Just to summarize the discussion below. It is possible to achieve correct rendering of such a double-sided transparent mesh. To do this, you need to create 6 versions of the mesh, corresponding to 6 sides of a cube. Each version needs to be sorted in a back-to-front order based on the 'side of the cube' (front, back, left, right, top, bottom).
When rendering choose the correct mesh (based on the camera viewing direction) and render that single mesh.
The easy solution for your case (based on the picture you attached), without going to expensive sorting and multiple meshes, is to disable depth test and enable face culling. That produces acceptable results if you do not have any opaque objects in front of the mesh.

Smooth Rotation using Bullet and Ogre3D

I've been suffering from an issue regarding the implementation of orienting characters in a game I'm implementing using Ogre3D and Bullet physics.
What I have: A Direction Vector that the character is moving in, along with its current orientation.
What I need: To set the orientation of the character to face the way it is moving.
I have a snippet of code that sort of does what I want:
btTransform src = body->getCenterOfMassTransform();
btVector3 up = BtOgre::Convert::toBullet(Ogre::Vector3::UNIT_X);
btVector3 normDirection = mDirection.normalized();
btScalar angle = acos(up.dot(normDirection));
btVector3 axis = up.cross(normDirection);
src.setRotation(btQuaternion(axis, angle));
body->setCenterOfMassTransform(src);
Where 'body' is the rigidbody I'm trying to orient.
This snippet has a couple of problems however:
1) When changing direction, it tends to 'jitter' i.e. it rapidly faces one way, then the opposite for a second or so before correcting itself to the orientation it is supposed to be at.
2) Most times that the code is run I get an assertion error from Bullet's btQuaternion on
assert(d != btScalar(0.0));
Can anyone help?
Thanks!
I think you shouldn't use functions like 'acos' for such things, as it may cause some inconsistencies in border-cases as the 180 vs 0 rotation mentioned above. You can also get high numerical error for such data.
The second thing is that - in general - you should avoid setting explicit position and rotation in physics engines, but rather apply forces and torques to make your body moving as you want. Your current approach may work perfectly now, but when you add another object and force you character to occupy the same space, your simulation will explode. And at this stage it's very hard to fix it, so it's better to do it right from start :) .
I know that finding correct force/torque can be tricky but it's the best way to make your simulation consistent.

Resources