Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to make a mirror-image of an image?

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 15th Mar 2017 19:46
Hello everybody.

I was trying to make a mirror.

Basically I SetRenderToImage the camera view to an image, and then pasted the image on an object representing the mirror each frame-per-second.
It's working fine, but the image is not left-right reversed like a real mirror.

How to reverse an image left-right so it became the mirror image of the original image?
Or
Is there a way to reverse the object texturing so that the texturing is done reversely left-right?

Thanks.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Mar 2017 20:16 Edited at: 15th Mar 2017 20:18
You can flip the UV map in a modeling application if AppGameKit doesnt expose adequate UV commands

...interesting, the A GK acronym is automatically expanded now in post text
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Mar 2017 21:44
Memblocks

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Mar 2017 22:23
SetSpriteUV

This command overrides the normal UV calculations of the sprites and allows you to set them directly for each vertex. Note that animation using sprite sheets or atlas textures will not function when using this command, and the UV offset and zoom functions will have no effect. You have complete control over the UV coordinates. To undo this use ResetSpriteUV to return to calculated UV coordinates.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 15th Mar 2017 22:38
SetSpriteFlip() maybe
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 16th Mar 2017 13:13
Quote: "SetSpriteFlip() maybe"
I was thinking exactly the same. Apply your image to a sprite and flip it.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Mar 2017 15:20
I was going to say SetSpriteFlip but he mentioned object texturing so I didn't bother.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 31st Mar 2017 00:03 Edited at: 31st Mar 2017 00:06
Yeah Sprite flipping and UV work for sprite.

But still can't find a way to mirror an image plastered on a 3D plane
I tried flipping a 3D plane (rotating it 180 degree on Y axis, but it seems that each side of the plane was textured individually, so the texture of one side is not a mirror image of the other side...
I have to do this real-time, so the mirror camera can capture my character image when myy character is standing/walking in front of it, then use that camera render as texture for the mirror.

I would like to try the memblock method, but how should I alter it so the image is flipped left-right?
If I reverse the order of the memblock content, wouldn't it also turns the image upside down too?
damothegreat
User Banned
Posted: 31st Mar 2017 00:14 Edited at: 31st Mar 2017 00:15
I wouldn't use memblocks in the game processing game loop - will just degrade the performance.

Although if its a once step transform mirror image then its possible (anything is possible)

What do you want to try and achieve again.

A mirror image of a per second camera grab... ok...

its possible with memblock routine... You like us to work it out - or shall I put some code together to do it


Damo
damothegreat
User Banned
Posted: 31st Mar 2017 00:33
Bear with me, I get some code to you

Damian
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 31st Mar 2017 09:14
You should only need to change the UV coords of the plain object once, then the image would remain flipped.

I would just after creation of the mirror object, convert it to a memblock, reset the UV coords, then convert it back to an object. You'd only need to do the memblock bit when you want to change whether or not to flip the texture.
Signature removed by mod because it's larger than 600x120... please resize and try again.
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 31st Mar 2017 09:32
I would suggest a simple shader would be the quickest we to achieve this, just invert the x-axis pixels and you have an instant mirror. This way your GPU handles the image flip and not your CPU.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 31st Mar 2017 11:12
Quote: "a simple shader would be the quickest"

This would indeed be better. lol
Signature removed by mod because it's larger than 600x120... please resize and try again.
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 1st Apr 2017 12:20
Quote: "You should only need to change the UV coords of the plain object once, then the image would remain flipped.

I would just after creation of the mirror object, convert it to a memblock, reset the UV coords, then convert it back to an object. You'd only need to do the memblock bit when you want to change whether or not to flip the texture."


Sounds promising.
Would you give some sort of pseudo-codes using key commands? I don't think I'm familiar with altering UV coordinates manually....
damothegreat
User Banned
Posted: 1st Apr 2017 18:39
There is a lot of examples from masters of AppGameKit that have taken the time to learn and create stuff

Here is just 1 example on how to change UV texture and stuff like, thanks to Phealax

https://forum.thegamecreators.com/thread/206300

and if search UV in AppGameKit Chat bit then there is tuns more examples

Hope this helps
Damo
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 2nd Apr 2017 00:27 Edited at: 2nd Apr 2017 00:27
I Imagine this is the key command?

SetMeshMemblockVertexUV( memID, vertexIndex, u, v )

What value should I put in 'u' and 'v' to reverse the UV coordinates for a 3D object?
damothegreat
User Banned
Posted: 2nd Apr 2017 00:38
Arrggghhh

Whats the best way to learn? not us giving you the code but by seeing exactly what that command does

I really hope your not wanting this forum to make your game for you

Damo
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Apr 2017 01:22 Edited at: 2nd Apr 2017 01:24
If your mirror is a simple plane, just rotate it upside down. Otherwise, flip the UV coordinates like Damo said.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Apr 2017 01:23
there is a great example in the code for the setspriteuv() command
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpriteUV.htm
damothegreat
User Banned
Posted: 2nd Apr 2017 01:27
Spot on..

That's how we learn

Are you born been a programmer @Hakimfullmatel ?

If need anymore help then give us nudge
damothegreat
User Banned
Posted: 2nd Apr 2017 01:45
we don't want you to write you game for you..

if you understand it then you become better programmer.

Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 3rd Apr 2017 12:50
Not tested it, but a shader like this should work:



invVarying.x = 1.0 - uvVarying.x;
invVarying.y = uvVarying.y;
gl_FragColor = texture2D(texture0, invVarying);

}

Login to post a reply

Server time is: 2024-11-24 17:04:09
Your offset time is: 2024-11-24 17:04:09